[R-meta] Plotting confidence intervals around regression slope using rma.mv
Bronwen Stanford
bstanfor at ucsc.edu
Mon Mar 12 20:02:30 CET 2018
I am trying to plot the regression line estimated using metafor and 95%
confidence intervals on the regression line, and I'm not sure how to do
this. Here is an example of what I'm hoping to create using lm from base R:
https://stat.ethz.ch/pipermail/r-help/2007-November/146285.html
The model has random effects, but for the purposes of this plot, I'm
interested in just plotting the slope of one predictor and the CI for that
predictor, ignoring the random effects.
Do I need to use a model matrix (along these lines
http://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#lme4) ? And if so,
does anyone have any example syntax that I could follow? I tried adapting
the linked example, and ran into a lot of problems.
Here is a dummy example (that isn't working). I'm interested in plotting
values of y against x while holding "a" constant:
#create example data
df<-data.frame(expand.grid(
a=seq(0,1, length=2), #covariate
x=seq(0,1, length=5), #predictor I want to plot
y=seq(0,5, length=5), #response
vi=seq(.1,.5, length=2), #variance
ID=c("A","B") #random effect
))
#run the model
m1<-rma.mv(y, V=vi,
mods= ~ a + x,
random=(~1|ID), struct="DIAG",
data=df)
#create new df to use for predictions, only allowing x to vary
df1<-data.frame(expand.grid(
a=mean(df$a),
x=seq(0,1, length=5)
))
d1f$preds<-predict(m1, newmods=df1, interval=c("confidence"))
I get the message "Error in Xi.new %*% x$beta : requires numeric/complex
matrix/vector arguments".
[[alternative HTML version deleted]]
More information about the R-sig-meta-analysis
mailing list