Function to fit regression models based on correlation and covariance matrices.

matreg(y, x, R, n, V, cov=FALSE, means, ztor=FALSE, nearpd=FALSE, level=95, digits, ...)

## Arguments

y index of the outcome variable. indices of the predictor variables. correlation or covariance matrix (or only the lower triangular part including the diagonal). sample size based on which the elements in the correlation/covariance matrix were computed. variance-covariance matrix of the lower triangular elements of the correlation/covariance matrix. Either V or n should be specified, not both. See ‘Details’. logical to specify whether R is a covariance matrix (the default is FALSE). optional vector to specify the means of the variables (only relevant when cov=TRUE). logical to specify whether R is a matrix of r-to-z transformed correlations and it should be back-transformed to raw correlations (the default is FALSE). See ‘Details’. logical to specify whether the nearPD function from the Matrix package should be used when the $$R_{x,x}$$ matrix cannot be inverted. See ‘Note’. numeric value between 0 and 100 to specify the confidence interval level (the default is 95). integer to specify the number of decimal places to which the printed results should be rounded. If unspecified, the default is 4. other arguments.

## Details

Let $$R$$ be a $$p \times p$$ correlation or covariance matrix. Let $$y$$ denote the row/column of the outcome variable and $$x$$ the row(s)/column(s) of the predictor variable(s) in this matrix. Let $$R_{x,x}$$ and $$R_{x,y}$$ denote the corresponding submatrices of $$R$$. Then $b = R_{x,x}^{-1} R_{x,y}$ yields the standardized or raw regression coefficients (depending on whether $$R$$ is a correlation or covariance matrix, respectively) when regressing the outcome variable on the predictor variable(s).

