blsplit: Split Block Diagonal Matrix

View source: R/blsplit.r

blsplitR Documentation

Split Block Diagonal Matrix

Description

Function to split a block diagonal matrix into a list of sub-matrices.

Usage

blsplit(x, cluster, fun, args, sort=FALSE)

Arguments

x

a block diagonal matrix.

cluster

vector to specify the clustering variable to use for splitting.

fun

optional argument to specify a function to apply to each sub-matrix.

args

optional argument to specify any additional argument(s) for the function specified via fun.

sort

logical to indicate whether to sort the list by the unique cluster values (the default is FALSE).

Value

A list of one or more sub-matrices.

Author(s)

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

See Also

bldiag for a function to create a block diagonal matrix based on sub-matrices.

vcalc for a function to construct a variance-covariance matrix of dependent effect sizes or outcomes, which often has a block diagonal structure.

Examples

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

### assume that the effect sizes within studies are correlated with rho=0.6
V <- vcalc(vi, cluster=study, obs=esid, data=dat, rho=0.6)

### split V matrix into list of sub-matrices
Vs <- blsplit(V, cluster=dat$study)
Vs[1:2]
lapply(Vs[1:2], cov2cor)

### illustrate the use of the fun and args arguments
blsplit(V, cluster=dat$study, cov2cor)[1:2]
blsplit(V, cluster=dat$study, round, 3)[1:2]

metafor documentation built on May 29, 2024, 7:44 a.m.