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.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.012 0.006 0.005
#> 2 0.006 0.008 0.004
#> 3 0.005 0.004 0.006
#>
#>