The $$R$$ matrix may be computed based on a single sample of $$n$$ subjects. In this case, one should specify the sample size via argument n. The variance-covariance matrix of the standardized regression coefficients is then given by $$\mbox{Var}[b] = \mbox{MSE} \times R_{x,x}^{-1}$$, where $$\mbox{MSE} = (1 - b'R_{x,y}) / (n - m)$$ and $$m$$ denotes the number of predictor variables. The standard errors of the regression coefficients are then given by the square root of the diagonal elements of $$\mbox{Var}[b]$$. Test statistics (in this case, t-statistics) and the corresponding p-values can then be computed as in a regular regression analysis. When $$R$$ is a covariance matrix, one should set cov=TRUE and specify the means of the $$p$$ variables via argument means to obtain raw regression coefficients including the intercept and corresponding standard errors.

Alternatively, $$R$$ may be the result of a meta-analysis of correlation coefficients. In this case, the elements in $$R$$ are pooled correlation coefficients and the variance-covariance matrix of these pooled coefficients should be specified via argument V. The order of elements in V should correspond to the order of elements in the lower triangular part of $$R$$ column-wise. For example, if $$R$$ is a $$4 \times 4$$ matrix of the form: $\begin{bmatrix} 1 & & & \\ r_{21} & 1 & & \\ r_{31} & r_{32} & 1 & \\ r_{41} & r_{42} & r_{43} & 1 \end{bmatrix}$ then the elements are $$r_{21}$$, $$r_{31}$$, $$r_{41}$$, $$r_{32}$$, $$r_{42}$$, and $$r_{43}$$ and hence V should be a $$6 \times 6$$ variance-covariance matrix of these elements in this order. The variance-covariance matrix of the standardized regression coefficients (i.e., $$\mbox{Var}[b]$$) is then computed as a function of V as described in Becker (1992) using the multivariate delta method. The standard errors of the standardized regression coefficients are then given by the square root of the diagonal elements of $$\mbox{Var}[b]$$. Test statistics (in this case, z-statistics) and the corresponding p-values can then be computed in the usual manner.

In case $$R$$ is the result of a meta-analysis of Fisher r-to-z transformed correlation coefficients (and hence V is then the corresponding variance-covariance matrix of these pooled transformed coefficients), one should set argument ztor=TRUE, so that the appropriate back-transformation is then applied to R (and V) within the function.

Finally, $$R$$ may be a covariance matrix based on a meta-analysis (e.g., the estimated variance-covariance matrix of the random effects in a multivariate model). In this case, one should set cov=TRUE and V should again be the variance-covariance matrix of the elements in $$R$$, but now including the diagonal. Hence, if $$R$$ is a $$4 \times 4$$ matrix of the form: $\begin{bmatrix} \tau_1^2 & & & \\ \tau_{21} & \tau_2^2 & & \\ \tau_{31} & \tau_{32} & \tau_3^2 & \\ \tau_{41} & \tau_{42} & \tau_{43} & \tau_4^2 \end{bmatrix}$ then the elements are $$\tau^2_1$$, $$\tau_{21}$$, $$\tau_{31}$$, $$\tau_{41}$$, $$\tau^2_2$$, $$\tau_{32}$$, $$\tau_{42}$$, $$\tau^2_3$$, $$\tau_{43}$$, and $$\tau^2_4$$, and hence V should be a $$10 \times 10$$ variance-covariance matrix of these elements in this order. Argument means can then again be used to specify the means of the variables.

## Value

An object of class "matreg". The object is a list containing the following components:

tab

a data frame with the estimated model coefficients, standard errors, test statistics, degrees of freedom (only for t-tests), p-values, and lower/upper confidence interval bounds.

vb

the variance-covariance matrix of the estimated model coefficients.

...

The results are formatted and printed with the print.matreg function.

## Note

Only the lower triangular part of R (and V if it is specified) is used in the computations.

If $$R_{x,x}$$ is not invertible, an error will be issued. In this case, one can set argument nearpd=TRUE, in which case the nearPD function from the Matrix package will be used to find the nearest positive semi-definite matrix, which should be invertible. The results should be treated with caution when this is done.

When $$R$$ is a covariance matrix with V and means specified, the means are treated as known constants when estimating the standard error of the intercept.

## Author

Wolfgang Viechtbauer wvb@metafor-project.org https://www.metafor-project.org

Becker, B. J. (1992). Using results from replicated studies to estimate linear models. Journal of Educational Statistics, 17(4), 341--362. https://doi.org/10.3102/10769986017004341

Becker, B. J. (1995). Corrections to "Using results from replicated studies to estimate linear models". Journal of Educational and Behavioral Statistics, 20(1), 100--102. https://doi.org/10.3102/10769986020001100

rcalc, rma.mv

## Examples

### copy data into 'dat'
dat <- dat.craft2003

### construct dataset and var-cov matrix of the correlations
tmp <- rcalc(ri ~ var1 + var2 | study, ni=ni, data=dat)
V <- tmp$V dat <- tmp$dat

### turn var1.var2 into a factor with the desired order of levels
dat$var1.var2 <- factor(dat$var1.var2,
levels=c("acog.perf", "asom.perf", "conf.perf", "acog.asom", "acog.conf", "asom.conf"))

### multivariate random-effects model
res <- rma.mv(yi, V, mods = ~ var1.var2 - 1, random = ~ var1.var2 | study, struct="UN", data=dat)
#> Warning: Rows with NAs omitted from model fitting.res
#>
#> Multivariate Meta-Analysis Model (k = 51; method: REML)
#>
#> Variance Components:
#>
#> outer factor: study     (nlvls = 9)
#> inner factor: var1.var2 (nlvls = 6)
#>
#>             estim    sqrt  k.lvl  fixed      level
#> tau^2.1    0.1611  0.4014      9     no  acog.perf
#> tau^2.2    0.0604  0.2459      9     no  asom.perf
#> tau^2.3    0.0468  0.2163      8     no  conf.perf
#> tau^2.4    0.0047  0.0683      9     no  acog.asom
#> tau^2.5    0.0125  0.1119      8     no  acog.conf
#> tau^2.6    0.0111  0.1052      8     no  asom.conf
#>
#>            rho.acg.p  rho.asm.p  rho.cnf.  rho.acg.s  rho.acg.c  rho.asm.c
#> acog.perf          1
#> asom.perf     0.9497          1
#> conf.perf    -0.6178    -0.5969         1
#> acog.asom     0.5491     0.4604   -0.9345          1
#> acog.conf     0.0432    -0.0495    0.7023    -0.6961          1
#> asom.conf     0.3532     0.2688   -0.1311    -0.0891     0.4193          1
#>            acg.p  asm.p  cnf.  acg.s  acg.c  asm.c
#> acog.perf      -      9     8      9      8      8
#> asom.perf     no      -     8      9      8      8
#> conf.perf     no     no     -      8      8      8
#> acog.asom     no     no    no      -      8      8
#> acog.conf     no     no    no     no      -      8
#> asom.conf     no     no    no     no     no      -
#>
#> Test for Residual Heterogeneity:
#> QE(df = 45) = 334.8358, p-val < .0001
#>
#> Test of Moderators (coefficients 1:6):
#> QM(df = 6) = 596.7711, p-val < .0001
#>
#> Model Results:
#>
#>                     estimate      se     zval    pval    ci.lb    ci.ub
#> var1.var2acog.perf   -0.0600  0.1408  -0.4264  0.6698  -0.3359   0.2159
#> var1.var2asom.perf   -0.1423  0.0917  -1.5527  0.1205  -0.3220   0.0373
#> var1.var2conf.perf    0.3167  0.0847   3.7393  0.0002   0.1507   0.4827  ***
#> var1.var2acog.asom    0.5671  0.0367  15.4640  <.0001   0.4953   0.6390  ***
#> var1.var2acog.conf   -0.4888  0.0509  -9.6048  <.0001  -0.5886  -0.3891  ***
#> var1.var2asom.conf   -0.4750  0.0506  -9.3901  <.0001  -0.5741  -0.3758  ***
#>
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
### restructure estimated mean correlations into a 4x4 matrix
R <- vec2mat(coef(res))
rownames(R) <- colnames(R) <- c("perf", "acog", "asom", "conf")
round(R, digits=3)
#>        perf   acog   asom   conf
#> perf  1.000 -0.060 -0.142  0.317
#> acog -0.060  1.000  0.567 -0.489
#> asom -0.142  0.567  1.000 -0.475
#> conf  0.317 -0.489 -0.475  1.000
### check that order in vcov(res) corresponds to order in R
round(vcov(res), digits=4)
#>                    var1.var2acog.perf var1.var2asom.perf var1.var2conf.perf
#> var1.var2acog.perf             0.0198             0.0115            -0.0069
#> var1.var2asom.perf             0.0115             0.0084            -0.0043
#> var1.var2conf.perf            -0.0069            -0.0043             0.0072
#> var1.var2acog.asom             0.0017             0.0009            -0.0017
#> var1.var2acog.conf             0.0004            -0.0002             0.0023
#> var1.var2asom.conf             0.0018             0.0010            -0.0004
#>                    var1.var2acog.asom var1.var2acog.conf var1.var2asom.conf
#> var1.var2acog.perf             0.0017             0.0004             0.0018
#> var1.var2asom.perf             0.0009            -0.0002             0.0010
#> var1.var2conf.perf            -0.0017             0.0023            -0.0004
#> var1.var2acog.asom             0.0013            -0.0009            -0.0004
#> var1.var2acog.conf            -0.0009             0.0026             0.0011
#> var1.var2asom.conf            -0.0004             0.0011             0.0026
### fit regression model with 'perf' as outcome and 'acog', 'asom', and 'conf' as predictors
fit <- matreg(1, 2:4, R=R, V=vcov(res))
fit
#>
#>       estimate      se     zval    pval    ci.lb   ci.ub
#> acog    0.1482  0.1566   0.9465  0.3439  -0.1587  0.4550
#> asom   -0.0536  0.0768  -0.6979  0.4852  -0.2043  0.0970
#> conf    0.3637  0.0910   3.9985  <.0001   0.1854  0.5419  ***
#>
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
# \dontrun{
### repeat the above but with r-to-z transformed correlations
dat <- dat.craft2003
tmp <- rcalc(ri ~ var1 + var2 | study, ni=ni, data=dat, rtoz=TRUE)
V <- tmp$V dat <- tmp$dat
dat$var1.var2 <- factor(dat$var1.var2,
levels=c("acog.perf", "asom.perf", "conf.perf", "acog.asom", "acog.conf", "asom.conf"))
res <- rma.mv(yi, V, mods = ~ var1.var2 - 1, random = ~ var1.var2 | study, struct="UN", data=dat)
#> Warning: Rows with NAs omitted from model fitting.R <- vec2mat(coef(res))
rownames(R) <- colnames(R) <- c("perf", "acog", "asom", "conf")
fit <- matreg(1, 2:4, R=R, V=vcov(res), ztor=TRUE)
fit# }
#>
#>       estimate      se     zval    pval    ci.lb   ci.ub
#> acog    0.1362  0.1697   0.8023  0.4224  -0.1965  0.4688
#> asom   -0.0678  0.0761  -0.8900  0.3735  -0.2170  0.0814
#> conf    0.3666  0.0934   3.9248  <.0001   0.1835  0.5496  ***
#>
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>