%Candace Metoyer %Stat 135 %Chapter 9 Demos %EXAMPLE 9.3 %Factor Analysis of Consumer Preference Data clear; clc; format compact; format short g; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Example 9.3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% p = 5; %Enter the correlation matrix R1 = [1 .02 .96 .42 .01]; R2 = [.02 1 .13 .71 .85]; R3 = [.96 .13 1 .5 .11]; R4 = [.42 .71 .50 1 .79]; R5 = [.01 .85 .11 .79 1]; R = [R1;R2;R3;R4;R5]; %Obtain the eigenvalues and eigenvectors [eigVEC, eigVAL] = eig(R); lambda = zeros(p,1); ReigVEC = zeros(size(eigVEC)); j = 1; for i = p:-1:1 %Decrease from p to 1 in steps of 1 lambda(i) = eigVAL(j,j); ReigVEC(:,i) = eigVEC(:,j); %re-ordered eigenvector matrix j = j+1; end lambda; ReigVEC; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Compute the cumulative percentage of the total variance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for i = 1:p cpercent(i) = sum(lambda(1:i))/sum(lambda); end cpercent %Compute the estimated factor loadings using m = 2 elltilde = [sqrt(lambda(1))*ReigVEC(:,1) sqrt(lambda(2))*ReigVEC(:,2)] %Compute the communalities and specific variances htilde2 = zeros(p,1); psitilde = zeros(p,p); for i = 1:p htilde2(i) = (norm(elltilde(i,:)))^2; psitilde(i,i) = 1 - htilde2(i); end lambda' %the eigenvalues htilde2 psitilde %Compare the estimate of R with the original matrix R Rest = elltilde*elltilde' + psitilde