[R] matrix computation???

Greg Snow Greg.Snow at imail.org
Thu Feb 19 18:31:43 CET 2009


You are computing the hat matrix to predict stack.loss, but stack.loss is a column in the A matrix, so you predictions are all perfect (given stack.loss, what is stack.loss, fairly simple answer, all errors are 0).  I think you want to redo this using only the 3 columns other than stack.loss in the call to svd, then you should get the results that you are expecting.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Kutlwano Ramaboa
> Sent: Wednesday, February 18, 2009 10:43 PM
> To: r-help at r-project.org
> Subject: [R] matrix computation???
> 
> Hello
> 
> Can anyone tell me what I am doing wrong below? My Y and y_hat are the
> same.
> 
> 
> 
> A<-scale(stackloss)
> n1<- dim(A)[1];n2<-dim(A)[2]
> X<-svd(A)
> Y<- matrix(A[,"stack.loss"],nrow=n1)
> Y
> y_hat <-matrix((X$u%*% t(X$u))%*%Y,nrow=n1,byrow=T)
> y_hat
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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