The function computes predicted values, corresponding standard errors, and confidence intervals for objects of class "matreg".

# S3 method for class 'matreg'
predict(object, newmods, intercept, addx=FALSE,
        level, adjust=FALSE, digits, transf, targs, vcov=FALSE, ...)

Arguments

object

an object of class "matreg".

newmods

vector or matrix to specify the values of the moderator/predictor values for which the predicted values should be calculated. See ‘Details’.

intercept

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 model also included an intercept.

addx

logical to specify whether the values of the moderator/predictor variables should be added to the returned object. See ‘Examples’.

level

numeric value between 0 and 100 to specify the confidence interval level (see here for details). If unspecified, the default is to take the value from the object.

adjust

logical to specify whether the width of confidence intervals should be adjusted using a Bonferroni correction (the default is FALSE).

digits

optional integer to specify the number of decimal places to which the printed results should be rounded.

transf

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.

targs

optional arguments needed by the function specified under transf.

vcov

logical to specify whether the variance-covariance matrix of the predicted values should also be returned (the default is FALSE).

...

other arguments.

Details

For models including \(p'\) moderator/predictor variables, new moderator/predictor values (for \(k_{new}\) hypothetical new studies/cases) must be specified by setting newmods equal to a \(k_{new} \times p'\) matrix with the corresponding new moderator/predictor values (if newmods is a vector, then only a single predicted value is computed unless the model only includes a single moderator/predictor, in which case predicted values corresponding to all the vector values are computed). If the model object includes an intercept (so that the model has \(p' + 1\) coefficients), 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. If the matrix specified via newmods has row names, then these are used to label the predicted values in the output.

When computing multiple predicted values, one can set adjust=TRUE to obtain confidence 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).

Value

An object of class c("predict.matreg","list.rma"). The object is a list containing the following components:

pred

predicted value(s).

se

corresponding standard error(s).

ci.lb

lower bound of the confidence interval(s).

ci.ub

upper bound of the confidence interval(s).

X

the moderator/predictor value(s) used to calculate the predicted values (only when addx=TRUE).

...

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.

Note

Under the ‘Regular \(R\) Matrix’ case (see matreg), confidence intervals are constructed based on the critical values from a t-distribution with \(k-p\) degrees of freedom, where \(p\) denotes the total number of coefficients (i.e., including the intercept term if the model includes one). Otherwise, critical values from a standard normal distribution (i.e., \(\pm 1.96\) for level=95) are used.

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.

References

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

Examples

### fit a regression model with lm() to the 'mtcars' dataset
res <- lm(mpg ~ hp + wt + am, data=mtcars)

### obtain a predicted value
predict(res, newdata=data.frame(hp=120, wt=4.2, am=1), interval="confidence")
#>        fit      lwr      upr
#> 1 19.49912 15.79498 23.20327

### covariance matrix of the dataset
S <- cov(mtcars)

### fit the same regression model using matreg()
res <- matreg(mpg ~ hp + wt + am, R=S, cov=TRUE,
              means=colMeans(mtcars), n=nrow(mtcars))

### obtain the same predicted value
predict(res, newmods=c(hp=120, wt=4.2, am=1))
#> 
#>     pred     se   ci.lb   ci.ub 
#>  19.4991 1.8083 15.7950 23.2033 
#>