21 January 2013

Summary for MCA in R

standing <- read.table("filename.dat",sep=",",header=TRUE,row.names=1)

summary(gmo[,1:16])

specifiying supplement (sup, eg. description of individual answering questionairre) on the data:  res.mca <- MCA(tea,quali.sup=c(19:21,23:26))

names(standing)

ggplot:
mca1 = MCA(standing, graph = FALSE)
cats = apply(standing,2,function(x) nlevels(as.factor(x)))
mca1_vars_df = data.frame(mca1$var$coord, Variable = rep(names(cats), cats))
mca1_obs_df = data.frame(mca1$ind$coord)
ggplot(data = mca1_vars_df, aes(x = Dim.1, y = Dim.2, label = rownames(mca1_vars_df))) + geom_hline(yintercept = 0, colour = "gray70") + geom_vline(xintercept = 0, colour = "gray70") + geom_text(aes(colour = Variable)) + geom_density2d(colour = "gray80") + geom_text(data = mca1_vars_df, aes(x = Dim.1, y = Dim.2, label = rownames(mca1_vars_df), colour = Variable))

category comparison (one with others):
catdes(standing,num.var=2)
    $test.chi2


run a script containing printouts and plots:
source("script.r",print.eval = TRUE)

(note: printing is turned off in loops), so to plot in a loop:
print(ggplot(...))

leading zeros:
u <- formatC(i, width = 2, format = "d", flag = "0")
or
sprintf("Leading zeros:%04d", x)

Variables representation (use new.plot when the graph window is not showing anymore):
plot.MCA(res.2,choix="var",new.plot=TRUE)
add cex=0.5 for small font

Plotting data.frame:
X11();barplot(c(as.matrix(mca2$eig[3])))

Data used for "variables representation" plot in MCA:
res.mca$var$eta2

No comments:

Post a Comment