[R] correlating matrices

Rui Barradas ruipbarradas at sapo.pt
Fri Sep 21 21:05:11 CEST 2012


Hello,

As for the first question, predict.lm with new data uses the formula 
used in the fit so do not change the way you pass on your new data. If 
the formula was Y ~ X1 + X2 you can use

newdata = data.frame(New1, New2)
newdata = data.frame(cbind(New1, New2))

but the order must be kept. (And why cbind, by the way?)

2. Use something folloing these lines. (Untested, obviously, without a 
data example.)
pred <- predict(...etc...)
no_na <- complete.cases( cbind(matrix1, matrix2) )

matrix1[ no_na, ] <- pred[1, ]
matrix2[ no_na, ] <- pred[2, ]


Hope this helps,

Rui Barradas

Em 21-09-2012 17:09, frauke escreveu:
> Thank you for the fast help!
>
> I am not sure though if I understand the predict.lm business. The newdata
> that I would make predictions from consists of six matrices, one for each
> variable. Do I cbind the matrices like you suggest for the regression and
> then convert them to a dataframe? How does R know which column in the matrix
> I created with cbind belongs to which variable in the regression?
>
> One last question. If I use predict.lm without newdata it gives me as many
> data points as were used for the regression. However, in my matrices I have
> rows of NA for days without observations. My problem is now that if
> predict.lm only gives me the datapoints used for regression I can not match
> them to the actual observations days anymore. Is there anyway of keeping the
> original matrix and put the predicted value in it?
>
> Thanks again, Frauke
>
>
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/correlating-matrices-tp4643660p4643858.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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.




More information about the R-help mailing list