I have tried everything: Different functions and changed the way I type in the confidence interval (CI) that I want. I need a CI for correlations that ranges from -1 to 1 by 0.5 steps.
my R-code:
data <- escalc(measure = "ZCOR",
ri = data$r,
ni = data$Sample_Size,
data = data,
vtype = "LS",
append = TRUE)
View(data)
## random effect model
res <- rma(yi, vi, data = data)
res #tau^2 = 0.0260, I^2= 95.92%, H^2= 24.51
confint(res)
### Forest plot
forest(res,
addpred = TRUE,
slab = paste(data$Authors, data$Publication.year, sep = ", "),
xlim = c(-10, 7),
ylim=c(-1,23),
alim = c(-1, 1),
at = seq(-1, 1, by = 0.5),
atransf = transf.ztor,
header="Author(s) and Year",
efac = 1,
xlab = "Correlation coefficient (Pearson's r)",
cex= 1)
op <- par(cex = 1, font = 2) #cex ist die Textgrösse der Beschriftungen
#text(-16, 18, "Author(s) and Year", pos = 4) #Links
#text(7, 18, "Pearson's r [95% CI]", pos = 2) #rechts
text(3.5, 22, "SW", pos = 2)
par(op)
I looked it up at the website of the metaphor package and it didn't help me. https://wviechtb.github.io/metafor/reference/forest.rma.html
You are doing an axis transformation (atransf = transf.ztor
) in which case you have to apply the reverse transformation to the at
values. Here is a reproducible example:
library(metafor)
### copy dat.molloy2014 to dat and keep only the variables we need here
dat <- dat.molloy2014
dat <- dat[1:4]
### change one correlation to 0.7
dat$ri[1] <- 0.7
### calculate r-to-z transformed correlations and corresponding sampling variances
dat <- escalc(measure="ZCOR", ri=ri, ni=ni, data=dat, slab=paste(authors, year, sep=", "))
dat
### meta-analysis of the transformed correlations using a random-effects model
res <- rma(yi, vi, data=dat)
res
### average correlation with 95% CI
predict(res, digits=3, transf=transf.ztor)
### forest plot
forest(res, addpred=TRUE, xlim=c(-1.6,1.6), atransf=transf.ztor,
at=transf.rtoz(seq(-0.6, 0.8, by=0.2)), digits=c(2,1), cex=0.9,
header="Author(s), Year")
Note the use of transf.rtoz()
on the at
values. But you cannot use transf.rtoz(seq(-1, 1, by=0.5))
because for -1 and 1, the transformed values correspond to -Inf
and Inf
. In other words, when doing such an axis transformation, the values -1 and 1 on the x-axis would correspond to values that are infinitely far away from 0, which obviously doesn't work. So you will either have to use some other finite bounds or not do an axis transformation and instead directly back-transform all values with the transf
argument. For the example:
### forest plot
forest(res, addpred=TRUE, xlim=c(-1.6,1.6), transf=transf.ztor,
at=seq(-0.6, 1, by=0.2), digits=c(2,1), cex=0.9,
header="Author(s), Year")
Now you can directly specify the at
values (including -1 and 1). Since transf.ztor()
is a non-linear transformation, note that the resulting CIs are now visibly asymmetric (they are asymmetric no matter how you do the back-transformation, but with the axis transformation, they are visually symmetric), although unless the correlations are very large, the asymmetry is hardly visible (even on the first correlation which I turned into a 0.7).