使用 vcov 命令自动化模型

问题描述

我正在对许多暴露和结果运行一系列回归模型。此代码用于玩具示例。

我希望使用 vcov 命令为结果列表中的所有模型调整标准误差,但它不起作用。我已经展示了我的代码

ivs_vec <- names(data)[c(2:5)] #Replace with numbers from prevIoUs step
dvs_vec <- names(data)[c(7:9)] #Replace with continuous phenotype columns
ivs <- paste0(" ~ ",ivs_vec)

dvs_ivs <- unlist(lapply(ivs,function(x) paste0(dvs_vec,x))) ##given a list x,unlist simplifies to produce a vector
formulas <- lapply(dvs_ivs,formula)

lm_results <- lapply(formulas,function(x) {
  lm(x,data=data)
})

应用以下内容,我收到以下错误

h <- lapply(lm_results,function(x) coeftest(x,vcov ="HC1")) 
Error message: 
Error in diag(se) : invalid 'nrow' value (too large or NA)
In addition: Warning message:
In diag(se) : NAs introduced by coercion
Called from: diag(se)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)