metafor 提供与原始值不同的 95% CI

发布于 2025-01-09 16:19:54 字数 1586 浏览 2 评论 0原文

我正在使用 metafor 包来组合线性回归模型中的 beta 系数。我使用了以下代码。我提供了 rma 函数报告的 se 和 beta 值。但是,当我看到森林图时,95% 置信区间与研究中报告的不同。我还尝试使用 mtcars 数据集运行三个模型并组合系数。尽管如此,我们在森林图上看到的 95% CI 仍与原始模型不同。这些偏差远非舍入误差。下面是一个可重现的示例。

library(metafor)
library(dplyr)

lm1 <- lm(hp~mpg, data=mtcars[1:15,])
lm2 <- lm(hp~mpg, data=mtcars[1:32,])
lm3 <- lm(hp~mpg, data=mtcars[13:32,])

study <- c("study1", "study2", "study3")
beta_coef <- c(lm1$coefficients[2], 
               lm2$coefficients[2], 
               lm3$coefficients[2]) %>% as.numeric()
se <- c(1.856, 1.31,1.458) 

ci_lower <- c(confint(lm1)[2,1], 
              confint(lm2)[2,1], 
              confint(lm3)[2,1]) %>% as.numeric()

ci_upper <- c(confint(lm1)[2,2], 
              confint(lm2)[2,2], 
              confint(lm3)[2,2]) %>% as.numeric()

df <- cbind(study=study, 
            beta_coef=beta_coef, 
            se=se, 
            ci_lower=ci_lower, 
            ci_upper=ci_upper) %>% as.data.frame()

pooled <- rma(yi=beta_coef, vi=se, slab=study)

forest(pooled)

输入图片此处描述

将森林图上的置信区间与数据框中的置信区间进行比较。

输入图片此处描述

数据框

df <- cbind(study=study, 
            beta_coef=beta_coef, 
            se=se, 
            ci_lower=ci_lower, 
            ci_upper=ci_upper) %>% as.data.frame()

I am using metafor package for combining beta coefficients from the linear regression model. I used the following code. I supplied the reported se and beta values for the rma function. But, when I see the forest plot, the 95% confidence intervals are different from the ones reported in the studies. I also tried it using mtcars data set by running three models and combining the coefficients. Still, the 95%CI we see on the forest plot are different from the original models. The deviations are far from rounding errors. A reproducible example is below.

library(metafor)
library(dplyr)

lm1 <- lm(hp~mpg, data=mtcars[1:15,])
lm2 <- lm(hp~mpg, data=mtcars[1:32,])
lm3 <- lm(hp~mpg, data=mtcars[13:32,])

study <- c("study1", "study2", "study3")
beta_coef <- c(lm1$coefficients[2], 
               lm2$coefficients[2], 
               lm3$coefficients[2]) %>% as.numeric()
se <- c(1.856, 1.31,1.458) 

ci_lower <- c(confint(lm1)[2,1], 
              confint(lm2)[2,1], 
              confint(lm3)[2,1]) %>% as.numeric()

ci_upper <- c(confint(lm1)[2,2], 
              confint(lm2)[2,2], 
              confint(lm3)[2,2]) %>% as.numeric()

df <- cbind(study=study, 
            beta_coef=beta_coef, 
            se=se, 
            ci_lower=ci_lower, 
            ci_upper=ci_upper) %>% as.data.frame()

pooled <- rma(yi=beta_coef, vi=se, slab=study)

forest(pooled)

enter image description here

Compare the confidence intervals on the forest plot with the one on the data frame.

enter image description here

data frame

df <- cbind(study=study, 
            beta_coef=beta_coef, 
            se=se, 
            ci_lower=ci_lower, 
            ci_upper=ci_upper) %>% as.data.frame()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丿*梦醉红颜 2025-01-16 16:19:54

参数 vi 用于指定抽样方差,但您将标准误差传递给参数。所以你应该这样做:

pooled <- rma(yi=beta_coef, sei=se, slab=study)

但是你仍然会发现这里存在差异,因为森林图中的 CI 是基于正态分布构建的,而从回归模型获得的 CI 是基于 t 分布的。如果您想要森林图中完全相同的 CI,您可以将 CI 边界传递给如下函数:

forest(beta_coef, ci.lb=ci_lower, ci.ub=ci_upper)

如果您想将某些元分析中的摘要多边形添加到森林图中,您可以使用 addpoly()。所以这个例子的完整代码是:

forest(beta_coef, ci.lb=ci_lower, ci.ub=ci_upper, ylim=c(-1.5,6))
addpoly(pooled, row=-1)
abline(h=0)

Argument vi is for specifying the sampling variances, but you are passing the standard errors to the argument. So you should do:

pooled <- rma(yi=beta_coef, sei=se, slab=study)

But you will still find a discrepancy here, since the CIs in the forest plot are constructed based on a normal distribution, while the CIs you obtained from the regression model are based on t-distributions. If you want the exact same CIs in the forest plot, you could just pass the CI bounds to the function like this:

forest(beta_coef, ci.lb=ci_lower, ci.ub=ci_upper)

If you want to add a summary polygon from some meta-analysis to the forest plot, you can do this with addpoly(). So the complete code for this example would be:

forest(beta_coef, ci.lb=ci_lower, ci.ub=ci_upper, ylim=c(-1.5,6))
addpoly(pooled, row=-1)
abline(h=0)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文