Tuesday, October 12, 2010

R: Canonical Discriminant Analysis

# Data input: generic

# lib(s): candisc, heplots # !!! heplots is a necessary dependency, and wasn't available on the SG host, so I used USA-CA(1) - think it's UC Berkeley !!!

# Red indicates stuff ya gotta to edit.

# this requires the input of some kind of precomputed multivariate model - usually MANOVA.
# Generalized canonical discriminant analysis may also be perfromed for one term in a multivariate linear model (ie: an object of class mlm) - this means the output of some lm() function.

library(candisc)

# MANOVA:
Y <- cbind(infile$dep.var1,infile$dep.var2,...,infile$dep.var)# dependent variables have to be cbind-ed together.
output <- manova(Y ~ indep.var1*indep.var2*indep.var3*...*indep.var)

# Canonical Discriminant Analysis (in its simplest form)
candisc(output)

# Here's the mlm:
Y <- cbind(infile$dep.var1,infile$dep.var2,...,infile$dep.var)# dependent variables have to be cbind-ed together.
output <- lm(Y ~ indep.var1*indep.var2*indep.var3*...*indep.var)

# and here's the generalized canonical discriminant analysis (in its simplest form)
candisc(output,term="indep.var")

# a plot for thought:
candisc.result <- candisc(output)
plot(candisc.result)

# /* END OF CANONICAL DISCRIMINANT ANALYSIS */

No comments:

Post a Comment