![](/img/trans.png)
[英]Categorize a continuous predictor variable and calculate proportion of binary outcome
[英]Calculate emmeans using multiple values of the continuous predictor
這個問題與Emmeans 連續自變量有關
我想用單線計算至少三個diameter
值的 EMM,即最小值、平均值和最大值。 指定cov.reduce = range
僅使用最小和最大diameter
給出估計值,刪除cov.reduce = range
給出使用平均diameter
的估計值。
mod = glm(log(strength) ~ machine + diameter, data = fiber)
emmeans(mod, ~machine*diameter, cov.reduce = range)
machine diameter emmean SE df asymp.LCL asymp.UCL
A 15 3.48 0.0315 Inf 3.42 3.54
B 15 3.50 0.0333 Inf 3.44 3.57
C 15 3.43 0.0232 Inf 3.39 3.48
A 32 3.88 0.0243 Inf 3.83 3.93
B 32 3.90 0.0228 Inf 3.86 3.95
C 32 3.83 0.0329 Inf 3.77 3.90
結合cov.reduce = c(range, mean)
僅給出平均diameter
的估計值。
> emmeans(mod, ~machine*diameter, cov.reduce = c(range, mean))
machine diameter emmean SE df asymp.LCL asymp.UCL
A 24.1 3.69 0.0167 Inf 3.66 3.73
B 24.1 3.72 0.0172 Inf 3.69 3.75
C 24.1 3.65 0.0182 Inf 3.61 3.68
Results are given on the log (not the response) scale.
Confidence level used: 0.95
指定數字(不僅僅是范圍內的值,還有實際的最小值、平均值和最大值)會產生錯誤。
> emmeans(mod, ~machine*diameter, cov.reduce = c(1, 15, 32))
Error in fix.cr(cov.reduce) : Invalid 'cov.reduce' argument
> emmeans(mod, ~machine*diameter, cov.reduce = c( 15, 24, 32))
Error in fix.cr(cov.reduce) : Invalid 'cov.reduce' argument
我知道我可以運行兩行代碼,然后合並輸出,但我想知道是否有單行解決方案。 謝謝你。
這很容易做到,因為您可以指定任何 function。 所以試試
emmeans(..., cov.reduce = function(x) quantile(x, c(0, 0.5, 1)))
這放置了中位數而不是平均值,但是您可以編寫一個 function 來返回您想要的任何內容。 它可以是如上所示的內聯 function,也可以是單獨的 function 的名稱。
順便說一句,對於特定值,請使用at
而不是cov.reduce
。 例如,
emmeans(..., at = list(diameter = c(15, 24, 32)))
有關詳細信息,請參閱ref_grid()
的文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.