## univariate example
x <- rnorm.mixt(n=100, mus=1, sigmas=1, props=1)
fhat <- kde(x, h=sqrt(0.09))
plot(fhat)
## bivariate example
data(unicef)
H.scv <- Hscv(unicef)
fhat <- kde(unicef, H=H.scv)
plot(fhat)
plot(fhat, drawpoints=TRUE, drawlabels=FALSE, col=3, lwd=2)
plot(fhat, display="persp")
plot(fhat, display="image", col=rev(heat.colors(100)))
plot(fhat, display="filled")
## pair of densities with same absolute contour levels
x <- rmvnorm.mixt(n=100, mus=c(0,0), Sigmas=diag(2), props=1)
Hx <- Hpi(x)
fhatx <- kde(x=x, H=Hx)
y <- rmvnorm.mixt(n=100, mus=c(0.5,0.5), Sigmas=0.5*diag(2), props=1)
Hy <- Hpi(y)
fhaty <- kde(x=y, H=Hy)
lev <- contourLevels(fhatx, prob=c(0.25, 0.5, 0.75))
plot(fhatx, abs.cont=lev)
plot(fhaty, abs.cont=lev, col=3, add=TRUE)
## large sample - 10000 sample from bivariate standard normal
x <- rmvnorm.mixt(10000, c(0,0), diag(2))
H.pi <- Hpi.diag(x, binned=TRUE)
fhat <- kde(x, H=H.pi, binned=TRUE)
plot(fhat, drawpoints=FALSE, cont=seq(10,90, by=20))
## trivariate example
mus <- rbind(c(0,0,0), c(-1,1,1))
Sigma <- matrix(c(1, 0.7, 0.7, 0.7, 1, 0.7, 0.7, 0.7, 1), nr=3, nc=3)
Sigmas <- rbind(Sigma, Sigma)
props <- c(1/2, 1/2)
x <- rmvnorm.mixt(n=1000, mus=mus, Sigmas=Sigmas, props=props)
H.pi <- Hpi(x, pilot="samse")
fhat <- kde(x, H=H.pi)
plot(fhat)
Run the code above in your browser using DataLab