Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

list2matrix

Convert a List of Symmetric Matrices into a Stacked Matrix


Description

It converts a list of symmetric matrices into a stacked matrix. Dimensions of the symmetric matrices have to be the same. It tries to preserve the dimension names if possible. Dimension names will be created if there are no dimension names in the first symmetric matrix.

Usage

list2matrix(x, diag = FALSE)

Arguments

x

A list of k p x p symmetric matrices.

diag

Logical. If it is TRUE, vech is used to vectorize the (covariance) matrices. If it is FALSE, vechs is used to vectorize the (correlation) matrices.

Value

A k x p* stacked matrix where p* = p(p-1)/2 for diag=FALSE or p* = p(p+1)/2 for diag=TRUE.

Author(s)

Mike W.-L. Cheung <mikewlcheung@nus.edu.sg>

Examples

C1 <- matrix(c(1,0.5,0.4,0.5,1,0.2,0.4,0.2,1), ncol=3)  
C2 <- matrix(c(1,0.4,NA,0.4,1,NA,NA,NA,NA), ncol=3)  

## A list without dimension names 
list2matrix(list(C1, C2))
#      x2_x1 x3_x1 x3_x2
# [1,]   0.5   0.4   0.2
# [2,]   0.4    NA    NA

dimnames(C1) <- list( c("x","y","z"), c("x","y","z") )
dimnames(C2) <- list( c("x","y","z"), c("x","y","z") )

## A list with dimension names
list2matrix(list(C1, C2))
#      y_x z_x z_y
# [1,] 0.5 0.4 0.2
# [2,] 0.4  NA  NA

metaSEM

Meta-Analysis using Structural Equation Modeling

v1.2.5
GPL (>= 2)
Authors
Mike Cheung [aut, cre] (<https://orcid.org/0000-0003-0113-0758>)
Initial release
2020-11-29

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.