[R] correlating matrices
frauke
fhoss at andrew.cmu.edu
Wed Sep 19 20:56:15 CEST 2012
Hi,
thank you for taking the time and reading my question. My question is
twofold:
1. I have several matrices with variables and one matrix with water levels.
I want to predict the water level with the data in the other matrices.
Basically,
* mod<-lm(matrix1 ~ matrix2+matrix3)*
( What looks like a minus is meant to be the wiggly minus.)
Of course I could dissemble the matrices and paste their columns into one
long, long vector. But the method above gives reasonable results. Are there
any methodological objections against doing this?
2. After having done the regression I now want to make a prediction. Thus
given the coefficients of my regression mod and matrix2 and matrix3 I want
to predict a new matrix. This is where the matrix approach becomes
difficult. I made it work, but it is very unelegant:
*pred<-rep(coef(mod)[1],2)+coef(mod)[2]*matrix2+coef(mod)[3]*matrix3
PRED<-matrix(pred, nrow=length(matrix1[,1]), ncol=length(matrix1[1,]),
byrow=F)*
Is there a more elegant way of doing this? Because I dont have two but six
matrices as independent variables, so it becomes pretty lengthy. I could
not make the command predict() work for this.
Thank you!
--
View this message in context: http://r.789695.n4.nabble.com/correlating-matrices-tp4643660.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list