
Last chance! 50% off unlimited learning
Sale ends in
## univariate
## S3 method for class 'kde':
plot(x, xlab, ylab="Density function", add=FALSE,
drawpoints=FALSE, ptcol="blue", col="black", jitter=TRUE, ...)## bivariate
## S3 method for class 'kde':
plot(x, display="slice", cont=c(25,50,75), abs.cont,
xlab, ylab, zlab="Density function", add=FALSE, drawpoints=FALSE,
drawlabels=TRUE, theta=-30, phi=40, d=4,
ptcol="blue", col="black", ...)
## trivariate
## S3 method for class 'kde':
plot(x, cont=c(25,50,75), abs.cont, colors,add=FALSE,
drawpoints=FALSE, alphavec, xlab, ylab, zlab, size=3, ptcol="blue",
...)
misc3d
and rgl
libraries and is sent to RGL window.drawpoints=TRUE
then a rug plot is added.
-- There are three types of plotting displays for 2-d data available,
controlled by the display
parameter. If display="slice"
then a slice/contour plot
is generated using contour
.
The default contours are at 25%, 50%, 75% or
cont=c(25,50,75)
which are upper percentages of
highest density regions. See below for alternative
contour levels.
If display="persp"
then a perspective/wire-frame plot
is generated. The default z-axis limits zlim
are the default
from the usual persp
command.
If display="image"
then an image plot
is generated. Default colours are the default from the usual
image
command.
-- For 3-dimensional data, the interactive plot is a series of nested
3-d contours.
The default contours are cont=c(25,50,75)
. See below for
alternative contour levels. The
default colors
are heat.colors
and the
default opacity alphavec
ranges from 0.1 to 0.5.
-- To specifiy contours, either one of cont
or abs.cont
is required. cont
specifies upper percentages which
correspond to
highest density regions. If abs.cont=NULL
then a pretty
set of contours is drawn. If abs.cont
is set to particular
values, then contours at these levels are drawn.
This third option is useful for plotting
multiple density estimates with common contour levels. See
contourLevels
for details on computing contour levels
for kde
objects.
kde
## univariate example
x <- rnorm.mixt(n=100, mus=1, sigmas=1, props=1)
fhat <- kde(x=x, h=hpi(x))
plot(fhat)
## bivariate example
data(unicef)
H.scv <- Hscv(x=unicef)
fhat <- kde(x=unicef, H=H.scv)
plot(fhat)
plot(fhat, drawpoints=TRUE, drawlabels=FALSE, col=3, lwd=2)
plot(fhat, display="persp", border=NA, col="grey96", shade=0.75)
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, xmin=c(-4,-4), xmax=c(4,4))
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, xmin=c(-4,-4), xmax=c(4,4))
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=100, mus=mus, Sigmas=Sigmas, props=props)
H.pi <- Hpi(x, pilot="samse")
fhat <- kde(x, H=H.pi)
plot(fhat)
plot(fhat, axes=FALSE, box=FALSE); axes3d(c('x','y','z'))
Run the code above in your browser using DataLab