[R] Change the order of variables in a linear model

2012-05-16 Thread Frank Paetzold
Hello, the following lines m <- matrix(c(1,1,9,1,2,6,1,3,7,2,1,4,2,2,5,2,3,1,3,1,2,3,2,-1,3,3,-2), 9, 3, byrow = TRUE, dimnames=list(NULL, cbind('A','B','Y'))) md <- as.data.frame(m) md$A <- as.factor(md$A) md$B <- as.factor(md$B) mm <- model.matrix(Y~A+B+A:B, data=md) produce > mm (Interce

[R] set specific contrasts using lapply

2012-05-11 Thread Frank Paetzold
I have the following data set > data A B X1 X2 Y 1 A1 B1 1.1 2.9 1.2 2 A1 B2 1.0 3.2 2.3 3 A2 B1 1.0 3.3 1.6 4 A2 B2 0.5 2.6 3.1 > sapply(data, class) A BX1X2 Y "factor" "factor" "numeric" "numeric" "numeric" I'd like to set a specific type of

Re: [R] generalized inverse using matinv (Design)

2011-08-17 Thread Frank Paetzold
thank you all. i have deliberately chosen matinv (although obviously an outdated version) because it uses the sweep operator. i know of other methods to calculate generalized inverses. however, it is also true that the sweep operator is capable of computing g2 generalized inverses. The ginv re

[R] generalized inverse using matinv (Design)

2011-08-16 Thread Frank Paetzold
i am trying to use matinv from the Design package to compute the generalized inverse of the normal equations of a 3x3 design via the sweep operator. That is, for the linear model y = ยต + x1 + x2 + x1*x2 where x1, x2 are 3-level factors and dummy coding is being used the matrix to be inverted i