library(MASS)
data(iris)
xlab <- "Sepal length (mm)"
ylab <- "Sepal width (mm)"
xlim <- c(4,8)
ylim <- c(2,4.5)
## univariate example
ir <- iris[,1]
ir.gr <- iris[,5]
kda.fhat <- kda.kde(ir, ir.gr, hs=sqrt(c(0.01, 0.04, 0.07)))
plot(kda.fhat, xlab=xlab, ptcol=1:3)
## bivariate example
ir <- iris[,1:2]
ir.gr <- iris[,5]
H <- Hkda(ir, ir.gr, bw="plugin", pre="scale")
kda.fhat <- kda.kde(ir, ir.gr, Hs=H)
plot(kda.fhat, cont=0, xlab=xlab, ylab=ylab, xlim=xlim, ylim=ylim)
plot(kda.fhat, ncont=6, xlab=xlab, ylab=ylab, xlim=xlim, ylim=ylim,
col=c("transparent", "grey", "#8f8f8f"), drawlabels=FALSE,
pch=c(1,5,10))
## trivariate example
ir <- iris[,1:3]
ir.gr <- iris[,5]
H <- Hkda(ir, ir.gr, bw="plugin", pre="scale")
kda.fhat <- kda.kde(ir, ir.gr, Hs=H)
plot(kda.fhat)
## colour indicates species, transparency indicates density heights
Run the code above in your browser using DataLab