Thursday, October 21, 2010

R: Quardratic Discriminant Analysis

# Data input: generic

# lib(s): MASS, klaR

# Quadratic Discriminant Analysis with resubstitution prediction and equal prior probabilities.

library(MASS)
fit <- qda(dep.cat.var ~ indep.var1 + indep.var2 + indep.var3 + ... + indep.var, data=na.omit(infile),prior=c(1,1,1,...,1)/X) # where the number of 1's in prior=c(1,1,1,...,1) is equivalent to the number of groups in dep.cat.var and X is the number of groups in dep.cat.var (an integer).
# i would imagine all the independent variables here are continous variables, but i could be wrong. :\

# an exploratory graph
library(klaR)
partimat(dep.cat.var ~ indep.var1 + indep.var2 + indep.var3 + ... + indep.var,data=infile,method="qda")

# /* END OF QUADRATIC DISCRIMINANT ANALYSIS */

No comments:

Post a Comment