User Tools

Site Tools


factor_analysis

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
factor_analysis [2018/12/22 01:55] hkimscilfactor_analysis [2019/09/14 18:56] – [e.g. secu com finance 2007 example] hkimscil
Line 1148: Line 1148:
 ====== e.g., 5 ====== ====== e.g., 5 ======
 {{:r:EFA.csv}} {{:r:EFA.csv}}
 +====== e.g. secu com finance 2007 example  ======
 +{{:r:secu_com_finance_2007.csv}}
 +
 +<code>
 +Sys.setlocale("LC_ALL","Korean")
 +secu_com_finance_2007 <- read.csv("http://commres.net/wiki/_media/r/secu_com_finance_2007.csv")
 +secu_com_finance_2007
 +
 +# V1 : 총자본순이익율
 +# V2 : 자기자본순이익율
 +# V3 : 자기자본비율
 +# V4 : 부채비율
 +# V5 : 자기자본회전율
 +
 +# 표준화 변환 (standardization)
 +secu_com_finance_2007 <- transform(secu_com_finance_2007, 
 +    V1_s = scale(V1), 
 +    V2_s = scale(V2), 
 +    V3_s = scale(V3), 
 +    V4_s = scale(V4),
 +    V5_s = scale(V5))
 +
 +# 부채비율(V4_s)을 방향(max(V4_s)-V4_s) 변환
 +secu_com_finance_2007 <- transform(secu_com_finance_2007, V4_s2 = max(V4_s) - V4_s)
 +
 +# variable selection
 +secu_com_finance_2007_2 <- secu_com_finance_2007[,c("company", "V1_s", "V2_s", "V3_s", "V4_s2", "V5_s")]
 + 
 +# Correlation analysis
 +cor(secu_com_finance_2007_2[,-1])
 +
 +round(cor(secu_com_finance_2007_2[,-1]), digits=3) # 반올림
 +
 +# Scatter plot matrix
 +plot(secu_com_finance_2007_2[,-1])
 +
 +# Scree Plot
 +plot(prcomp(secu_com_finance_2007_2[,c(2:6)]), type="l", sub = "Scree Plot")
 +
 +</code>
 +
 +<code>
 +# 요인분석(maximum likelihood factor analysis)
 +# rotation = "varimax"
 +secu_factanal <- factanal(secu_com_finance_2007_2[,2:6], 
 +    factors = 2, 
 +    rotation = "varimax", # "varimax", "promax", "none" 
 +    scores="regression") # "regression", "Bartlett"
 +print(secu_factanal)
 +
 +</code>
 +
 +<code>
 +print(secu_factanal$loadings, cutoff=0) # display every loadings
 +
 +# factor scores plotting
 +secu_factanal$scores
 +
 +plot(secu_factanal$scores, main="Biplot of the first 2 factors")
 +
 +# 관측치별 이름 매핑(rownames mapping)
 +text(secu_factanal$scores[,1], secu_factanal$scores[,2], 
 +   labels = secu_com_finance_2007$company, 
 +   cex = 0.7, pos = 3, col = "blue")
 +
 +# factor loadings plotting
 +points(secu_factanal$loadings, pch=19, col = "red")
 +
 +
 +text(secu_factanal$loadings[,1], secu_factanal$loadings[,2], 
 +   labels = rownames(secu_factanal$loadings), 
 +   cex = 0.8, pos = 3, col = "red")
 +
 +# plotting lines between (0,0) and (factor loadings by Var.)
 +segments(0,0,secu_factanal$loadings[1,1], secu_factanal$loadings[1,2])
 +segments(0,0,secu_factanal$loadings[2,1], secu_factanal$loadings[2,2])
 +segments(0,0,secu_factanal$loadings[3,1], secu_factanal$loadings[3,2])
 +segments(0,0,secu_factanal$loadings[4,1], secu_factanal$loadings[4,2])
 +segments(0,0,secu_factanal$loadings[5,1], secu_factanal$loadings[5,2])
 +
 +
 +
 +</code>
 ====== etc.  ====== ====== etc.  ======
 <del>see http://geog.uoregon.edu/bartlein/courses/geog495/lec16.html</del> <del>see http://geog.uoregon.edu/bartlein/courses/geog495/lec16.html</del>
 {{:r:boxes.csv}} {{:r:boxes.csv}}
 {{:r:cities.csv}} {{:r:cities.csv}}
-{{:r:secu_com_finance_2007.csv}}+
 ====== Reference ====== ====== Reference ======
 {{:factor_analysis_lecture_note.pdf|Lecture Note}} from databaser {{:factor_analysis_lecture_note.pdf|Lecture Note}} from databaser
  
factor_analysis.txt · Last modified: 2023/11/06 02:53 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki