3
$\begingroup$

I would like to compile data from several published studies. I am trying to conduct a meta-regression using restricted cubic splines to analyse and plot the association between two variables (x and y), which is not linear.

Here's a simplified version of the code I used to fit the restricted cubic splines in the meta-regression:

library(metafor)

spl <- rma(y, y_se, mods = ~ rcs(x, c(1,2,3,4,5)), data=data, method="DL", random = ~ 1 | id)

However, the estimates of the regression between the knots are very high (+1111) and low (-1826), when I expected much less variation (-2 to 2).

    Model Results:

                          estimate
intrcpt                    89.7615
rcs(x, c(1,2,3,4,5))x        14.0133
rcs(x, c(1,2,3,4,5))x '     -112.4379
rcs(x, c(1,2,3,4,5))x ''    1111.1094
rcs(x, c(1,2,3,4,5))x '''  -1826.6025

And when I plot these, it gives me also a very odd plot:

with(predict(spl, dose), plot(dose, pred, type = "l"))

enter image description here

Do you have an idea why? Is this because rcs() cannot be used with rma()? If this is the problem, what is the alternative to include a restricted cubic spline model within rma()?

Thanks in advance for your help!

$\endgroup$
3
  • 3
    $\begingroup$ 1) rma() does not have a random argument. 2) You appear to pass the SE of the estimates as the second argument. However, the second argument of rma() is for the variances. Either use rma(y, y_se^2, ...) or rma(y, sei=y_se, ...). 3) You also may want to mention that rcs() comes from the rms package. Note that 1) and 2) do not explain these strange results. In general, rma() plays nicely with rcs(), but unless you provide a fully reproducible example illustrating the problems you are encountering, it will be next to impossible for me (or anybody else) to help. $\endgroup$
    – Wolfgang
    May 15, 2017 at 20:22
  • $\begingroup$ Unfortunately the plot still looks odd. I think that there is something wrong with the way I am plotting the results... Do you have an example on how to plot a line with the results of a rma() including restricted cubic splines and the 95% confidence interval upper and lower bounds? $\endgroup$
    – user1505
    May 16, 2017 at 12:31
  • $\begingroup$ Without more detail this is going to be hard to unpick as @wolfgang states. We do notkknow (a) how many studies you have (b) what x is (c) what scientific question is leading to a spline function. $\endgroup$
    – mdewey
    May 16, 2017 at 17:24

1 Answer 1

3
$\begingroup$

Here is an example to illustrate the use of a restricted cubic spline with metafor.

library(metafor)
library(rms)

### load data
dat <- get(data(dat.raudenbush1985, package="metafor"))

### plot data
with(dat, plot(weeks, yi, pch=19, xlab="Weeks", ylab="Standardized Mean Difference"))
xs <- seq(0,25,by=1)

### linear model
res <- rma(yi ~ weeks, vi, data=dat)
lines(xs, predict(res, newmods=xs)$pred, lwd=2)

### model with restricted cubic spline
knots <- c(1,2,5,10)
res <- rma(yi~rcs(weeks,knots), vi, data=dat)
lines(xs, predict(res, newmods=rcspline.eval(xs, knots, inclx=TRUE))$pred, col="red", lwd=2)

Scatterplot with Regression Lines

$\endgroup$
1
  • $\begingroup$ This is exactly what I needed: I used your example and it worked perfectly! Thank you very much! $\endgroup$
    – user1505
    May 18, 2017 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.