Last chance! 50% off unlimited learning
Sale ends in
Kernel density estimate for 1- to 6-dimensional data.
kde(x, H, h, gridsize, gridtype, xmin, xmax, supp=3.7, eval.points,
binned=FALSE, bgridsize, positive=FALSE, adj.positive, w,
compute.cont=TRUE, approx.cont=TRUE, unit.interval=FALSE,
verbose=FALSE)# S3 method for kde
predict(object, ..., x, zero.flag=TRUE)
matrix of data values
bandwidth matrix/scalar bandwidth. If these are missing, Hpi
or hpi
is called by default.
vector of number of grid points
not yet implemented
vector of minimum/maximum values for grid
effective support for standard normal
vector or matrix of points at which estimate is evaluated
flag for binned estimation. Default is FALSE.
vector of binning grid sizes
flag if 1-d data are positive. Default is FALSE.
adjustment applied to positive 1-d data
vector of weights. Default is a vector of all ones.
flag for computing 1% to 99% probability contour levels. Default is TRUE.
flag for computing approximate probability contour levels. Default is TRUE.
flag if 1-d data are bounded on unit interval [0,1]. Default is FALSE.
flag to print out progress information. Default is FALSE.
object of class kde
interploted values object$estimate
of when x
outside of object$eval.points
=0 (if TRUE
), = nearest
object$estimate
(if FALSE
)
other parameters
A kernel density estimate is an object of class kde
which is a
list with fields:
data points - same as input
vector or list of points at which the estimate is evaluated
density estimate at eval.points
scalar bandwidth (1-d only)
bandwidth matrix
"linear"
flag for estimation on a grid
flag for binned estimation
variable names
weights
probability contour levels (if compute.cont=TRUE
)
For d=1, if h
is missing, the default bandwidth is hpi
.
For d>1, if H
is missing, the default is Hpi
.
For d=1, if positive=TRUE
then x
is transformed to
log(x+adj.positive)
where the default adj.positive
is
the minimum of x
.
For d=1, 2, 3, 4, and if eval.points
is not specified, then the
density estimate is computed over a grid
defined by gridsize
(if binned=FALSE
) or
by bgridsize
(if binned=TRUE
). This form is suitable for
visualisation in conjuction with the plot
method.
--If eval.points
is specified, as a vector (d=1) or
as a matrix (d=2, 3, 4), then the
density estimate is computed at eval.points
. This form is
suitable for numerical summaries (e.g. maximum likelilood), and is
not compatible with the plot
method.
--For d>4, computing the kernel
density estimate over a grid is not feasible, and so it is computed exactly
and eval.points
(as a matrix) must be specified.
Binned kernel estimation is an approximation to the exact kernel estimation and is available for d=1, 2, 3, 4. This makes kernel estimators feasible for large samples.
The default bgridsize,gridsize
are d=1: 401; d=2: rep(151, 2);
d=3: rep(51, 3); d=4: rep(21,4).
The effective support for a normal kernel is where
all values outside [-supp,supp]^d
are zero.
The default xmin
is min(x)-Hmax*supp
and xmax
is max(x)+Hmax*supp
where Hmax
is the maximum of the
diagonal elements of H
. The grid produced is the outer
product of c(xmin[1], xmax[1])
, ..., c(xmin[d], xmax[d])
.
# NOT RUN {
## positive data example
set.seed(8192)
x <- 2^rnorm(100)
fhat <- kde(x=x, positive=TRUE)
plot(fhat, col=3)
points(c(0.5, 1), predict(fhat, x=c(0.5, 1)))
## large data example on non-default grid
## 151 x 151 grid = [-5,-4.933,..,5] x [-5,-4.933,..,5]
set.seed(8192)
x <- rmvnorm.mixt(10000, mus=c(0,0), Sigmas=invvech(c(1,0.8,1)))
fhat <- kde(x=x, binned=TRUE, compute.cont=TRUE, xmin=c(-5,-5), xmax=c(5,5), bgridsize=c(151,151))
plot(fhat)
## See other examples in ? plot.kde
# }
Run the code above in your browser using DataLab