vcov.rma.Rd
Function to extract various types of variance-covariance matrices from objects of class "rma"
. By default, the variance-covariance matrix of the fixed effects is returned.
# S3 method for class 'rma'
vcov(object, type="fixed", ...)
an object of class "rma"
.
character string to specify the type of variance-covariance matrix to return: type="fixed"
returns the variance-covariance matrix of the fixed effects (the default), type="obs"
returns the marginal variance-covariance matrix of the observed effect sizes or outcomes, type="fitted"
returns the variance-covariance matrix of the fitted values, type="resid"
returns the variance-covariance matrix of the residuals.
other arguments.
Note that type="obs"
currently only works for object of class "rma.uni"
and "rma.mv"
.
For objects of class "rma.uni"
, the marginal variance-covariance matrix of the observed effect sizes or outcomes is a diagonal matrix with \(\hat{\tau}^2 + v_i\) along the diagonal, where \(\hat{\tau}^2\) is the estimated amount of (residual) heterogeneity (set to 0 in equal-effects models) and \(v_i\) is the sampling variance of the \(i\text{th}\) study.
For objects of class "rma.mv"
, the structure can be more complex and depends on the random effects included in the model.
A matrix corresponding to the requested variance-covariance matrix.
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
### calculate log risk ratios and corresponding sampling variances
dat <- escalc(measure="RR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg)
### fit mixed-effects model with absolute latitude and publication year as moderators
res <- rma(yi, vi, mods = ~ ablat + year, data=dat)
### var-cov matrix of the fixed effects (i.e., the model coefficients)
vcov(res)
#> intrcpt ablat year
#> intrcpt 846.5702229 -0.1783751581 -0.4272176864
#> ablat -0.1783752 0.0001047356 0.0000889397
#> year -0.4272177 0.0000889397 0.0002156144
### marginal var-cov matrix of the observed log risk ratios
round(vcov(res, type="obs"), 3)
#> 1 2 3 4 5 6 7 8 9 10 11 12 13
#> 1 0.436 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
#> 2 0.000 0.305 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
#> 3 0.000 0.000 0.526 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
#> 4 0.000 0.000 0.000 0.131 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
#> 5 0.000 0.000 0.000 0.000 0.162 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
#> 6 0.000 0.000 0.000 0.000 0.000 0.118 0.000 0.000 0.000 0.000 0.000 0.000 0.000
#> 7 0.000 0.000 0.000 0.000 0.000 0.000 0.334 0.000 0.000 0.000 0.000 0.000 0.000
#> 8 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.115 0.000 0.000 0.000 0.000 0.000
#> 9 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.167 0.000 0.000 0.000 0.000
#> 10 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.184 0.000 0.000 0.000
#> 11 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.123 0.000 0.000
#> 12 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.643 0.000
#> 13 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.182
### var-cov matrix of the fitted values
round(vcov(res, type="fitted"), 3)
#> 1 2 3 4 5 6 7 8 9 10 11 12 13
#> 1 0.075 0.066 0.037 -0.024 0.009 0.059 0.006 -0.014 0.018 0.034 0.003 0.012 -0.011
#> 2 0.066 0.072 0.040 0.011 -0.009 0.056 -0.004 -0.023 0.012 0.038 -0.007 0.014 0.000
#> 3 0.037 0.040 0.026 0.014 0.004 0.032 0.006 -0.002 0.013 0.025 0.005 0.015 0.008
#> 4 -0.024 0.011 0.014 0.106 -0.022 -0.006 -0.005 0.003 0.000 0.018 -0.004 0.021 0.047
#> 5 0.009 -0.009 0.004 -0.022 0.040 0.006 0.031 0.036 0.022 0.004 0.032 0.012 0.008
#> 6 0.059 0.056 0.032 -0.006 0.006 0.048 0.005 -0.010 0.016 0.030 0.003 0.013 -0.002
#> 7 0.006 -0.004 0.006 -0.005 0.031 0.005 0.026 0.030 0.019 0.006 0.026 0.013 0.012
#> 8 -0.014 -0.023 -0.002 0.003 0.036 -0.010 0.030 0.042 0.019 -0.001 0.032 0.014 0.020
#> 9 0.018 0.012 0.013 0.000 0.022 0.016 0.019 0.019 0.017 0.013 0.019 0.014 0.010
#> 10 0.034 0.038 0.025 0.018 0.004 0.030 0.006 -0.001 0.013 0.024 0.005 0.015 0.010
#> 11 0.003 -0.007 0.005 -0.004 0.032 0.003 0.026 0.032 0.019 0.005 0.027 0.013 0.013
#> 12 0.012 0.014 0.015 0.021 0.012 0.013 0.013 0.014 0.014 0.015 0.013 0.015 0.017
#> 13 -0.011 0.000 0.008 0.047 0.008 -0.002 0.012 0.020 0.010 0.010 0.013 0.017 0.029
### var-cov matrix of the residuals
round(vcov(res, type="resid"), 3)
#> 1 2 3 4 5 6 7 8 9 10 11 12 13
#> 1 0.361 -0.066 -0.037 0.024 -0.009 -0.059 -0.006 0.014 -0.018 -0.034 -0.003 -0.012 0.011
#> 2 -0.066 0.233 -0.040 -0.011 0.009 -0.056 0.004 0.023 -0.012 -0.038 0.007 -0.014 0.000
#> 3 -0.037 -0.040 0.501 -0.014 -0.004 -0.032 -0.006 0.002 -0.013 -0.025 -0.005 -0.015 -0.008
#> 4 0.024 -0.011 -0.014 0.025 0.022 0.006 0.005 -0.003 0.000 -0.018 0.004 -0.021 -0.047
#> 5 -0.009 0.009 -0.004 0.022 0.122 -0.006 -0.031 -0.036 -0.022 -0.004 -0.032 -0.012 -0.008
#> 6 -0.059 -0.056 -0.032 0.006 -0.006 0.070 -0.005 0.010 -0.016 -0.030 -0.003 -0.013 0.002
#> 7 -0.006 0.004 -0.006 0.005 -0.031 -0.005 0.308 -0.030 -0.019 -0.006 -0.026 -0.013 -0.012
#> 8 0.014 0.023 0.002 -0.003 -0.036 0.010 -0.030 0.073 -0.019 0.001 -0.032 -0.014 -0.020
#> 9 -0.018 -0.012 -0.013 0.000 -0.022 -0.016 -0.019 -0.019 0.150 -0.013 -0.019 -0.014 -0.010
#> 10 -0.034 -0.038 -0.025 -0.018 -0.004 -0.030 -0.006 0.001 -0.013 0.160 -0.005 -0.015 -0.010
#> 11 -0.003 0.007 -0.005 0.004 -0.032 -0.003 -0.026 -0.032 -0.019 -0.005 0.096 -0.013 -0.013
#> 12 -0.012 -0.014 -0.015 -0.021 -0.012 -0.013 -0.013 -0.014 -0.014 -0.015 -0.013 0.628 -0.017
#> 13 0.011 0.000 -0.008 -0.047 -0.008 0.002 -0.012 -0.020 -0.010 -0.010 -0.013 -0.017 0.153