Augment 接受模型對象和數據集,並添加有關數據集中每個觀察值的信息。最常見的是,這包括 .fitted
列中的預測值、.resid
列中的殘差以及 .se.fit
列中擬合值的標準誤差。新列始終以 .
前綴開頭,以避免覆蓋原始數據集中的列。
用戶可以通過 data
參數或 newdata
參數傳遞數據以進行增強。如果用戶將數據傳遞給 data
參數,則它必須正是用於擬合模型對象的數據。將數據集傳遞給 newdata
以擴充模型擬合期間未使用的數據。這仍然要求至少存在用於擬合模型的所有預測變量列。如果用於擬合模型的原始結果變量未包含在 newdata
中,則輸出中不會包含 .resid
列。
根據是否給出 data
或 newdata
,增強的行為通常會有所不同。這是因為通常存在與訓練觀察(例如影響或相關)測量相關的信息,而這些信息對於新觀察沒有有意義的定義。
為了方便起見,許多增強方法提供默認的 data
參數,以便 augment(fit)
將返回增強的訓練數據。在這些情況下,augment 嘗試根據模型對象重建原始數據,並取得了不同程度的成功。
增強數據集始終以 tibble::tibble 形式返回,其行數與傳遞的數據集相同。這意味著傳遞的數據必須可強製轉換為 tibble。如果預測變量將模型作為協變量矩陣的一部分輸入,例如當模型公式使用 splines::ns()
、 stats::poly()
或 survival::Surv()
時,它會表示為矩陣列。
我們正在定義適合各種 na.action
參數的模型的行為,但目前不保證數據丟失時的行為。
用法
# S3 method for polr
augment(
x,
data = model.frame(x),
newdata = NULL,
type.predict = c("class"),
...
)
參數
- x
-
從
MASS::polr()
返回的polr
對象。 - data
-
base::data.frame 或
tibble::tibble()
包含用於生成對象x
的原始數據。默認為stats::model.frame(x)
,以便augment(my_fit)
返回增強的原始數據。不要將新數據傳遞給data
參數。增強將報告傳遞給data
參數的數據的影響和烹飪距離等信息。這些度量僅針對原始訓練數據定義。 - newdata
-
base::data.frame()
或tibble::tibble()
包含用於創建x
的所有原始預測變量。默認為NULL
,表示沒有任何內容傳遞給newdata
。如果指定了newdata
,則data
參數將被忽略。 - type.predict
-
要計算哪種類型的預測,傳遞給
MASS:::predict.polr()
。目前僅支持"class"
。 - ...
-
附加參數。不曾用過。僅需要匹配通用簽名。注意:拚寫錯誤的參數將被吸收到
...
中,並被忽略。如果拚寫錯誤的參數有默認值,則將使用默認值。例如,如果您傳遞conf.lvel = 0.9
,所有計算將使用conf.level = 0.95
進行。這裏有兩個異常:
也可以看看
其他序號整理器:augment.clm()
, glance.clmm()
, glance.clm()
, glance.polr()
, glance.svyolr()
, tidy.clmm()
, tidy.clm()
, tidy.polr()
, tidy.svyolr()
例子
# load libraries for models and data
library(MASS)
# fit model
fit <- polr(Sat ~ Infl + Type + Cont, weights = Freq, data = housing)
# summarize model fit with tidiers
tidy(fit, exponentiate = TRUE, conf.int = TRUE)
#>
#> Re-fitting to get Hessian
#> # A tibble: 8 × 7
#> term estimate std.error statistic conf.low conf.high coef.type
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 InflMedium 1.76 0.105 5.41 1.44 2.16 coefficie…
#> 2 InflHigh 3.63 0.127 10.1 2.83 4.66 coefficie…
#> 3 TypeApartment 0.564 0.119 -4.80 0.446 0.712 coefficie…
#> 4 TypeAtrium 0.693 0.155 -2.36 0.511 0.940 coefficie…
#> 5 TypeTerrace 0.336 0.151 -7.20 0.249 0.451 coefficie…
#> 6 ContHigh 1.43 0.0955 3.77 1.19 1.73 coefficie…
#> 7 Low|Medium 0.609 0.125 -3.97 NA NA scale
#> 8 Medium|High 2.00 0.125 5.50 NA NA scale
glance(fit)
#> # A tibble: 1 × 7
#> edf logLik AIC BIC deviance df.residual nobs
#> <int> <dbl> <dbl> <dbl> <dbl> <int> <int>
#> 1 8 -1740. 3495. 3539. 3479. 1673 1681
augment(fit, type.predict = "class")
#> # A tibble: 72 × 6
#> Sat Infl Type Cont `(weights)` .fitted
#> <ord> <fct> <fct> <fct> <int> <fct>
#> 1 Low Low Tower Low 21 Low
#> 2 Medium Low Tower Low 21 Low
#> 3 High Low Tower Low 28 Low
#> 4 Low Medium Tower Low 34 High
#> 5 Medium Medium Tower Low 22 High
#> 6 High Medium Tower Low 36 High
#> 7 Low High Tower Low 10 High
#> 8 Medium High Tower Low 11 High
#> 9 High High Tower Low 36 High
#> 10 Low Low Apartment Low 61 Low
#> # ℹ 62 more rows
fit2 <- polr(factor(gear) ~ am + mpg + qsec, data = mtcars)
tidy(fit, p.values = TRUE)
#>
#> Re-fitting to get Hessian
#> p-values can presently only be returned for models that contain
#> no categorical variables with more than two levels
#> # A tibble: 8 × 6
#> term estimate std.error statistic p.value coef.type
#> <chr> <dbl> <dbl> <dbl> <lgl> <chr>
#> 1 InflMedium 0.566 0.105 5.41 NA coefficient
#> 2 InflHigh 1.29 0.127 10.1 NA coefficient
#> 3 TypeApartment -0.572 0.119 -4.80 NA coefficient
#> 4 TypeAtrium -0.366 0.155 -2.36 NA coefficient
#> 5 TypeTerrace -1.09 0.151 -7.20 NA coefficient
#> 6 ContHigh 0.360 0.0955 3.77 NA coefficient
#> 7 Low|Medium -0.496 0.125 -3.97 NA scale
#> 8 Medium|High 0.691 0.125 5.50 NA scale
相關用法
- R broom augment.poLCA 使用來自 poLCA 對象的信息增強數據
- R broom augment.plm 使用來自 plm 對象的信息增強數據
- R broom augment.pam 使用來自 pam 對象的信息增強數據
- R broom augment.betamfx 使用來自 betamfx 對象的信息增強數據
- R broom augment.robustbase.glmrob 使用來自 glmrob 對象的信息增強數據
- R broom augment.rlm 使用來自 rlm 對象的信息增強數據
- R broom augment.htest 使用來自(n)個 htest 對象的信息來增強數據
- R broom augment.clm 使用來自 clm 對象的信息增強數據
- R broom augment.speedlm 使用來自 speedlm 對象的信息增強數據
- R broom augment.felm 使用來自 (n) 個 felm 對象的信息來增強數據
- R broom augment.smooth.spline 整理一個(n)smooth.spline對象
- R broom augment.drc 使用來自 a(n) drc 對象的信息增強數據
- R broom augment.decomposed.ts 使用來自 decomposed.ts 對象的信息增強數據
- R broom augment.lm 使用來自 (n) lm 對象的信息增強數據
- R broom augment.rqs 使用來自 (n) 個 rqs 對象的信息來增強數據
- R broom augment.nls 使用來自 nls 對象的信息增強數據
- R broom augment.gam 使用來自 gam 對象的信息增強數據
- R broom augment.fixest 使用來自(n)個最固定對象的信息來增強數據
- R broom augment.survreg 使用來自 survreg 對象的信息增強數據
- R broom augment.rq 使用來自 a(n) rq 對象的信息增強數據
- R broom augment.Mclust 使用來自 Mclust 對象的信息增強數據
- R broom augment.nlrq 整理 a(n) nlrq 對象
- R broom augment.robustbase.lmrob 使用來自 lmrob 對象的信息增強數據
- R broom augment.lmRob 使用來自 lmRob 對象的信息增強數據
- R broom augment.mlogit 使用來自 mlogit 對象的信息增強數據
注:本文由純淨天空篩選整理自等大神的英文原創作品 Augment data with information from a(n) polr object。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。