## bivariate example
library(MASS)
data(iris)
ir <- iris[,c(1,2)]
ir.gr <- iris[,5]
xlab <- "Sepal length (mm)"
ylab <- "Sepal width (mm)"
xlim <- c(4,8)
ylim <- c(2,4.5)
H <- Hkda(ir, ir.gr, bw="plugin", pre="scale")
fhat <- kda.kde(ir, ir.gr, H)
lda.fhat <- pda.pde(ir, ir.gr, type="line")
qda.fhat <- pda.pde(ir, ir.gr, type="quad")
layout(rbind(c(1,2), c(3,4)))
plot(fhat, cont=0, xlab=xlab, ylab=ylab, xlim=xlim, ylim=ylim,
pch=c(1,5,10))
plot(fhat, ncont=6, xlab=xlab, ylab=ylab, xlim=xlim, ylim=ylim,
col=c("transparent", "grey", "#8f8f8f"), drawlabels=FALSE)
plot(lda.fhat, ncont=6, xlim=xlim, ylim=ylim, xlab=xlab, ylab=ylab,
disp="")
plot(qda.fhat, ncont=6, xlim=xlim, ylim=ylim, xlab=xlab, ylab=ylab,
lty=c(2,5,3))
layout(1)
## trivariate example
ir <- iris[,1:3]
ir.gr <- iris[,5]
H <- Hkda(ir, ir.gr, bw="plugin", pre="scale")
fhat <- kda.kde(ir, ir.gr, H)
plot(fhat, cont=c(25,50))
## colour indicates species, transparency indicates density heights
qda.fhat <- pda.pde(ir, ir.gr, type="quad")
plot(qda.fhat, cont=c(25,50))
Run the code above in your browser using DataLab