Monday, September 20, 2010

R: Correspondence Analysis

# In general, I didn't code this myself.
# Compiled from various sources.

# lib(s): ca, rgl

# Red indicates stuff you have to edit.

# Before using this script:
library(ca) # rgl will load automatically

# the easiest way to do this:
ca(infile)

mytable <- with(mydata, table(infile$cat.var1,infile$cat.var2)) # create a 2 way table
prop.table(mytable, 1) # row percentages
prop.table(mytable, 2) # column percentages
fit <- ca(mytable)
# print(fit) # basic results. Unnecessary in view of the next line.
summary(fit) # extended results. Quantities in the result are multiplied by 1000 (ie: expressed in permills)
plot(fit) # symmetric map
plot(fit, mass = TRUE, contrib = "absolute", map ="rowgreen", arrows = c(FALSE, TRUE)) # asymmetric map

# /* END OF CORRESPONDENCE ANALYSIS */

No comments:

Post a Comment