[R] PCA reconstruction funtion

Andris Jankevics andza at osi.lv
Fri Nov 10 09:58:21 CET 2006


Also new values can be easy calculated from prcomp object:

Data <- scale(iris[,1:4],center=TRUE,scale=TRUE)
iris.pc <- prcomp(Data)

# Explained variation
(iris.pc$sdev^2/sum(iris.pc$sdev^2))*100

# Loadings
iric.pc$rotation

#Scores
iris.pc$x


#Fitted Values for each PC

# Xfit = T*P^t

PCfit <- function (i,pcdata) 
{PCI <- pcdata$x[,i]%*%t(pcdata$rotation[,i])}

Fitted <- lapply (c(1:4),PCfit,pcdata=iris.pc)

for ( i in c(1:4) ) {
assign (paste("IrisPC",i,sep=""),Fitted[[i]])}

#Residuals
EPC1 <- round(Data - IrisPC1,3)
EPC2 <- round(Data - (IrisPC1+IrisPC2),3)
EPC3 <- round(Data - (IrisPC1+IrisPC2+IrisPC3),3)
EPC4 <- round(Data - (IrisPC1+IrisPC2+IrisPC3+IrisPC4),3)    # 0

Andris Jankevics

On Piektdiena, 10. Novembris 2006 05:58, Renaud Lancelot wrote:
> See ?rconst in package ade4. You will need to fit the PCA with
> dudi.pca (same package).
>
> Best,
>
> Renaud
>
> 2006/11/9, Poizot Emmanuel <poizot at cnam.fr>:
> > Dear all,
> >
> > I did performed a PCA analysis (using prcomp function) on a data matrix.
> > Then I would like to reconstruction part of the original data set using
> > only specifics and choosen  eigenvectors.
> > I would like to know if there is a function under R witch can perform
> > this reconstruction.
> > Regards
> >
> > --
> >
> > ------------------------------------------------
> > Emmanuel Poizot
> > Cnam/Intechmer
> > B.P. 324
> > 50103 Cherbourg Cedex
> >
> > Phone (Direct) : (00 33)(0)233887342
> > Fax : (00 33)(0)233887339
> > ------------------------------------------------
> >
> >
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch 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