I am using the function princomp
in R to run a principal components analysis.
In the summary()
of the model, the standard deviations of the components are listed. However, these standard deviations are not the same as the square root of the eigenvalues. Shouldn't these values be the same?
In an attempt to figure out what was wrong, I also tried to take each observation and multiply each term by its respective coefficient in the first component and then summed them. I then took the standard deviation of all of these calculated values. The standard deviation from this method matched the square root of the eigenvalues.
Why is the standard deviation in the summary not matching the standard deviation I calculated by hand and the square root of the eigenvalues? Am I mistaken in believing they should be the same?
Here is the code:
#import Data
data <- T8.5
attach(data)
#name variables
names(data) <- c("Total Population", "Median School Years", "Total Employment", "Health Services Employment", "Median Home Value")
#show data
data
#PCA
pca <- princomp(data, cor=FALSE, scores=TRUE)
eigenvalues <- eigen(var(data), symmetric=FALSE, only.values=FALSE)
#The standard deviations are different in the next two lines
summary(pca)
sqrt(eigenvalues$values)
#Here is where I tried to calculate the first component by hand
load <- with(pca, unclass(loadings))
value <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0)
#Testing the standard deviation for component 1
for (i in 1:14){
sum=0
for (j in 1:5){
sum = sum + data[i,j]*(load[j,1])
}
value[i] = sum
}
sd(value)
#This matches the sqrt(eigenvalues)