Dear R-list members, Just wondering if there is any way to compute the duplication matrix in R. I tried to search for it but only found functions "xpnd" and "vech". Basically for a symmetric n by n matrix A, the duplication matrix D_n is a matrix of dimension n^2 by n(n+1)/2 such that D_n vech(A)= c(A), where c(A) just vectorizes A. The duplication matrix is defined on page 49 of the book "Matrix differential calculus with applications in statistics and econometrics" by Magnus and Neudecker (1988 ) Thanks a lot! --------------------------------- ÑÅ»¢Ãâ·ÑÓÊÏä-3.5GÈÝÁ¿£¬20M¸½¼þ [[alternative HTML version deleted]]
On Sun, 10 Sep 2006, w wrote:> Dear R-list members, > Just wondering if there is any way to compute the duplication matrix in R. > I tried to search for it but only found functions "xpnd" and "vech". >Something like this: Dn <- function(x){ mat <- diag(x) index <- seq(x*(x+1)/2) mat[ lower.tri( mat , TRUE ) ] <- index mat[ upper.tri( mat ) ] <- t( mat )[ upper.tri( mat ) ] outer(c(mat), index , function( x , y ) ifelse(x==y, 1, 0 ) ) } Dn(4) returns what you describe for a 4 x 4 matrix> Basically for a symmetric n by n matrix A, the duplication matrix D_n is > a matrix of dimension n^2 by n(n+1)/2 such that > D_n vech(A)= c(A), where c(A) just vectorizes A. > > The duplication matrix is defined on page 49 of the book "Matrix > differential calculus with applications in statistics and econometrics" > by Magnus and Neudecker (1988 ) > > Thanks a lot! > > > > > > --------------------------------- > ????????????-3.5G??????20M???? > [[alternative HTML version deleted]] > >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://biostat.ucsd.edu/~cberry/ La Jolla, San Diego 92093-0717
Note that xpnd(v), which you mentioned in your post, is a linear transform whose effect on v is the same as D_n %*% v so just pump an identity matrix through xpnd to get its matrix: library(MCMCpack) D_n <- function(n) apply(diag(n*(n+1)/2), 2, xpnd, n) # test D_n(3) On 9/9/06, w <scip1121 at yahoo.com.cn> wrote:> Dear R-list members, > Just wondering if there is any way to compute the duplication matrix in R. > I tried to search for it but only found functions "xpnd" and "vech". > > Basically for a symmetric n by n matrix A, the duplication matrix D_n is > a matrix of dimension n^2 by n(n+1)/2 such that > D_n vech(A)= c(A), where c(A) just vectorizes A. > > The duplication matrix is defined on page 49 of the book "Matrix > differential calculus with applications in statistics and econometrics" > by Magnus and Neudecker (1988 ) > > Thanks a lot! > > > > > > --------------------------------- > ????????????-3.5G??????20M???? > [[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 > and provide commented, minimal, self-contained, reproducible code. > > >