predict.rma.Rd
The function computes predicted values, corresponding standard errors, confidence intervals, and prediction intervals for objects of class "rma"
.
# S3 method for class 'rma'
predict(object, newmods, intercept, tau2.levels, gamma2.levels, addx=FALSE,
level, adjust=FALSE, digits, transf, targs, vcov=FALSE, ...)
# S3 method for class 'rma.ls'
predict(object, newmods, intercept, addx=FALSE, newscale, addz=FALSE,
level, adjust=FALSE, digits, transf, targs, vcov=FALSE, ...)
an object of class "rma"
or "rma.ls"
.
optional vector or matrix to specify the values of the moderator values for which the predicted values should be calculated. See ‘Details’.
logical to specify whether the intercept should be included when calculating the predicted values for newmods
. If unspecified, the intercept is automatically added when the original model also included an intercept.
vector to specify the levels of the inner factor when computing prediction intervals. Only relevant for models of class "rma.mv"
(see rma.mv
) and when the model includes more than a single \(\tau^2\) value. See ‘Details’.
vector to specify the levels of the inner factor when computing prediction intervals. Only relevant for models of class "rma.mv"
(see rma.mv
) and when the model includes more than a single \(\gamma^2\) value. See ‘Details’.
logical to specify whether the values of the moderator variables should be added to the returned object. See ‘Examples’.
optional vector or matrix to specify the values of the scale variables for which the predicted values should be calculated. Only relevant for location-scale models (see rma.uni
). See ‘Details’.
logical to specify whether the values of the scale variables should be added to the returned object.
numeric value between 0 and 100 to specify the confidence and prediction interval level (see here for details). If unspecified, the default is to take the value from the object.
logical to specify whether the width of confidence/prediction intervals should be adjusted using a Bonferroni correction (the default is FALSE
).
optional integer to specify the number of decimal places to which the printed results should be rounded.
optional argument to specify a function to transform the predicted values and interval bounds (e.g., transf=exp
; see also transf). If unspecified, no transformation is used.
optional arguments needed by the function specified under transf
.
logical to specify whether the variance-covariance matrix of the predicted values should also be returned (the default is FALSE
).
other arguments.
For an equal-effects model, predict(object)
returns the estimated (average) outcome in the set of studies included in the meta-analysis. This is the same as the estimated intercept in the equal-effects model (i.e., \(\hat{\theta}\)).
For a random-effects model, predict(object)
returns the estimated (average) outcome in the hypothetical population of studies from which the set of studies included in the meta-analysis are assumed to be a random selection. This is the same as the estimated intercept in the random-effects model (i.e., \(\hat{\mu}\)).
For models including one or more moderators, predict(object)
returns \(\hat{y} = Xb\), where \(X\) denotes the model matrix (see model.matrix
) and \(b\) the estimated model coefficient (see coef
), or in words, the estimated (average) outcomes for values of the moderator(s) equal to those of the \(k\) studies included in the meta-analysis (i.e., the ‘fitted values’ for the \(k\) studies).
For models including \(p'\) moderator variables, new moderator values (for \(k_{new}\) hypothetical new studies) can be specified by setting newmods
equal to a \(k_{new} \times p'\) matrix with the corresponding new moderator values (if newmods
is a vector, then only a single predicted value is computed unless the model only includes a single moderator variable, in which case predicted values corresponding to all the vector values are computed). If the model object includes an intercept (so that the model matrix has \(p' + 1\) columns), then it will be automatically added to newmods
unless one sets intercept=FALSE
; alternatively, if newmods
is a \(k_{new} \times (p'+1)\) matrix, then the intercept
argument is ignored and the first column of the matrix determines whether the intercept is included when computing the predicted values or not. Note that any factors in the original model get turned into the appropriate contrast variables within the rma.uni
function, so that newmods
should actually include the values for the contrast variables. If the matrix specified via newmods
has row names, then these are used to label the predicted values in the output. Examples are shown below.
For random/mixed-effects models, a prediction interval is also computed (Riley et al., 2011, but see ‘Note’). The interval estimates where level
% of the true effect sizes or outcomes fall in the hypothetical population of studies (and hence where the true effect or outcome of a new study from the population of studies should fall in level
% of the cases).
For random-effects models that were fitted with the rma.mv
function, the model may actually include multiple \(\tau^2\) values (i.e., when the random
argument includes an ‘~ inner | outer
’ term and struct="HCS"
, struct="DIAG"
, struct="HAR"
, or struct="UN"
). In that case, the function will provide prediction intervals for each level of the inner factor (since the prediction intervals differ depending on the \(\tau^2\) value). Alternatively, one can use the tau2.levels
argument to specify for which level(s) the prediction interval should be provided. If the model includes a second ‘~ inner | outer
’ term with multiple \(\gamma^2\) values, prediction intervals for each combination of levels of the inner factors will be provided. Alternatively, one can use the tau2.levels
and gamma2.levels
arguments to specify for which level combination(s) the prediction interval should be provided.
When using the newmods
argument for mixed-effects models that were fitted with the rma.mv
function, if the model includes multiple \(\tau^2\) (and multiple \(\gamma^2\)) values, then one must use the tau2.levels
(and gamma2.levels
) argument to specify the levels of the inner factor(s) (i.e., a vector of length \(k_{new}\)) to obtain the appropriate prediction interval(s).
For location-scale models fitted with the rma.uni
function, one can use newmods
to specify the values of the \(p'\) moderator variables included in the model and newscale
to specify the values of the \(q'\) scale variables included in the model. Whenever newmods
is specified, the function computes predicted effects/outcomes for the specified moderators values. To obtain the corresponding prediction intervals, one must also specify the corresponding newscale
values. If only newscale
is specified (and not newmods
), the function computes the predicted log-transformed \(\tau^2\) values (when using a log link) for the specified scale values. By setting transf=exp
, one can then obtain the predicted \(\tau^2\) values.
When computing multiple predicted values, one can set adjust=TRUE
to obtain confidence/prediction intervals whose width is adjusted based on a Bonferroni correction (e.g., instead of 95% CIs, the function provides (100-5/\(k_{new}\))% CIs, where \(k_{new}\) denotes the number of predicted values computed).
An object of class c("predict.rma","list.rma")
. The object is a list containing the following components:
predicted value(s).
corresponding standard error(s).
lower bound of the confidence interval(s).
upper bound of the confidence interval(s).
lower bound of the prediction interval(s) (only for random/mixed-effects models).
upper bound of the prediction interval(s) (only for random/mixed-effects models).
the level(s) of the inner factor (only for models of class "rma.mv"
with multiple \(\tau^2\) values).
the level(s) of the inner factor (only for models of class "rma.mv"
with multiple \(\gamma^2\) values).
the moderator value(s) used to calculate the predicted values (only when addx=TRUE
).
the scale value(s) used to calculate the predicted values (only when addz=TRUE
and only for location-scale models).
some additional elements/values.
If vcov=TRUE
, then the returned object is a list with the first element equal to the one as described above and the second element equal to the variance-covariance matrix of the predicted values.
The object is formatted and printed with the print
function. To format the results as a data frame, one can use the as.data.frame
function.
Confidence and prediction intervals are constructed based on the critical values from a standard normal distribution (i.e., \(\pm 1.96\) for level=95
). When the model was fitted with test="t"
, test="knha"
, test="hksj"
, or test="adhoc"
, then a t-distribution with \(k-p\) degrees of freedom is used, where \(p\) denotes the total number of columns of the model matrix (i.e., counting the intercept term if the model includes one).
For a random-effects model (where \(p=1\)) fitted with the rma.uni
function, note that this differs slightly from Riley et al. (2011), who suggest to use a t-distribution with \(k-2\) degrees of freedom for constructing the prediction interval. Neither a normal, nor a t-distribution with \(k-1\) or \(k-2\) degrees of freedom is correct; all of these are approximations. The computations are done in the way described above, so that the prediction interval is identical to the confidence interval when \(\hat{\tau}^2 = 0\), which could be argued is the logical thing that should happen. If the prediction interval for a random-effects model should be computed as described by Riley et al. (2011), then one can use argument pi.type="Riley"
(and for mixed-effects meta-regression models, the function then uses \(k-p-1\) degrees of freedom).
The predicted values are based only on the fixed effects of the model. Best linear unbiased predictions (BLUPs) that combine the fitted values based on the fixed effects and the estimated contributions of the random effects can be obtained with blup
(currently only for objects of class "rma.uni"
).
When using the transf
option, the transformation is applied to the predicted values and the corresponding interval bounds. The standard errors are omitted from the printed output. Also, vcov=TRUE
is ignored when using the transf
option.
Hedges, L. V., & Olkin, I. (1985). Statistical methods for meta-analysis. San Diego, CA: Academic Press.
Riley, R. D., Higgins, J. P. T., & Deeks, J. J. (2011). Interpretation of random effects meta-analyses. British Medical Journal, 342, d549. https://doi.org/10.1136/bmj.d549
Viechtbauer, W. (2010). Conducting meta-analyses in R with the metafor package. Journal of Statistical Software, 36(3), 1–48. https://doi.org/10.18637/jss.v036.i03
Viechtbauer, W., & López-López, J. A. (2022). Location-scale models for meta-analysis. Research Synthesis Methods. 13(6), 697–715. https://doi.org/10.1002/jrsm.1562
### calculate log risk ratios and corresponding sampling variances
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)
### fit random-effects model
res <- rma(yi, vi, data=dat)
### estimated average log risk ratio with 95% CI/PI
predict(res, digits=2)
#>
#> pred se ci.lb ci.ub pi.lb pi.ub
#> -0.71 0.18 -1.07 -0.36 -1.87 0.44
#>
### estimated average risk ratio with 95% CI/PI
predict(res, transf=exp, digits=2)
#>
#> pred ci.lb ci.ub pi.lb pi.ub
#> 0.49 0.34 0.70 0.15 1.55
#>
### note: strictly speaking, the value obtained is the estimated median risk ratio
### because exponentiation is a non-linear transformation; but we can estimate the
### average risk ratio by using the integral transformation
predict(res, transf=transf.exp.int, targs=res$tau2, digits=2)
#>
#> pred ci.lb ci.ub pi.lb pi.ub
#> 0.57 0.40 0.81 0.18 1.81
#>
### fit mixed-effects model with absolute latitude as a moderator
res <- rma(yi, vi, mods = ~ ablat, data=dat)
### predicted average risk ratios for given absolute latitude values
predict(res, transf=exp, addx=TRUE)
#>
#> pred ci.lb ci.ub pi.lb pi.ub X.intrcpt X.ablat
#> 1 0.3574 0.2714 0.4705 0.1947 0.6560 1 44
#> 2 0.2595 0.1749 0.3848 0.1328 0.5070 1 55
#> 3 0.3788 0.2927 0.4901 0.2079 0.6900 1 42
#> 4 0.2831 0.1977 0.4054 0.1478 0.5422 1 52
#> 5 0.8809 0.6321 1.2276 0.4667 1.6625 1 13
#> 6 0.3574 0.2714 0.4705 0.1947 0.6560 1 44
#> 7 0.7397 0.5639 0.9704 0.4036 1.3557 1 19
#> 8 0.8809 0.6321 1.2276 0.4667 1.6625 1 13
#> 9 0.5861 0.4716 0.7284 0.3270 1.0505 1 27
#> 10 0.3788 0.2927 0.4901 0.2079 0.6900 1 42
#> 11 0.7616 0.5752 1.0083 0.4138 1.4016 1 18
#> 12 0.4922 0.3989 0.6073 0.2753 0.8799 1 33
#> 13 0.4922 0.3989 0.6073 0.2753 0.8799 1 33
#>
### predicted average risk ratios for 10-60 degrees absolute latitude
predict(res, newmods=c(10, 20, 30, 40, 50, 60), transf=exp, addx=TRUE)
#>
#> pred ci.lb ci.ub pi.lb pi.ub X.intrcpt X.ablat
#> 1 0.9612 0.6668 1.3857 0.5000 1.8478 1 10
#> 2 0.7185 0.5526 0.9343 0.3936 1.3117 1 20
#> 3 0.5371 0.4355 0.6623 0.3005 0.9600 1 30
#> 4 0.4015 0.3151 0.5115 0.2218 0.7266 1 40
#> 5 0.3001 0.2144 0.4201 0.1586 0.5678 1 50
#> 6 0.2243 0.1423 0.3538 0.1105 0.4552 1 60
#>
### can also include the intercept term in the 'newmods' matrix
predict(res, newmods=cbind(1, c(10, 20, 30, 40, 50, 60)), transf=exp, addx=TRUE)
#>
#> pred ci.lb ci.ub pi.lb pi.ub X.intrcpt X.ablat
#> 1 0.9612 0.6668 1.3857 0.5000 1.8478 1 10
#> 2 0.7185 0.5526 0.9343 0.3936 1.3117 1 20
#> 3 0.5371 0.4355 0.6623 0.3005 0.9600 1 30
#> 4 0.4015 0.3151 0.5115 0.2218 0.7266 1 40
#> 5 0.3001 0.2144 0.4201 0.1586 0.5678 1 50
#> 6 0.2243 0.1423 0.3538 0.1105 0.4552 1 60
#>
### apply a Bonferroni correction for obtaining the interval bounds
predict(res, newmods=cbind(1, c(10, 20, 30, 40, 50, 60)), transf=exp, addx=TRUE, adjust=TRUE)
#>
#> pred ci.lb ci.ub pi.lb pi.ub X.intrcpt X.ablat
#> 1 0.9612 0.5875 1.5727 0.3988 2.3167 1 10
#> 2 0.7185 0.5046 1.0232 0.3196 1.6155 1 20
#> 3 0.5371 0.4051 0.7121 0.2458 1.1736 1 30
#> 4 0.4015 0.2898 0.5562 0.1806 0.8922 1 40
#> 5 0.3001 0.1908 0.4720 0.1272 0.7079 1 50
#> 6 0.2243 0.1215 0.4142 0.0865 0.5815 1 60
#>
### fit mixed-effects model with absolute latitude and publication year as moderators
res <- rma(yi, vi, mods = ~ ablat + year, data=dat)
### predicted average risk ratios for 10 and 60 degrees latitude in 1950 and 1980
predict(res, newmods=cbind(c(10,60,10,60),c(1950,1950,1980,1980)), transf=exp, addx=TRUE)
#>
#> pred ci.lb ci.ub pi.lb pi.ub X.intrcpt X.ablat X.year
#> 1 0.8995 0.3689 2.1933 0.2981 2.7146 1 10 1950
#> 2 0.2217 0.1278 0.3847 0.0944 0.5208 1 60 1950
#> 3 0.9525 0.6199 1.4637 0.4361 2.0802 1 10 1980
#> 4 0.2348 0.1005 0.5481 0.0805 0.6843 1 60 1980
#>
### predicted average risk ratios for 10 and 60 degrees latitude in 1970 (row names as labels)
predict(res, newmods=rbind(at10=c(10,1970), at60=c(60,1970)), transf=exp)
#>
#> pred ci.lb ci.ub pi.lb pi.ub
#> at10 0.9345 0.5833 1.4973 0.4179 2.0899
#> at60 0.2303 0.1209 0.4386 0.0921 0.5761
#>
### fit mixed-effects model with two moderators (one of which is a factor)
res <- rma(yi, vi, mods = ~ ablat + factor(alloc), data=dat)
### examine how the factor was actually coded for the studies in the dataset
predict(res, addx=TRUE)
#>
#> pred se ci.lb ci.ub pi.lb pi.ub X.intrcpt X.ablat X.factor.alloc.random
#> 1 -1.1744 0.2137 -1.5932 -0.7557 -2.0293 -0.3196 1 44 1
#> 2 -1.4745 0.2742 -2.0119 -0.9370 -2.3933 -0.5556 1 55 1
#> 3 -1.1199 0.2061 -1.5238 -0.7159 -1.9676 -0.2722 1 42 1
#> 4 -1.3926 0.2552 -1.8928 -0.8925 -2.2902 -0.4951 1 52 1
#> 5 -0.0614 0.3336 -0.7152 0.5924 -1.0528 0.9300 1 13 0
#> 6 -0.9069 0.3176 -1.5295 -0.2844 -1.8780 0.0642 1 44 0
#> 7 -0.4925 0.2338 -0.9508 -0.0343 -1.3674 0.3823 1 19 1
#> 8 -0.3289 0.2694 -0.8568 0.1991 -1.2422 0.5845 1 13 1
#> 9 -0.7107 0.2007 -1.1040 -0.3175 -1.5534 0.1320 1 27 1
#> 10 -0.7939 0.2667 -1.3166 -0.2712 -1.7042 0.1164 1 42 0
#> 11 -0.1393 0.2654 -0.6594 0.3808 -1.0481 0.7695 1 18 0
#> 12 -0.5484 0.2438 -1.0263 -0.0706 -1.4337 0.3369 1 33 0
#> 13 -0.5484 0.2438 -1.0263 -0.0706 -1.4337 0.3369 1 33 0
#> X.factor.alloc.systematic
#> 1 0
#> 2 0
#> 3 0
#> 4 0
#> 5 0
#> 6 0
#> 7 0
#> 8 0
#> 9 0
#> 10 1
#> 11 1
#> 12 1
#> 13 1
#>
### predicted average risk ratios at 30 degrees for the three factor levels
### note: the contrast (dummy) variables need to specified explicitly here
predict(res, newmods=c(30, 0, 0), addx=TRUE) # for alternate allocation
#>
#> pred se ci.lb ci.ub pi.lb pi.ub X.intrcpt X.ablat X.factor.alloc.random
#> -0.5251 0.2923 -1.0980 0.0478 -1.4651 0.4149 1 30 0
#> X.factor.alloc.systematic
#> 0
#>
predict(res, newmods=c(30, 1, 0), addx=TRUE) # for random allocation
#>
#> pred se ci.lb ci.ub pi.lb pi.ub X.intrcpt X.ablat X.factor.alloc.random
#> -0.7926 0.1941 -1.1729 -0.4122 -1.6293 0.0442 1 30 1
#> X.factor.alloc.systematic
#> 0
#>
predict(res, newmods=c(30, 0, 1), addx=TRUE) # for systematic allocation
#>
#> pred se ci.lb ci.ub pi.lb pi.ub X.intrcpt X.ablat X.factor.alloc.random
#> -0.4666 0.2420 -0.9410 0.0078 -1.3501 0.4168 1 30 0
#> X.factor.alloc.systematic
#> 1
#>
### can also use a named vector with arbitrary order and abbreviated variable names
predict(res, newmods=c(sys=0, ran=0, abl=30))
#>
#> pred se ci.lb ci.ub pi.lb pi.ub
#> -0.5251 0.2923 -1.0980 0.0478 -1.4651 0.4149
#>
predict(res, newmods=c(sys=0, ran=1, abl=30))
#>
#> pred se ci.lb ci.ub pi.lb pi.ub
#> -0.7926 0.1941 -1.1729 -0.4122 -1.6293 0.0442
#>
predict(res, newmods=c(sys=1, ran=0, abl=30))
#>
#> pred se ci.lb ci.ub pi.lb pi.ub
#> -0.4666 0.2420 -0.9410 0.0078 -1.3501 0.4168
#>