View source: R/predict.matreg.r
| predict.matreg | R Documentation |
The function computes predicted values, corresponding standard errors, and confidence intervals for objects of class "matreg". \loadmathjax
## S3 method for class 'matreg'
predict(object, newmods, intercept, addx=FALSE,
level, adjust=FALSE, digits, transf, targs, vcov=FALSE, ...)
object |
an object of class |
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 |
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 |
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., |
targs |
optional arguments needed by the function specified under |
vcov |
logical to specify whether the variance-covariance matrix of the predicted values should also be returned (the default is |
... |
other arguments. |
For models including \mjseqnp' moderator/predictor variables, new moderator/predictor values (for \mjeqnk_newk_new hypothetical new studies/cases) must be specified by setting newmods equal to a \mjeqnk_new \times p'k_new x 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 \mjseqnp' + 1 coefficients), then it will be automatically added to newmods unless one sets intercept=FALSE; alternatively, if newmods is a \mjeqnk_new \times (p'+1)k_new x (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/\mjeqnk_newk_new)% CIs, where \mjeqnk_newk_new denotes the number of predicted values computed).
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 |
... |
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.
Under the ‘Regular \mjseqnR Matrix’ case (see matreg), confidence intervals are constructed based on the critical values from a t-distribution with \mjseqnk-p degrees of freedom, where \mjseqnp 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., \mjeqn\pm 1.96±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.
Wolfgang Viechtbauer (wvb@metafor-project.org, https://www.metafor-project.org).
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
### 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")
### 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.