Thank you Greg! Yes this is the comparison I was looking for. >>> Greg Snow <greg.s...@imail.org> 2009/02/24 06:07 PM >>> The same as what? It is not clear what you are trying to compare.
Is this the comparison that you are looking for?: > A <- scale(stackloss) > > fit1 <- lm( stack.loss ~ . - 1, data=as.data.frame(A)) > tmp1 <- fitted(fit1) > > fit2 <- svd(A[,-4]) > tmp2 <- fit2$u %*% t(fit2$u) %*% A[,4] > > all.equal( as.vector(tmp1), as.vector(tmp2)) [1] TRUE > -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Kutlwano Ramaboa > Sent: Tuesday, February 24, 2009 1:02 AM > To: Greg Snow; r-help@r-project.org > Subject: Re: [R] matrix computation??? > > Hi Greg > > Thanks for responding. > > When I scale stackloss and compute the fitted values of the scaled data > frame, the values are not the same: > > A<-data.frame(scale(stackloss)) > > lm<- lm(stack.loss ~ . -1, qr=T, data=A) > summary(lm) > fitted.values(lm) > > Or should I not be comparing the two? > > >>> Greg Snow <greg.s...@imail.org> 2009/02/19 07:31 PM >>> > 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.s...@imail.org > 801.408.8111 > > > > -----Original Message----- > > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > > project.org] On Behalf Of Kutlwano Ramaboa > > Sent: Wednesday, February 18, 2009 10:43 PM > > To: r-help@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@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. > > ______________________________________________ > R-help@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. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. ______________________________________________ R-help@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. [[alternative HTML version deleted]] ______________________________________________ R-help@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.