# Re: [R] Block-Diagonal Matrix and Multivariate Skew Normal

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Thu 01 Sep 2005 - 04:36:46 EST

For your first question, here's a function originally posted by Ben Bolker, with modification by Rich Raubertas:

blockdiag <- function (x, ...)
{

if (!is.list(x))

x <- list(x)
args <- list(...)
if (length(args) > 0)

args <- c(x, args)
else args <- x
idx <- which(!sapply(args, is.matrix))     if (length(idx) > 0)

for (i in idx) args[[i]] <- as.matrix(args[[i]])     if (length(args) == 1)

return(args[])
nr <- sapply(args, nrow)
nc <- sapply(args, ncol)
cumnc <- cumsum(nc)
NR <- sum(nr)
NC <- sum(nc)
rowfun <- function(m, zbefore, zafter) {

```        cbind(matrix(0, ncol = zbefore, nrow = nrow(m)), m, matrix(0,
ncol = zafter, nrow = nrow(m)))
```
}
ret <- rowfun(args[], 0, NC - ncol(args[]))     for (i in 2:length(args)) {
```        ret <- rbind(ret, rowfun(args[[i]], cumnc[i - 1], NC -
cumnc[i]))
```

}
ret
}

Andy

> From: Caio Lucidius Naberezny Azevedo
>
> Dear R-users,
>
> Does anybody know how to construct a block-diagonal matrix
> (with the blocks being different matrixs, concerning the
> dimension and the values) ?
>
> I would like to know also if there is any package that
> generates values from a multivariate skew normal distribution.
>
> Thanks all,
>
> Caio
>
>
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help