factor_analysis_examples
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
factor_analysis_examples [2019/11/20 08:39] – created hkimscil | factor_analysis_examples [2022/05/05 15:02] (current) – [2] hkimscil | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | ====== Personality ====== | + | {{: |
< | < | ||
- | d <- read.table(" | + | # read the dataset into R variable using the read.csv(file) function |
+ | data <- read.csv(" | ||
+ | head(data) | ||
</ | </ | ||
- | 살펴보기 (head) | ||
- | 구조및성질 (str) | ||
- | 상관관계 도식화 (corrplot) | ||
- | * require corrplot package | ||
< | < | ||
- | install.packages(" | + | # install the package |
- | library(corrplot) | + | # install.packages(" |
- | corrplot(cor(d), order = " | + | # install.packages(" |
- | </ | + | # load the package |
+ | library(psych) | ||
+ | library(GPArotation) | ||
+ | </ | ||
- | fa 펑션 factor analysis | ||
< | < | ||
- | library(psych) | + | # calculate the correlation matrix |
- | d.fa <- fa(d, rotate=" | + | corMat |
- | names(d.fa) # to see what comes with the output d.fa | + | # display the correlation matrix |
+ | round(corMat,3) | ||
</ | </ | ||
+ | < | ||
+ | # use fa() to conduct an oblique principal-axis exploratory factor analysis | ||
+ | # save the solution to an R variable | ||
+ | fa.ini <- fa(r = corMat) | ||
+ | # display the solution output | ||
+ | fa.ini | ||
+ | </ | ||
+ | < | ||
+ | names(fa.ini) | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | fa.ini$e.values | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | num <- 5 | ||
+ | fa.5 <- fa(r=corMat, | ||
+ | fa.5.oblimin.minres <- fa(r=corMat, | ||
+ | fa.5.vm.minres <- fa(r=corMat, | ||
+ | |||
+ | fa.sort(fa.5.oblimin.minres) | ||
+ | fa.sort(fa.5.vm.minres) | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | > fa.sort(fa.5.oblimin.minres) | ||
+ | Factor Analysis using method = minres | ||
+ | Call: fa(r = corMat, nfactors = num, rotate = " | ||
+ | Standardized loadings (pattern matrix) based upon correlation matrix | ||
+ | MR1 | ||
+ | Resale_Value | ||
+ | Price 0.58 0.23 -0.11 -0.01 -0.07 0.35 0.645 1.4 | ||
+ | Maintenance | ||
+ | Fuel_Efficiency | ||
+ | Safety | ||
+ | Space_comfort | ||
+ | Fuel_Type | ||
+ | Technology | ||
+ | After_Sales_Service -0.01 0.04 0.95 -0.01 -0.01 0.92 0.085 1.0 | ||
+ | Color 0.03 -0.05 0.02 0.78 0.09 0.67 0.329 1.0 | ||
+ | Exterior_Looks | ||
+ | Testimonials | ||
+ | Test_drive | ||
+ | Product_reviews | ||
+ | |||
+ | | ||
+ | SS loadings | ||
+ | Proportion Var 0.12 0.10 0.09 0.08 0.07 | ||
+ | Cumulative Var 0.12 0.22 0.30 0.38 0.45 | ||
+ | Proportion Explained | ||
+ | Cumulative Proportion 0.26 0.48 0.67 0.85 1.00 | ||
+ | |||
+ | With factor correlations of | ||
+ | MR1 | ||
+ | MR1 1.00 -0.03 0.16 0.25 0.03 | ||
+ | MR2 -0.03 1.00 0.32 -0.07 0.21 | ||
+ | MR4 0.16 0.32 1.00 0.13 0.07 | ||
+ | MR5 0.25 -0.07 0.13 1.00 0.17 | ||
+ | MR3 0.03 0.21 0.07 0.17 1.00 | ||
+ | |||
+ | Mean item complexity = 1.8 | ||
+ | Test of the hypothesis that 5 factors are sufficient. | ||
+ | |||
+ | The degrees of freedom for the null model are 91 and the objective function was 2.97 | ||
+ | The degrees of freedom for the model are 31 and the objective function was 0.34 | ||
+ | |||
+ | The root mean square of the residuals (RMSR) is 0.04 | ||
+ | The df corrected root mean square of the residuals is 0.06 | ||
+ | |||
+ | Fit based upon off diagonal values = 0.97 | ||
+ | Measures of factor score adequacy | ||
+ | | ||
+ | Correlation of (regression) scores with factors | ||
+ | Multiple R square of scores with factors | ||
+ | Minimum correlation of possible factor scores | ||
+ | |||
+ | |||
+ | > fa.sort(fa.5.vm.minres) | ||
+ | Factor Analysis using method = minres | ||
+ | Call: fa(r = corMat, nfactors = num, rotate = " | ||
+ | Standardized loadings (pattern matrix) based upon correlation matrix | ||
+ | MR1 | ||
+ | Resale_Value | ||
+ | Maintenance | ||
+ | Price 0.57 0.15 -0.05 -0.04 -0.02 0.35 0.645 1.2 | ||
+ | Fuel_Efficiency | ||
+ | Space_comfort | ||
+ | Fuel_Type | ||
+ | Technology | ||
+ | Safety | ||
+ | Testimonials | ||
+ | Test_drive | ||
+ | Product_reviews | ||
+ | After_Sales_Service | ||
+ | Color 0.21 -0.05 0.26 0.07 0.74 0.67 0.329 1.4 | ||
+ | Exterior_Looks | ||
+ | |||
+ | | ||
+ | SS loadings | ||
+ | Proportion Var 0.12 0.11 0.08 0.07 0.07 | ||
+ | Cumulative Var 0.12 0.23 0.31 0.38 0.45 | ||
+ | Proportion Explained | ||
+ | Cumulative Proportion 0.27 0.51 0.68 0.84 1.00 | ||
+ | |||
+ | Mean item complexity = 1.7 | ||
+ | Test of the hypothesis that 5 factors are sufficient. | ||
+ | |||
+ | The degrees of freedom for the null model are 91 and the objective function was 2.97 | ||
+ | The degrees of freedom for the model are 31 and the objective function was 0.34 | ||
+ | |||
+ | The root mean square of the residuals (RMSR) is 0.04 | ||
+ | The df corrected root mean square of the residuals is 0.06 | ||
+ | |||
+ | Fit based upon off diagonal values = 0.97 | ||
+ | Measures of factor score adequacy | ||
+ | | ||
+ | Correlation of (regression) scores with factors | ||
+ | Multiple R square of scores with factors | ||
+ | Minimum correlation of possible factor scores | ||
+ | > | ||
+ | > | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | Factor Analysis using method = minres | ||
+ | Call: fa(r = corMat, nfactors = num, rotate = " | ||
+ | Standardized loadings (pattern matrix) based upon correlation matrix | ||
+ | MR1 | ||
+ | ---------------------------------------------------------------- | ||
+ | Resale_Value | ||
+ | Maintenance | ||
+ | Price 0.57 0.15 -0.05 -0.04 -0.02 0.35 0.645 1.2 | ||
+ | Fuel_Efficiency | ||
+ | ---------------------------------------------------------------- | ||
+ | Space_comfort | ||
+ | Fuel_Type | ||
+ | Technology | ||
+ | Safety | ||
+ | ---------------------------------------------------------------- | ||
+ | Testimonials | ||
+ | Test_drive | ||
+ | Product_reviews | ||
+ | ---------------------------------------------------------------- | ||
+ | After_Sales_Service | ||
+ | ---------------------------------------------------------------- | ||
+ | Color 0.21 -0.05 0.26 0.07 0.74 0.67 0.329 1.4 | ||
+ | Exterior_Looks | ||
+ | |||
+ | | ||
+ | SS loadings | ||
+ | Proportion Var 0.12 0.11 0.08 0.07 0.07 | ||
+ | Cumulative Var 0.12 0.23 0.31 0.38 0.45 | ||
+ | Proportion Explained | ||
+ | Cumulative Proportion 0.27 0.51 0.68 0.84 1.00 | ||
+ | </ | ||
+ | |||
+ | ====== 2 ====== | ||
+ | < | ||
+ | food <- read.csv(" | ||
+ | | ||
+ | str(food) | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | food.ini <- fa(food) | ||
+ | food.ini$e.values | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | food.fa <- factanal(food, | ||
+ | food.fa | ||
+ | food.fa$uniquenesses | ||
+ | apply(food.fa$loadings^2, | ||
+ | 1 - apply(food.fa$loadings^2, | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | Lambda <- food.fa$loadings | ||
+ | Psi <- diag(food.fa$uniquenesses) | ||
+ | S <- food.fa$correlation | ||
+ | Sigma <- Lambda %*% t(Lambda) + Psi | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | round(S - Sigma, 6) | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | food.fa.none <- factanal(food, | ||
+ | food.fa.varimax <- factanal(food, | ||
+ | food.fa.promax <- factanal(food, | ||
+ | |||
+ | par(mfrow = c(1,3)) | ||
+ | plot(food.fa.none$loadings[, | ||
+ | | ||
+ | xlab = " | ||
+ | ylab = " | ||
+ | ylim = c(-1,1), | ||
+ | xlim = c(-1,1), | ||
+ | main = "No rotation" | ||
+ | abline(h = 0, v = 0) | ||
+ | |||
+ | plot(food.fa.varimax$loadings[, | ||
+ | | ||
+ | xlab = " | ||
+ | ylab = " | ||
+ | ylim = c(-1,1), | ||
+ | xlim = c(-1,1), | ||
+ | main = " | ||
+ | |||
+ | text(food.fa.varimax$loadings[, | ||
+ | | ||
+ | colnames(food), | ||
+ | col=" | ||
+ | abline(h = 0, v = 0) | ||
+ | |||
+ | plot(food.fa.promax$loadings[, | ||
+ | | ||
+ | xlab = " | ||
+ | ylab = " | ||
+ | ylim = c(-1,1), | ||
+ | xlim = c(-1,1), | ||
+ | main = " | ||
+ | abline(h = 0, v = 0) | ||
+ | |||
+ | par(mfrow = c(1,1)) | ||
+ | </ |
factor_analysis_examples.1574206792.txt.gz · Last modified: 2019/11/20 08:39 by hkimscil