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

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.

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]
#> $`1`
#>            [,1]       [,2]       [,3]       [,4]       [,5]       [,6]
#> [1,] 0.07400000 0.03256182 0.03579642 0.02523284 0.02969485 0.04858296
#> [2,] 0.03256182 0.03980000 0.02625218 0.01850511 0.02177744 0.03562949
#> [3,] 0.03579642 0.02625218 0.04810000 0.02034336 0.02394075 0.03916883
#> [4,] 0.02523284 0.01850511 0.02034336 0.02390000 0.01687579 0.02761004
#> [5,] 0.02969485 0.02177744 0.02394075 0.01687579 0.03310000 0.03249242
#> [6,] 0.04858296 0.03562949 0.03916883 0.02761004 0.03249242 0.08860000
#> 
#> $`2`
#>             [,1]        [,2]        [,3]
#> [1,] 0.011500000 0.005609278 0.005187485
#> [2,] 0.005609278 0.007600000 0.004217108
#> [3,] 0.005187485 0.004217108 0.006500000
#> 
lapply(Vs[1:2], cov2cor)
#> $`1`
#>      [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,]  1.0  0.6  0.6  0.6  0.6  0.6
#> [2,]  0.6  1.0  0.6  0.6  0.6  0.6
#> [3,]  0.6  0.6  1.0  0.6  0.6  0.6
#> [4,]  0.6  0.6  0.6  1.0  0.6  0.6
#> [5,]  0.6  0.6  0.6  0.6  1.0  0.6
#> [6,]  0.6  0.6  0.6  0.6  0.6  1.0
#> 
#> $`2`
#>      [,1] [,2] [,3]
#> [1,]  1.0  0.6  0.6
#> [2,]  0.6  1.0  0.6
#> [3,]  0.6  0.6  1.0
#> 

### illustrate the use of the fun and args arguments
blsplit(V, cluster=dat$study, cov2cor)[1:2]
#> $`1`
#>      [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,]  1.0  0.6  0.6  0.6  0.6  0.6
#> [2,]  0.6  1.0  0.6  0.6  0.6  0.6
#> [3,]  0.6  0.6  1.0  0.6  0.6  0.6
#> [4,]  0.6  0.6  0.6  1.0  0.6  0.6
#> [5,]  0.6  0.6  0.6  0.6  1.0  0.6
#> [6,]  0.6  0.6  0.6  0.6  0.6  1.0
#> 
#> $`2`
#>      [,1] [,2] [,3]
#> [1,]  1.0  0.6  0.6
#> [2,]  0.6  1.0  0.6
#> [3,]  0.6  0.6  1.0
#> 
blsplit(V, cluster=dat$study, round, 3)[1:2]
#> $`1`
#>       [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
#> [1,] 0.074 0.033 0.036 0.025 0.030 0.049
#> [2,] 0.033 0.040 0.026 0.019 0.022 0.036
#> [3,] 0.036 0.026 0.048 0.020 0.024 0.039
#> [4,] 0.025 0.019 0.020 0.024 0.017 0.028
#> [5,] 0.030 0.022 0.024 0.017 0.033 0.032
#> [6,] 0.049 0.036 0.039 0.028 0.032 0.089
#> 
#> $`2`
#>       [,1]  [,2]  [,3]
#> [1,] 0.011 0.006 0.005
#> [2,] 0.006 0.008 0.004
#> [3,] 0.005 0.004 0.006
#>