# Would the group means of PC scores differ from the PC scores of group means?

I have $2$ $n\times p$ matrices, where $n$ are the rows (samples), and $p$ the columns (measurements). Each matrix has samples and measurements from different groups. I call these the "raw" data. I've conducted a principal components analyses of the complete raw data, and computed the mean of each PC score by group. The latter I call the mean of the PC scores by group.

My question is whether the means of the PC scores by group (raw-data $\rightarrow$ PCA $\rightarrow$ mean PCs by group) would differ from the PC scores derived from a PCA conducted on the "raw" group means (raw data $\rightarrow$ mean by group $\rightarrow$ PCA)?

### Example analysis of simulated data

set.seed(123)
a <- matrix(rnorm(900),ncol=3,byrow=F)
a[1:100,] <- 4 + a[1:100,]
a[101:200,] <- -4 + a[101:200,]
# compute PCA and extract PC scores
pc <- prcomp(a)$x plot(pc[,1:2],col=rep(c("red","blue","green"),each=100)) # compute PC means and plot m <-rbind(colMeans(pc[1:100,1:2]),colMeans(pc[101:200,1:2]),colMeans(pc[201:300,1‌​‌​:2])) points(m,col="black", pch=19,cex=1) # compute means of raw data by group b <- rbind(colMeans(a[1:100,]),colMeans(a[101:200,]),colMeans(a[201:300,])) # conduct PCA on "raw means" and plot pc2 <- prcomp(b)$x
points(pc2[,1:2],col="black", pch=17,cex=1)

• The mean of a random variable is a number and therefore has no covariance. It sounds like you might be asking about the difference between the distribution of a random variable and the distribution of the mean of a sample from that variable, but it is hard to tell: perhaps you could edit this question to clarify what you are looking for. PCA, by the way, does not model the data as realizations of random variables: it is a descriptive procedure. – whuber Oct 27 '13 at 17:11
• I am not sure how you would do PCA on the means. But, if you know what you mean, why not just do it both ways and see if they are different? – Peter Flom Oct 27 '13 at 17:50
• I have, and there is a slight difference between means. I believe this is happening because the covariance between the sample Ps do not equal the covariance between their means (mean of P by group). I am assuming that this is happening because in the latter not all deviations are going into the computation of the covariance matrix (i.e.,1/(n-1)*sum(x-xbar * y-ybar)). I wondered if there is a more general reason for the differences. – user2925487 Oct 27 '13 at 18:18
• The command "colMeans(pc[1:100,1:2])" would not run (or even worse maybe calculates recycled loadings...). If you are interested in PC-scores, you need to use the "predict" method of "prcomp", i.e. "predict(pc)". Besides all other issues: Is there a particular reason why you run the PCA on unscaled variables? – Michael M Oct 28 '13 at 19:21