blsplit.RdFunction to split a block diagonal matrix into a list of sub-matrices.
blsplit(x, cluster, fun, args, sort=FALSE)a block diagonal matrix.
vector to specify the clustering variable to use for splitting.
optional argument to specify a function to apply to each sub-matrix.
optional argument to specify any additional argument(s) for the function specified via fun.
logical to specify whether to sort the list by the unique cluster values (the default is FALSE).
A list of one or more sub-matrices.
### 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.0740 0.0326 0.0358 0.0252 0.0297 0.0486
#> 2 0.0326 0.0398 0.0263 0.0185 0.0218 0.0356
#> 3 0.0358 0.0263 0.0481 0.0203 0.0239 0.0392
#> 4 0.0252 0.0185 0.0203 0.0239 0.0169 0.0276
#> 5 0.0297 0.0218 0.0239 0.0169 0.0331 0.0325
#> 6 0.0486 0.0356 0.0392 0.0276 0.0325 0.0886
#>
#>
#> $`2`
#>
#> 1 2 3
#> 1 0.0115 0.0056 0.0052
#> 2 0.0056 0.0076 0.0042
#> 3 0.0052 0.0042 0.0065
#>
#>
lapply(Vs[1:2], cov2cor)
#> $`1`
#>
#> 1 2 3 4 5 6
#> 1 1.0000 0.6000 0.6000 0.6000 0.6000 0.6000
#> 2 0.6000 1.0000 0.6000 0.6000 0.6000 0.6000
#> 3 0.6000 0.6000 1.0000 0.6000 0.6000 0.6000
#> 4 0.6000 0.6000 0.6000 1.0000 0.6000 0.6000
#> 5 0.6000 0.6000 0.6000 0.6000 1.0000 0.6000
#> 6 0.6000 0.6000 0.6000 0.6000 0.6000 1.0000
#>
#>
#> $`2`
#>
#> 1 2 3
#> 1 1.0000 0.6000 0.6000
#> 2 0.6000 1.0000 0.6000
#> 3 0.6000 0.6000 1.0000
#>
#>
### 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.0000 0.6000 0.6000 0.6000 0.6000 0.6000
#> 2 0.6000 1.0000 0.6000 0.6000 0.6000 0.6000
#> 3 0.6000 0.6000 1.0000 0.6000 0.6000 0.6000
#> 4 0.6000 0.6000 0.6000 1.0000 0.6000 0.6000
#> 5 0.6000 0.6000 0.6000 0.6000 1.0000 0.6000
#> 6 0.6000 0.6000 0.6000 0.6000 0.6000 1.0000
#>
#>
#> $`2`
#>
#> 1 2 3
#> 1 1.0000 0.6000 0.6000
#> 2 0.6000 1.0000 0.6000
#> 3 0.6000 0.6000 1.0000
#>
#>
blsplit(V, cluster=dat$study, round, 3)[1:2]
#> $`1`
#>
#> 1 2 3 4 5 6
#> 1 0.0740 0.0330 0.0360 0.0250 0.0300 0.0490
#> 2 0.0330 0.0400 0.0260 0.0190 0.0220 0.0360
#> 3 0.0360 0.0260 0.0480 0.0200 0.0240 0.0390
#> 4 0.0250 0.0190 0.0200 0.0240 0.0170 0.0280
#> 5 0.0300 0.0220 0.0240 0.0170 0.0330 0.0320
#> 6 0.0490 0.0360 0.0390 0.0280 0.0320 0.0890
#>
#>
#> $`2`
#>
#> 1 2 3
#> 1 0.0120 0.0060 0.0050
#> 2 0.0060 0.0080 0.0040
#> 3 0.0050 0.0040 0.0060
#>
#>