opt_lin_bw {cylcop} | R Documentation |
Find the Optimal Bandwidth for a Linear Kernel Density Estimate
Description
This function wraps stats::bw.ucv()
and stats::bw.nrd()
of the 'stats'
package, simplifying their inputs. For more control,
these 'stats' functions could be used directly.
Usage
opt_lin_bw(x, method = c("cv", "nrd"))
Arguments
x |
|
method |
character string describing the method used to find
the optimal bandwidth. Either |
Details
The normal reference distribution (nrd
) method involves
matching a normal distribution to the data using an empirical measure of spread.
The optimal bandwidth for that normal distribution can then be exactly calculated
by minimizing the mean integrated square error.
method="cv"
finds the optimal bandwidth using unbiased cross-validation.
Value
A numeric value, the optimized bandwidth.
See Also
stats::bw.ucv()
,
stats::bw.nrd()
opt_lin_bw()
.
Examples
require(graphics)
set.seed(123)
n <- 1000
x <- rweibull(n, shape = 10)
bw1 <- opt_lin_bw(x = x, method="nrd")
bw2 <- opt_lin_bw(x = x, method="cv")
dens1 <- fit_steplength(x = x, parametric = FALSE, bandwidth = bw1)
dens2 <- fit_steplength(x = x, parametric = FALSE, bandwidth = bw2)
true_dens <- dweibull(seq(0,max(x),length.out = 200), shape = 10)
plot(seq(0,max(x),length.out = 200), true_dens, type = "l")
lines(dens1$x, dens1$y, col = "red")
lines(dens2$x, dens2$y, col = "green")
[Package cylcop version 0.2.0 Index]