微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

比较拟合模型时,如何使用 (pool.compare) 函数解决“已弃用”警告?

如何解决比较拟合模型时,如何使用 (pool.compare) 函数解决“已弃用”警告?

我有两个模型,我在一个估算数据集上运行这些模型以生成汇总估计值。我的理解是,因为这两个模型都运行了数百个估算数据帧,所以我必须将所有回归模型估计汇集或基本上“平均”成一个“整体”估计。以下是我所做的步骤:

#1 ImpuTE MASTER DATASET
     imputed_data <- mice(master,m=20,maxit=50,seed=5798713)

#2 RUN LINEAR MODEL 
     model.linear <- with(imputed_data,lm(outcome~exposure+age+gender+weight))
     summary(pool(model.linear))

#3 RUN NON-LINEAR RESTRICTED CUBIC SPLINE (3-KNOT) MODEL
     model.rcs <- with(imputed_data,lm(outcome~rcs(exposure,3)+age+gender+weight))
     summary(pool(model.rcs))

#4 COMPARE BOTH MODELS USING POOL.COMPARE FUNCTION
     pool.compare(model.rcs,model.linear)

一旦我使用“summary(pool(..)”函数,线性和 RCS 模型都会产生“合并”估计、95% CI 和 p 值。但是,问题是当我运行“池”时。 compare" 函数,我收到一个错误消息:

Error: Model 'fit0' not contained in 'fit1'
In addition: Warning message:
'pool.compare' is deprecated.
Use 'D1' instead.
See help("Deprecated") 

当“曝光”、“结果”和列出的所有协变量在线性模型和 RCS 模型之间相同时,我不明白为什么模型说 fit0 不包含在 fit1 中。有没有我在这里缺少的选项?

非常感谢任何帮助/指导。

附言不幸的是,考虑到估算数据集的大小,我无法提供示例数据切割。如果有任何疑问,请告诉我如何更好地改进我的问题。

解决方法

正如错误所说,pool.compare 已弃用。而是使用 D1

library(mice)
library(rms)
D1(model.rcs,model.linear)
#    test statistic df1      df2 dfcom    p.value      riv
# 1 ~~ 2  6.248565   2 8.635754    20 0.02098072 0.449098

在一些例子中,只有警告,但在其他例子中,它同时给出错误和警告

pool.compare(model.rcs,model.linear)
#Error: Model 'fit0' not contained in 'fit1'
#In addition: Warning message:
#  'pool.compare' is deprecated.
#Use 'D1' instead.
#See help("Deprecated") 

错误是因为模型本身,即 rcs 模型,而下面我们正在比较两个线性模型

imp <- mice(nhanes)
model.linear <- with(imp,lm(age ~ bmi + hyp + chl))
model.rcs <- with(imp,lm(age ~ rcs(bmi,3) + hyp + chl))

可重现的例子

imp <- mice(nhanes2,print=FALSE,m=50,seed=00219)
fit0 <- with(data=imp,expr=lm(bmi~age+hyp))
fit1 <- with(data=imp,expr=lm(bmi~age+hyp+chl))
stat <- pool.compare(fit1,fit0)
#Warning message:
#'pool.compare' is deprecated.
#Use 'D1' instead.
#See help("Deprecated") 

stat <- D1(fit1,fit0)
stat
#   test statistic df1     df2 dfcom    p.value       riv
# 1 ~~ 2  7.606026   1 16.2182    20 0.01387548 0.3281893

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。