[R] principal components question

Bill Simpson William.Simpson at drdc-rddc.gc.ca
Wed Sep 29 19:40:27 CEST 2004


I have the following problem with PCA.

I have measures from lots of people (>200) on variables sf1, sf2, sf4, 
sf8, sf16, sf24. The goal is to see underlying "channels" using PCA. Each 
person i has a "contrast sensitivity function" s_i(f) composed of the 
summed output of several channels c(f), each weighted differently for each 
subject:

s_i(f) = a_1i * c_1(f) + a_2i * c_2(f) + ... + a_ni * c_n(f)

(s_i(f) was measured at 6 values of f, sf1-sf24)

This all works well using prcomp.

My question. I would like to fit the average s(f) across subjects using 
the derived channels c_1(f) - c_n(f). Somehow I need to get the weights 
a_1 to a_n

s(f) = a_1 * c_1(f) + a_2 * c_2(f) + ... + a_n * c_n(f)

Here is what I did, but there is probably a better solution.
dd is the data frame.

sf<-c(1,2,4,8,16,24)
ddmean<-apply(dd,2,mean)
out<-prcomp(dd)
r1<-out$rotation[,1];r2<-out$rotation[,2];r3<-out$rotation[,3]

#rotate the loadings to give "simple structure"
Sr<- varimax(out$rotation[,1:3])$loadings
Sr1<-Sr[,1];Sr2<-Sr[,2];Sr3<-Sr[,3]  #I just used the first 3 PCs

fn <- function(p) sum((ddmean - (p[4]+p[1]*Sr1 +p[2]*Sr2+p[3]*Sr3))^2)
fit<-nlm(fn,p=c(-1000,-100,-100,10),hessian=TRUE)
b<-fit$estimate

plot(sf,ddmean,log="x",ylim=c(5,225),xaxt="n",ylab="",xlab="",pch=15)
lines(sf,b[4]+b[1]*Sr1 + b[2]*Sr2 + b[3]*Sr3,lwd=3)
lines(sf,b[4]/3+b[1]*Sr1,lty=1)
lines(sf,b[4]/3+b[2]*Sr2,lty=2)
lines(sf,b[4]/3+b[3]*Sr3,lty=3)

Thanks very much for any help.

BTW, I have heard of "functional PCA" and it sounds more appropriate for 
what I am doing. Any pointers on how to do that in R or to any info are 
appreciated.

Bill Simpson




More information about the R-help mailing list