问题描述
使用 lmerTest::lmer()
对重复测量数据执行线性回归后,我想针对多重比较进行调整。
我运行了几个模型并使用 Bonferroni-Holm 来调整每个模型,请参阅下面的方法。
最后,我想用 modelsummary 生成一个回归表,其中应包括调整后的 p 值和额外的拟合优度统计数据(类似于 this SO post)。
– 也许 modelsummary()
中还有一种更简单的方法来调整我还不知道的 p 值?
(单独用于模型以及用于/跨一组模型)
MWE
library("modelsummary")
library("lmerTest")
library("parameters")
library("performance")
mod1 <- lmer(mpg ~ hp + (1 | cyl),data = mtcars)
mod2 <- lmer(mpg ~ hp + (1 | gear),data = mtcars)
l_mod <- list("mod1" = mod1,"mod2" = mod2)
# msummary(l_mod) # works well
adjMC <- function( model ) {
model_glht <- glht(model)
model_mc_adj <- summary(model_glht,test = adjusted('holm')) # Bonferroni-Holm is less conservative and uniformly more powerful than Bonferroni
return(model_mc_adj)
}
mod1_adj <- adjMC(mod1)
mod2_adj <- adjMC(mod2)
l_mod_adj <- list("mod1_adj" = mod1_adj,"mod2_adj" = mod2_adj)
但是,在调整 p 值后,模型中的类从“lmerModLmerTest”变为“summary.glht”
class(mod1) # => "lmerModLmerTest"
class(mod1_adj) # => "summary.glht"
"summary.glht" 在 list of supported models of modelsummary 中, 我成功地获得了估计值和 p 值:
parameters::model_parameters(mod1_adj)
# Parameter | Coefficient | SE | 95% CI | Statistic | df | p
# --------------------------------------------------------------------------------
# (Intercept) == 0 | 24.71 | 3.13 | [17.84,31.57] | 7.89 | 0 | < .001
# hp == 0 | -0.03 | 0.01 | [-0.06,0.00] | -2.09 | 0 | 0.064
# e.g. with modelsummary:
modelsummary::get_estimates(mod1_adj) # gives more info than broom::tidy(mod1_adj)
然而,获得拟合优度统计数据并没有成功:
performance::model_performance(mod1_adj)
# 'r2()' does not support models of class 'summary.glht'.
# Can't extract residuals from model.
# no 'nobs' method is availableModels of class 'summary.glht' are not yet supported.NULL
broom::glance(mod1_adj) # and also for broom.mixed::glance(mod1_adj)
# => Error: No glance method for objects of class summary.glht
# e.g. with modelsummary:
modelsummary::get_gof(mod1_adj)
# => Cannot extract information from models of class "summary.glht".
为了能够在最终回归表中包含调整后的 p 值,我尝试使用自定义函数为“summary.glht”生成自定义类,以提取估计值和拟合优度信息。
我扫描了 summary(mod1_adj)
以获取所需信息,例如 summary(mod1_adj)$coef
,但没有找到创建 fcts 所需的所有信息。
names(mod1_adj$test)
# [1] "pfunction" "qfunction" "coefficients" "sigma" "tstat" "pvalues" "type"
tidy.summary.glht <- function(x,...) {
s <- summary(x,...)
ret <- tibble::tibble(term = ...,estimate = s$test$coefficients,... = ...,p-values = s$test$pvalues)
ret
}
glance.summary.glht <- function(x,...) {
data.frame(
"Model" = "summary.glht",... = ...,"nobs" = stats::nobs(x)
)
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)