在metafor中为带有样条线的多变量模型生成regplot(边际关系)

发布于 2025-01-17 02:52:09 字数 1788 浏览 4 评论 0原文

我试图使用 metafor 包中的 regplot() 生成回归图,通过使用 rms 将连续预测器拟合为受限三次样条 R 中的包,在多变量回归的背景下。

但是,仔细查看此处列出的所有示例后: https://wviechtb.github.io /metafor/reference/regplot.html,我无法重现所需的图(即,建模为受限三次样条的连续预测器的回归图)。

这是一个可重现的示例:

library(metafor)
library(rms)
dat <- dat.bcg

#Fitting the meta-analysis
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat)

#Fit a multivariable meta-regression with ablat as a rcs with 3 knots
res <- rma(yi, vi, mods = ~ rcs(ablat,3)+year+alloc, data=dat)

模型的结果报告如下:

Model Results:

                     estimate       se     zval    pval      ci.lb    ci.ub   ​ 
intrcpt              -24.8731  38.8083  -0.6409  0.5216  -100.9361  51.1898    
rcs(ablat, 3)ablat     0.0043   0.0290   0.1497  0.8810    -0.0525   0.0611    
rcs(ablat, 3)ablat'   -0.0504   0.0466  -1.0799  0.2802    -0.1418   0.0410    
year                   0.0125   0.0196   0.6384  0.5232    -0.0259   0.0509    
allocrandom           -0.3525   0.4090  -0.8618  0.3888    -1.1541   0.4491    
allocsystematic       -0.2187   0.4832  -0.4526  0.6508    -1.1659   0.7284  

现在,如果我想生成该模型的正则图(即样条预测变量和效应大小之间的边际关系),我必须使用:

regplot(res, mod="rcs(ablat, 3)ablat")

但是生成的图(如下报告)在我看来,只考虑了样条建模变量的第一项: 输入图片描述在这里

始终如一,如果我将 regplot 的调用更改为 regplot(res, mod="rcs(ablat, 3)ablat'") (即,指定多变量回归模型中 ablat 的非线性项作为调节变量)。

我尝试通过 predict() 函数预先指定预测,然后将参数传递给 regplot,但我仍然无法生成所需的绘图。

I was trying to produce a regression plot with the regplot() in the metafor package, fitting a continuous predictor as a restricted cubic spline through the use of the rms package in R, in the context of a multivariable regression.

However, after carefully reviewing all the examples listed here: https://wviechtb.github.io/metafor/reference/regplot.html, I was unable to reproduce the plot desired (i.e., the regression plot of the continuous predictor modelled as a restricted cubic spline).

Here is a reproducible example:

library(metafor)
library(rms)
dat <- dat.bcg

#Fitting the meta-analysis
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat)

#Fit a multivariable meta-regression with ablat as a rcs with 3 knots
res <- rma(yi, vi, mods = ~ rcs(ablat,3)+year+alloc, data=dat)

The result of the model is reported below:

Model Results:

                     estimate       se     zval    pval      ci.lb    ci.ub   ​ 
intrcpt              -24.8731  38.8083  -0.6409  0.5216  -100.9361  51.1898    
rcs(ablat, 3)ablat     0.0043   0.0290   0.1497  0.8810    -0.0525   0.0611    
rcs(ablat, 3)ablat'   -0.0504   0.0466  -1.0799  0.2802    -0.1418   0.0410    
year                   0.0125   0.0196   0.6384  0.5232    -0.0259   0.0509    
allocrandom           -0.3525   0.4090  -0.8618  0.3888    -1.1541   0.4491    
allocsystematic       -0.2187   0.4832  -0.4526  0.6508    -1.1659   0.7284  

Now if I want to produce a regplot of this model (i.e., the marginal relationship between the spline predictor and the effect size), I must use:

regplot(res, mod="rcs(ablat, 3)ablat")

But the resulting plot (reported below) seems to me taking into account only the first term of the spline-modelled variable:
enter image description here

Consistently, I am able to produce another plot if I change my call of regplot to regplot(res, mod="rcs(ablat, 3)ablat'") (i.e., specifying as the moderator variable the non-linear term of ablat in the multivariable regression model).

I have tried to pre-specify prediction through the predict() function and then passing the argument to regplot, but I am still unable to produce the desired plot.

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

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

发布评论

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

评论(1

⒈起吃苦の倖褔 2025-01-24 02:52:09

我在这里发布解决方案,在评论中 @Wolfgang 的不可估量的帮助后,我设法安排了该解决方案,以防万一其他人将来需要:

res <- rma(yi, vi, mods = ~ rcs(ablat,3)+year+alloc, data=dat)

knots <- attr(rcs(model.matrix(res)[,2], 3), "parms")
knots
xs <- seq(10,60, length=500)
sav <- predict(res, newmods=cbind(rcspline.eval(xs, knots, inclx=TRUE),colMeans(model.matrix(res))[4],
                                  colMeans(model.matrix(res))[5],colMeans(model.matrix(res))[6]))
tmp <- regplot(res, mod=2, pred=sav, xvals=xs, las=1, digits=1, bty="l",
               psize=.20/sqrt(dat$vi), xlab="Predictor", main="Restricted Cubic Spline Model", transf=exp)
abline(v=knots, lty="dotted")
points(tmp)

这是结果图,代表 rcs 的边际关系(ablat,3) 效果大小:

在此处输入图像描述

I am posting here the solution, that I have managed to arrange after the inestimable help of @Wolfgang in the comments, just in case someone else needs in the future:

res <- rma(yi, vi, mods = ~ rcs(ablat,3)+year+alloc, data=dat)

knots <- attr(rcs(model.matrix(res)[,2], 3), "parms")
knots
xs <- seq(10,60, length=500)
sav <- predict(res, newmods=cbind(rcspline.eval(xs, knots, inclx=TRUE),colMeans(model.matrix(res))[4],
                                  colMeans(model.matrix(res))[5],colMeans(model.matrix(res))[6]))
tmp <- regplot(res, mod=2, pred=sav, xvals=xs, las=1, digits=1, bty="l",
               psize=.20/sqrt(dat$vi), xlab="Predictor", main="Restricted Cubic Spline Model", transf=exp)
abline(v=knots, lty="dotted")
points(tmp)

And here's the resulting plot, with represent the marginal relation of rcs(ablat,3) with the effect size:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文