[R] Block-Diagonal Matrix and Multivariate Skew Normal

Liaw, Andy andy_liaw at merck.com
Wed Aug 31 20:36:46 CEST 2005


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[[1]])
    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[[1]], 0, NC - ncol(args[[1]]))
    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 at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
> 
>




More information about the R-help mailing list