Saturday, October 27, 2007

Structural Equation Model

### Principle Component Analysis

## with prcomp()
prcomp(USArrests, scale=T)
prcomp(~Murder+Assault+Rape, data=USArrests, scale=T)
plot(prcomp(~Murder+Assault+Rape, data=USArrests, scale=T))
summary(prcomp(~Murder+Assault+Rape, data=USArrests, scale=T))
biplot(prcomp(~Murder+Assault+Rape, data=USArrests, scale=T))

## with princomp()
princomp(USArrests, cor=T)
princomp(~Murder+Assault+Rape, data=USArrests, cor=T)
summary(princomp(~Murder+Assault+Rape, data=USArrests, cor=T))
princomp(~Murder+Assault+Rape, data=USArrests, cor=T)$score
plot(princomp(~Murder+Assault+Rape, data=USArrests, cor=T))
biplot(princomp(~Murder+Assault+Rape, data=USArrests, cor=T))

# missing handling
USArrests[1,2]<-NA
princomp(~Murder+Assault+Rape, data=USArrests, na.action=na.exclude, cor=T)


### Factor Analysis with factanal()
factanal(~Murder+Assault+UrbanPop+Rape, factors=1, data=USArrests)

### FactoMineR

No comments: