I\'m having trouble with part (e) of this question. I have completed the other p
ID: 3072092 • Letter: I
Question
I'm having trouble with part (e) of this question. I have completed the other parts, I'm just posting the whole question as part (e) refers to part (c).
Mathematics of principal components (a) Using the data mtcars, create the corrclation matrix of all the attributes and store the results in a (b) Compute the cigenvalucs and cigenvectors of corMat. (c) Use prcomp to compute the principal components of the mtcars attributes (make sure to use the new object corMat scale option). (d) Compare the results from (b) and (c) - Are they the same? Different? Why? (e) Using R demonstrate that principal components 1 and 2 from (c) are orthogonal. (Hint: the inner product between two vectors is useful in determining the angle between the two vectors)Explanation / Answer
# Q a) Correlation matrix
corMat=cor(mtcars)
# Q b) Eigen values and vectros
eigen(corMat)
# Q c) Principal component analysis
PCA=princomp(mtcars, cor = TRUE)
# Q e)
Y=predict(PCA,mtcars)
# each column of Y matrix be the projection on principale component
y1=Y[,1] #be the 1st principale component.
y2=Y[,2] #be the 2nd principale component.
# Definition: Two vectors u and v whose dot product is u·v=0 or u'v=0 (i.e., the vectors are perpendicular) are said to be orthogonal.
Dprod=t(y1)%*%y2 # dot product of principal components.
#Output
#Dprod= -2.521236e-14
#which is nearly equal to 0 therefore both 1st and 2nd principal components are orthogonal.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.