#http://stats.stackexchange.com/q/166592/1036 library(MASS) #gung's answer using discriminant analysis Iris = iris[,c(1,5)] model = lda(Species~Sepal.Length, Iris) range(Iris$Sepal.Length) # [1] 4.3 7.9 predData <- data.frame(Sepal.Length=seq(4, 8, .1)) predData$ldaClass <- predict(model,newdata=predData)$class #effect plot, see http://www.jstatsoft.org/v32/i01/paper library(effects) library(nnet) mul_mod <- multinom(Species~Sepal.Length, data=Iris) eff <- effect("Sepal.Length", mul_mod) plot(eff, style="stacked", rug = FALSE) #default plot(eff) shows the probabilities in small multiples #can make the same type of plot with posterior for LDA, or prob for rpart predData$multinomClass <- predict(mul_mod, newdata=predData, type="class") predData #exactly the same predictions with multinomial and lda #with splines in prediction, stacked chart is basically the same #library(splines) #mul_modS <- multinom(Species~bs(Sepal.Length,3), data=Iris) #effS <- effect("bs(Sepal.Length,3)", mul_modS) #plot(effS, style="stacked", rug = FALSE) #Placidia's option of using trees library(rpart) modelTree <- rpart(Species~Sepal.Length, Iris) predData$TreeClass <- predict(modelTree,predData,type="class") predData #only one difference with LDA or multinomial logistic regression