II am translating some gauss code into R, and gauss has a matrix product function called the horizontal direct product (*~), which is some sort of variant on the Kronecker product. For example if x is 2x2 and y is 2x2 the horizontal direct product, z, of x and y is defined (in the Gauss manual) as: row 1 = x11*y11 x11*y12 x12*y11 x12*y12 row 2 = x21*y21 x21*y22 x22*y21 x22*y22 Or in R code if: x <- matrix(seq(1,4,by=1),2,2, byrow=TRUE) y <- matrix(seq(5,8,by=1),2,2, byrow=TRUE) The resulting matrix, if I had an operator, would be the following matrix z, here formed in a contrived manner: z.1 <- c(5, 6, 10, 12) z.2 <- c(21,24,28,32) z <- rbind(z.1,z.2) I realize that this is just the first and last row of x%*%y when x and y are two by two but this won't generalize with larger matrices. Any ideas about whether this can be done with existing R functions in a general way short of writing my own function? Thanks Luke Luke Keele Department of Political Science Ohio State University keele.4@polisci.osu.edu [[alternative HTML version deleted]]

maybe something like: "%*~%" <- function(x, y){ n <- nrow(x) out <- matrix(0, n, ncol(x) * ncol(y)) for(i in 1:n) out[i, ] <- c(y[i, ] %o% x[i, ]) out } x <- matrix(1:4, 2, 2, TRUE) y <- matrix(5:8, 2, 2, TRUE) x %*~% y I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting Luke Keele <keele.4 at polisci.osu.edu>:> II am translating some gauss code into R, and gauss has a matrix > product function called the horizontal direct product (*~), which is > some sort of variant on the Kronecker product. > > For example if x is 2x2 and y is 2x2 > > the horizontal direct product, z, of x and y is defined (in the Gauss > manual) as: > > row 1 = x11*y11 x11*y12 x12*y11 x12*y12 > row 2 = x21*y21 x21*y22 x22*y21 x22*y22 > > Or in R code if: > > x <- matrix(seq(1,4,by=1),2,2, byrow=TRUE) > y <- matrix(seq(5,8,by=1),2,2, byrow=TRUE) > > The resulting matrix, if I had an operator, would be the following > matrix z, here formed in a contrived manner: > > z.1 <- c(5, 6, 10, 12) > z.2 <- c(21,24,28,32) > z <- rbind(z.1,z.2) > > I realize that this is just the first and last row of x%*%y when x > and y are two by two but this won't generalize with larger > matrices. Any ideas about whether this can be done with existing R > functions in a general way short of writing my own function? > > Thanks > > Luke > > > > > Luke Keele > Department of Political Science > Ohio State University > keele.4 at polisci.osu.edu > > > > > [[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. > >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

On Fri, 25 Aug 2006, Luke Keele wrote:> II am translating some gauss code into R, and gauss has a matrix > product function called the horizontal direct product (*~), which is > some sort of variant on the Kronecker product. > > For example if x is 2x2 and y is 2x2 > > the horizontal direct product, z, of x and y is defined (in the Gauss > manual) as: > > row 1 = x11*y11 x11*y12 x12*y11 x12*y12 > row 2 = x21*y21 x21*y22 x22*y21 x22*y22 >It looks as though "%~%" <- function (A, B) { m <- ncol(A) n <- ncol(B) A[, rep(1:m, each = n)] * B[, rep(1:n, m)] } would do it. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle