I got hold of 'Modern Applied Statistics with S' by Venables and Ripley
(p.
335-336) and I was able to answer my own question:
###
AA<-read.table("http://www.natursyn.dk/online/fingerprinting.txt",header=T)
aa.grp <-
factor(c(rep('f',13),rep('b',10),rep('p',10)))
aa.lda<-lda(as.matrix(AA[3:9]),AA$group)
aa.ld<-predict(aa.lda,dimen=2)$x
eqscplot(aa.ld,type="n",xlab="LD1",
ylab="LD2",tol=0.25, las=1)
text(aa.ld,labels = as.character(aa.grp))
aa.lda2 <- lda(aa.ld, aa.grp)
x <- seq(-7, 5.5, 0.25)
y <- seq(-4.5, 6.5, 0.25)
Xcon <- matrix(c(rep(x,length(y)),
rep(y, rep(length(x), length(y)))),,2)
aa.pr1 <- predict(aa.lda2, Xcon)$post[, c("f","b")] %*%
c(1,1)
contour(x, y, matrix(aa.pr1, length(x), length(y)),
levels=0.5, add=T, lty=3,method="simple")
aa.pr2 <- predict(aa.lda2, Xcon)$post[, c("p","b")] %*%
c(1,1)
contour(x, y, matrix(aa.pr2, length(x), length(y)),
levels=0.5, add=T, lty=3,method="simple")
aa.pr3 <- predict(aa.lda2, Xcon)$post[, c("f","p")] %*%
c(1,1)
contour(x, y, matrix(aa.pr3, length(x), length(y)),
levels=0.5, add=T, lty=3,drawlabels=F)
###
Thomas Larsen wrote:>
> Hi,
>
> I am using the lda function from the MASS library. I would to find the
> decision boundaries of each class and subsequently plot them. I wonder if
> anybody can offer any help on this topic?
>
> Below I applied the lda function on a small dataset of mine.
>
> Any help will be much appreciated.
>
>> library(MASS)
>
>>
AA<-read.table("http://www.natursyn.dk/online/fingerprinting.txt",header=T)
>
>> aa.lda<-lda(as.matrix[3:9],AA$group)
>> aa.ld<-predict(aa.lda,dimen=2)$x
>> eqscplot(aa.ld,type="n",xlab="LD1",
ylab="LD2",las=1)
>>
text(aa.ld,c(rep('f',13),rep('b',10),rep('p',10)))
>
>> aa.mean<-lda(aa.ld,AA$group)$means
>> points(aa.mean,pch=3)
>
> Best,
> Thomas Larsen
>
> Leibniz-Laboratory for Stable Isotope Research
> Max-Eyth-Str. 11-13, 24118 Kiel, Germany
> Work: +49-431-880-3896
>
--
View this message in context:
http://www.nabble.com/Decision-boundaries-for-lda-function--tp24823213p25137633.html
Sent from the R help mailing list archive at Nabble.com.