setwd("C:\\Users\\authorized user\\Dropbox\\STAT445\\week9\\lectures") ########################################################## #problem 9.18 ########################################################## #excercise 8.16 page 475 # Variable explanation # x1= Bluegill # x2= Black crappie # x3= Smallmouth bass # x4= Largemouth bass # x5= Walleye # x6= Northern pike #Correlation matrix of the data #read the given matrix from the textbook Corr <- matrix(scan(n=36),nrow=6, byrow=TRUE) 1.0000 0.4919 0.2636 0.4653 -0.2277 0.0652 0.4919 1.0000 0.3217 0.3506 -0.1917 0.2045 0.2636 0.3217 1.0000 0.4108 0.0647 0.2493 0.4653 0.3506 0.4108 1.0000 -0.2249 0.2293 -0.2277 -0.1917 0.0647 -0.2249 1.0000 -0.2144 0.0652 0.2045 0.2493 0.2293 -0.2144 1.0000 colnames(Corr)=c('bg','bc','sb','lb','w','np') rownames(Corr)=c('bg','bc','sb','lb','w','np') #two factor analysis #factor1: described as sb+lb #factor2: described as bg+bc+lb #p_value =0.0294 reject null that 2 factors are sufficient at 0.05. fa1=factanal(covmat=Corr,factors=2,n.obs=120) (L=fa1$loadings) #calculate communalities (hi2=(L%*%t(L))) #get specific variances (psi=diag(fa1$uniquenesses)) #finally calculate the residual matrix (RezMat=Corr-(hi2+psi)) #diagonal elements of the residual matrix are 0 #which means that (hi2+psi) is close to #the the Correlation matrix #Interpretation #two factor analysis #factor1: described as bg+bc+lb #factor2: described as sb+lb #factor3: described as np #p_value =0.0014 reject null that 3 factors are sufficient at 0.01. fa2=factanal(covmat=Corr,factors=3,n.obs=120) (L=fa2$loadings) #calculate communalities (hi2=(L%*%t(L))) #get specific variances (psi=diag(fa2$uniquenesses)) #finally calculate the residual matrix (RezMat=Corr-(hi2+psi)) #diagonal elements of the residual matrix are 0 #which means that (hi2+psi) is close to #the the Correlation matrix #two factor model is better based on the p_value for the null hypothesis #that 2 factors are sufficient and also factor3 is harder to interpret in #3 factor model. Cumulative variance proportion increases unsignificantly #from 2 factor to 3 factor model