Function to construct a block diagonal matrix from (a list of) matrices.

bldiag(...)

Arguments

...

individual matrices or a list of matrices.

Author

Posted to R-help by Berton Gunter (2 Sep 2005).

See also

Examples

### copy data into 'dat' dat <- dat.berkey1998 ### construct list with the variance-covariance matrices of the observed outcomes for the studies V <- lapply(split(dat[c("v1i", "v2i")], dat$trial), as.matrix) V
#> $`1` #> v1i v2i #> 1 0.0075 0.0030 #> 2 0.0030 0.0077 #> #> $`2` #> v1i v2i #> 3 0.0057 9e-04 #> 4 0.0009 8e-04 #> #> $`3` #> v1i v2i #> 5 0.0021 0.0007 #> 6 0.0007 0.0014 #> #> $`4` #> v1i v2i #> 7 0.0029 0.0009 #> 8 0.0009 0.0015 #> #> $`5` #> v1i v2i #> 9 0.0148 0.0072 #> 10 0.0072 0.0304 #>
### construct block diagonal matrix V <- bldiag(V) V
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] 0.0075 0.0030 0.0000 0e+00 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 #> [2,] 0.0030 0.0077 0.0000 0e+00 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 #> [3,] 0.0000 0.0000 0.0057 9e-04 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 #> [4,] 0.0000 0.0000 0.0009 8e-04 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 #> [5,] 0.0000 0.0000 0.0000 0e+00 0.0021 0.0007 0.0000 0.0000 0.0000 0.0000 #> [6,] 0.0000 0.0000 0.0000 0e+00 0.0007 0.0014 0.0000 0.0000 0.0000 0.0000 #> [7,] 0.0000 0.0000 0.0000 0e+00 0.0000 0.0000 0.0029 0.0009 0.0000 0.0000 #> [8,] 0.0000 0.0000 0.0000 0e+00 0.0000 0.0000 0.0009 0.0015 0.0000 0.0000 #> [9,] 0.0000 0.0000 0.0000 0e+00 0.0000 0.0000 0.0000 0.0000 0.0148 0.0072 #> [10,] 0.0000 0.0000 0.0000 0e+00 0.0000 0.0000 0.0000 0.0000 0.0072 0.0304