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 drc
augment(
x,
data = NULL,
newdata = NULL,
se_fit = FALSE,
conf.int = FALSE,
conf.level = 0.95,
...
)
參數
- x
-
通過調用
drc::drm()
生成的drc
對象。 - 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
參數將被忽略。 - se_fit
-
邏輯指示是否應將
.se.fit
列添加到增強輸出中。對於某些模型,此計算可能有點耗時。默認為FALSE
。 - conf.int
-
邏輯指示是否在整理的輸出中包含置信區間。默認為
FALSE
。 - conf.level
-
用於置信區間的置信水平(如果
conf.int = TRUE
)。必須嚴格大於 0 且小於 1。默認為 0.95,對應於 95% 的置信區間。 - ...
-
附加參數。不曾用過。僅需要匹配通用簽名。注意:拚寫錯誤的參數將被吸收到
...
中,並被忽略。如果拚寫錯誤的參數有默認值,則將使用默認值。例如,如果您傳遞conf.lvel = 0.9
,所有計算將使用conf.level = 0.95
進行。這裏有兩個異常:
也可以看看
其他 drc 整理器:glance.drc()
、tidy.drc()
值
帶有列的 tibble::tibble()
:
- .cooksd
-
廚師距離。
- .fitted
-
擬合值或預測值。
- .lower
-
擬合值的區間下限。
- .resid
-
觀察值和擬合值之間的差異。
- .se.fit
-
擬合值的標準誤差。
- .upper
-
擬合值的區間上限。
例子
# load libraries for models and data
library(drc)
#>
#> 'drc' has been loaded.
#> Please cite R and 'drc' if used for a publication,
#> for references type 'citation()' and 'citation('drc')'.
#>
#> Attaching package: ‘drc’
#> The following objects are masked from ‘package:stats’:
#>
#> gaussian, getInitial
# fit model
mod <- drm(dead / total ~ conc, type,
weights = total, data = selenium, fct = LL.2(), type = "binomial"
)
# summarize model fit with tidiers
tidy(mod)
#> # A tibble: 8 × 6
#> term curve estimate std.error statistic p.value
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 b 1 -1.50 0.155 -9.67 2.01e-22
#> 2 b 2 -0.843 0.139 -6.06 1.35e- 9
#> 3 b 3 -2.16 0.138 -15.7 1.65e-55
#> 4 b 4 -1.45 0.169 -8.62 3.41e-18
#> 5 e 1 252. 13.8 18.2 1.16e-74
#> 6 e 2 378. 39.4 9.61 3.53e-22
#> 7 e 3 120. 5.91 20.3 1.14e-91
#> 8 e 4 88.8 8.62 10.3 3.28e-25
tidy(mod, conf.int = TRUE)
#> # A tibble: 8 × 8
#> term curve estimate std.error statistic p.value conf.low conf.high
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 b 1 -1.50 0.155 -9.67 2.01e-22 -1.81 -1.20
#> 2 b 2 -0.843 0.139 -6.06 1.35e- 9 -1.12 -0.571
#> 3 b 3 -2.16 0.138 -15.7 1.65e-55 -2.43 -1.89
#> 4 b 4 -1.45 0.169 -8.62 3.41e-18 -1.78 -1.12
#> 5 e 1 252. 13.8 18.2 1.16e-74 225. 279.
#> 6 e 2 378. 39.4 9.61 3.53e-22 301. 456.
#> 7 e 3 120. 5.91 20.3 1.14e-91 108. 131.
#> 8 e 4 88.8 8.62 10.3 3.28e-25 71.9 106.
glance(mod)
#> # A tibble: 1 × 4
#> AIC BIC logLik df.residual
#> <dbl> <dbl> <logLik> <int>
#> 1 768. 778. -376.2099 17
augment(mod, selenium)
#> # A tibble: 25 × 7
#> type conc total dead .fitted .resid .cooksd
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 0 151 3 0 0.0199 0
#> 2 1 100 146 40 0.199 0.0748 0.0000909
#> 3 1 200 116 31 0.414 -0.146 0.000104
#> 4 1 300 159 85 0.565 -0.0302 0.00000516
#> 5 1 400 150 102 0.667 0.0133 0.00000220
#> 6 1 500 140 112 0.737 0.0633 0.0000720
#> 7 2 0 141 2 0 0.0142 0
#> 8 2 100 153 30 0.246 -0.0495 0.000168
#> 9 2 200 142 59 0.369 0.0468 0.0000347
#> 10 2 300 139 82 0.451 0.139 0.0000430
#> # ℹ 15 more rows
相關用法
- R broom augment.decomposed.ts 使用來自 decomposed.ts 對象的信息增強數據
- 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.poLCA 使用來自 poLCA 對象的信息增強數據
- R broom augment.lm 使用來自 (n) lm 對象的信息增強數據
- R broom augment.rqs 使用來自 (n) 個 rqs 對象的信息來增強數據
- R broom augment.polr 使用來自 (n) 個 polr 對象的信息增強數據
- R broom augment.plm 使用來自 plm 對象的信息增強數據
- 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 對象的信息增強數據
- R broom augment.betareg 使用來自 betareg 對象的信息增強數據
注:本文由純淨天空篩選整理自等大神的英文原創作品 Augment data with information from a(n) drc object。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。