#First load required packageslibrary(tidyverse)Boston<-readRDS('Boston.rds')Boston%>% column_to_rownames('Town')%>% prcomp(scale.=TRUE)->pcaoutscreeplot(pcaout,type = 'l')
biplot(pcaout)
yij=λj1f1i+λj2f2i+…+ξij
yij=λj1f1i+λj2f2i+…+ξij
yi=Λfi+ξi
yij=λj1f1i+λj2f2i+…+ξij
yi=Λfi+ξi
E(yy′)=Σ=ΛΛ′+Ψ
E(yy′)=Σ=ΛΛ′+Ψ
factanal
from the stats
packagefactanal
from the stats
package#First load required packagesBoston<-readRDS('Boston.rds')Boston%>% column_to_rownames('Town')%>% factanal(factors = 2,scores = 'none', rotation = 'none')->facto
facto$loadings
## ## Loadings:## Factor1 Factor2## CRIM 0.548 ## ZN -0.401 0.455 ## INDUS 0.752 -0.513 ## CHAS -0.120 ## NOX 0.630 -0.628 ## RM -0.280 0.371 ## AGE 0.531 -0.576 ## DIS -0.611 0.573 ## RAD 0.923 0.282 ## TX 0.979 0.103 ## PTRATIO 0.472 0.251 ## B -0.459 ## LSTAT 0.532 -0.384 ## MEDV -0.622 0.297 ## ## Factor1 Factor2## SS loadings 5.071 2.080## Proportion Var 0.362 0.149## Cumulative Var 0.362 0.511
tidy
function in the broom
package.library(broom)fa_df<-tidy(facto) #Get into data frame
variable | uniqueness | fl1 | fl2 |
---|---|---|---|
CRIM | 0.6957467 | 0.5475829 | 0.0660978 |
ZN | 0.6318782 | -0.4009173 | 0.4554129 |
INDUS | 0.1721753 | 0.7517319 | -0.5125564 |
CHAS | 0.9847352 | -0.0248617 | -0.1202525 |
NOX | 0.2081610 | 0.6302070 | -0.6282309 |
RM | 0.7835958 | -0.2803734 | 0.3712276 |
AGE | 0.3870295 | 0.5306744 | -0.5756284 |
DIS | 0.2983700 | -0.6109165 | 0.5730549 |
RAD | 0.0687967 | 0.9228758 | 0.2819623 |
TX | 0.0307162 | 0.9790952 | 0.1032290 |
PTRATIO | 0.7146628 | 0.4716189 | 0.2509158 |
B | 0.7799470 | -0.4585974 | 0.0985286 |
LSTAT | 0.5691174 | 0.5324934 | -0.3838319 |
MEDV | 0.5247087 | -0.6220804 | 0.2970937 |
The plot is clearer if arrows are used
ggplot(fa_df,aes(x=fl1,y=fl2, label=variable))+ geom_segment(aes(xend=fl1, yend=fl2,x=0,y=0), arrow = arrow())+ geom_text(color='red',nudge_y = -0.05)
It is difficult to interpret these Factors
It is difficult to interpret these Factors
It is difficult to interpret these Factors
It is difficult to interpret these Factors
Recall the model is
yi=Λfi+ξi
Assume there is an r × r rotation matrix R. Since R′R=I the model above is equivalent to
yi=ΛR′Rfi+ξi
Grouping parts together we have
yi=(ΛR′)(Rfi)+ξi
Now we have new loadings ~Λ=ΛR′ and new factors ~fi=Rfi
rotation='varimax'
option in factanal
.Boston%>% column_to_rownames('Town')%>% factanal(factors = 2,scores = 'none', rotation = 'varimax')->facto_vari
variable | uniqueness | fl1 | fl2 |
---|---|---|---|
CRIM | 0.6957467 | 0.2269179 | 0.5027168 |
ZN | 0.6318782 | -0.5971858 | -0.1072602 |
INDUS | 0.1721753 | 0.8276842 | 0.3778276 |
CHAS | 0.9847352 | 0.0900150 | -0.0835228 |
NOX | 0.2081610 | 0.8637425 | 0.2139719 |
RM | 0.7835958 | -0.4627562 | -0.0477061 |
AGE | 0.3870295 | 0.7672114 | 0.1560450 |
DIS | 0.2983700 | -0.8065489 | -0.2260306 |
RAD | 0.0687967 | 0.2365087 | 0.9355566 |
TX | 0.0307162 | 0.4185322 | 0.8911309 |
PTRATIO | 0.7146628 | 0.0294672 | 0.5333993 |
B | 0.7799470 | -0.3217031 | -0.3413600 |
LSTAT | 0.5691174 | 0.6040563 | 0.2568894 |
MEDV | 0.5247087 | -0.5762219 | -0.3784402 |
rotation='promax'
in factanal
, an oblique 'rotation' can be carried out.Boston%>% column_to_rownames('Town')%>% factanal(factors = 2,scores = 'none', rotation = 'promax')->facto_promax
variable | uniqueness | fl1 | fl2 |
---|---|---|---|
CRIM | 0.6957467 | 0.0831127 | 0.5012340 |
ZN | 0.6318782 | -0.6473132 | 0.0800125 |
INDUS | 0.1721753 | 0.8163722 | 0.1528374 |
CHAS | 0.9847352 | 0.1327142 | -0.1267869 |
NOX | 0.2081610 | 0.9155035 | -0.0480169 |
RM | 0.7835958 | -0.5140824 | 0.1027513 |
AGE | 0.3870295 | 0.8251783 | -0.0817944 |
DIS | 0.2983700 | -0.8456368 | 0.0146546 |
RAD | 0.0687967 | -0.0584710 | 0.9960908 |
TX | 0.0307162 | 0.1660177 | 0.8829523 |
PTRATIO | 0.7146628 | -0.1542302 | 0.6038121 |
B | 0.7799470 | -0.2487379 | -0.2832482 |
LSTAT | 0.5691174 | 0.6024474 | 0.0898444 |
MEDV | 0.5247087 | -0.5276646 | -0.2392111 |
GPArotation
GPArotation
GPArotation
scores='regression'
or scores='Bartlett'
in factanal
.Other estimation methods can also be used for the factor model.
psych
package.Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |