vcov.rma.RdFunction 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
#> 1 0.4360 . . . . . . . . . . .
#> 2 . 0.3050 . . . . . . . . . .
#> 3 . . 0.5260 . . . . . . . . .
#> 4 . . . 0.1310 . . . . . . . .
#> 5 . . . . 0.1620 . . . . . . .
#> 6 . . . . . 0.1180 . . . . . .
#> 7 . . . . . . 0.3340 . . . . .
#> 8 . . . . . . . 0.1150 . . . .
#> 9 . . . . . . . . 0.1670 . . .
#> 10 . . . . . . . . . 0.1840 . .
#> 11 . . . . . . . . . . 0.1230 .
#> 12 . . . . . . . . . . . 0.6430
#> 13 . . . . . . . . . . . .
#> 13
#> 1 .
#> 2 .
#> 3 .
#> 4 .
#> 5 .
#> 6 .
#> 7 .
#> 8 .
#> 9 .
#> 10 .
#> 11 .
#> 12 .
#> 13 0.1820
### 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
#> 1 0.0750 0.0660 0.0370 -0.0240 0.0090 0.0590 0.0060 -0.0140 0.0180 0.0340 0.0030 0.0120
#> 2 0.0660 0.0720 0.0400 0.0110 -0.0090 0.0560 -0.0040 -0.0230 0.0120 0.0380 -0.0070 0.0140
#> 3 0.0370 0.0400 0.0260 0.0140 0.0040 0.0320 0.0060 -0.0020 0.0130 0.0250 0.0050 0.0150
#> 4 -0.0240 0.0110 0.0140 0.1060 -0.0220 -0.0060 -0.0050 0.0030 . 0.0180 -0.0040 0.0210
#> 5 0.0090 -0.0090 0.0040 -0.0220 0.0400 0.0060 0.0310 0.0360 0.0220 0.0040 0.0320 0.0120
#> 6 0.0590 0.0560 0.0320 -0.0060 0.0060 0.0480 0.0050 -0.0100 0.0160 0.0300 0.0030 0.0130
#> 7 0.0060 -0.0040 0.0060 -0.0050 0.0310 0.0050 0.0260 0.0300 0.0190 0.0060 0.0260 0.0130
#> 8 -0.0140 -0.0230 -0.0020 0.0030 0.0360 -0.0100 0.0300 0.0420 0.0190 -0.0010 0.0320 0.0140
#> 9 0.0180 0.0120 0.0130 . 0.0220 0.0160 0.0190 0.0190 0.0170 0.0130 0.0190 0.0140
#> 10 0.0340 0.0380 0.0250 0.0180 0.0040 0.0300 0.0060 -0.0010 0.0130 0.0240 0.0050 0.0150
#> 11 0.0030 -0.0070 0.0050 -0.0040 0.0320 0.0030 0.0260 0.0320 0.0190 0.0050 0.0270 0.0130
#> 12 0.0120 0.0140 0.0150 0.0210 0.0120 0.0130 0.0130 0.0140 0.0140 0.0150 0.0130 0.0150
#> 13 -0.0110 . 0.0080 0.0470 0.0080 -0.0020 0.0120 0.0200 0.0100 0.0100 0.0130 0.0170
#> 13
#> 1 -0.0110
#> 2 .
#> 3 0.0080
#> 4 0.0470
#> 5 0.0080
#> 6 -0.0020
#> 7 0.0120
#> 8 0.0200
#> 9 0.0100
#> 10 0.0100
#> 11 0.0130
#> 12 0.0170
#> 13 0.0290
### var-cov matrix of the residuals
round(vcov(res, type="resid"), 3)
#> 1 2 3 4 5 6 7 8 9 10 11 12
#> 1 0.3610 -0.0660 -0.0370 0.0240 -0.0090 -0.0590 -0.0060 0.0140 -0.0180 -0.0340 -0.0030 -0.0120
#> 2 -0.0660 0.2330 -0.0400 -0.0110 0.0090 -0.0560 0.0040 0.0230 -0.0120 -0.0380 0.0070 -0.0140
#> 3 -0.0370 -0.0400 0.5010 -0.0140 -0.0040 -0.0320 -0.0060 0.0020 -0.0130 -0.0250 -0.0050 -0.0150
#> 4 0.0240 -0.0110 -0.0140 0.0250 0.0220 0.0060 0.0050 -0.0030 . -0.0180 0.0040 -0.0210
#> 5 -0.0090 0.0090 -0.0040 0.0220 0.1220 -0.0060 -0.0310 -0.0360 -0.0220 -0.0040 -0.0320 -0.0120
#> 6 -0.0590 -0.0560 -0.0320 0.0060 -0.0060 0.0700 -0.0050 0.0100 -0.0160 -0.0300 -0.0030 -0.0130
#> 7 -0.0060 0.0040 -0.0060 0.0050 -0.0310 -0.0050 0.3080 -0.0300 -0.0190 -0.0060 -0.0260 -0.0130
#> 8 0.0140 0.0230 0.0020 -0.0030 -0.0360 0.0100 -0.0300 0.0730 -0.0190 0.0010 -0.0320 -0.0140
#> 9 -0.0180 -0.0120 -0.0130 . -0.0220 -0.0160 -0.0190 -0.0190 0.1500 -0.0130 -0.0190 -0.0140
#> 10 -0.0340 -0.0380 -0.0250 -0.0180 -0.0040 -0.0300 -0.0060 0.0010 -0.0130 0.1600 -0.0050 -0.0150
#> 11 -0.0030 0.0070 -0.0050 0.0040 -0.0320 -0.0030 -0.0260 -0.0320 -0.0190 -0.0050 0.0960 -0.0130
#> 12 -0.0120 -0.0140 -0.0150 -0.0210 -0.0120 -0.0130 -0.0130 -0.0140 -0.0140 -0.0150 -0.0130 0.6280
#> 13 0.0110 . -0.0080 -0.0470 -0.0080 0.0020 -0.0120 -0.0200 -0.0100 -0.0100 -0.0130 -0.0170
#> 13
#> 1 0.0110
#> 2 .
#> 3 -0.0080
#> 4 -0.0470
#> 5 -0.0080
#> 6 0.0020
#> 7 -0.0120
#> 8 -0.0200
#> 9 -0.0100
#> 10 -0.0100
#> 11 -0.0130
#> 12 -0.0170
#> 13 0.1530