I have trouble understanding how to 'export' equations of the delimitation lines resulting from a linear (LDA) or quadratic discriminant analysis (QDA) in R.
Ideally, I would like to compare both delineations (linear + quadratic curves) on the same graph. Here is an example of output (taken from http://adjchen.com/wiki/classification), with 2 groups. But it should work the same with multiples groups :
I have looked into this partial solution on stackoverflow, which I believe is a bit too sophisticated to draw a simple linear delimitation ?
How to plot classification borders on an Linear Discrimination Analysis plot in R
Here is an adaptation of the data set they use to play with in that example:
library(MASS)
# generate data
set.seed(123)
Ng <- 100 # number of cases per group
group.a.x <- rnorm(n = Ng, mean = 2, sd = 3)
group.a.y <- rnorm(n = Ng, mean = 2, sd = 3)
group.b.x <- rnorm(n = Ng, mean = 11, sd = 3)
group.b.y <- rnorm(n = Ng, mean = 11, sd = 3)
group.a <- data.frame(x = group.a.x, y = group.a.y, group = "A")
group.b <- data.frame(x = group.b.x, y = group.b.y, group = "B")
my.xy <- rbind(group.a, group.b)
# construct models
mdlLDA <- lda(group ~ x + y, data = my.xy)
mdlQDA <- qda(group ~ x + y, data = my.xy)
The closest alternative I came with is the partimat()
function from klaR
package, which however can be hard to modify or customize. Is there any other option using base R plot and equations of the delimitation line / curve ? or a ggplot function maybe ? Thanks in advance for any thoughts on this :) Best.