The function logdensity_fft
computes kernel density estimates (KDE) of strictly positive distributions by performing the KDE via fast fourier transform utilizing the fft
function. The syntax and function structure is largely borrowed from the function density
in package stats.
logdensity_fft(x, bw = "nrd0", adjust = 1, kernel = "gaussian",
weights = NULL, n = 512, from, to, cut = log(3), na.rm = FALSE)
the data from which the estimate is to be computed.
the smoothing bandwidth to be used. Can also be can also be a character string giving a rule to choose the bandwidth. Like density
defaults to "nrd0". All options in help(bw.nrd)
are available as well as "bw.logCV"
and "bw.logG"
.
the bandwidth used is actually adjust*bw
.
a character string giving the smoothing kernel to be used. Choose from "gaussian", "epanechnikov", "triangular", "uniform", "laplace" and "logistic". Default value is "gaussian".
numeric vector of non-negative observation weights of the same length as x
.
the number of equally spaced points at which the density is to be estimated. Note that these are equally spaced in the log domain for logdensity_fft
, and thus on a log scale when transformed back to the original domain.
the left and right-most points of the grid at which the density is to be estimated; the defaults are cut * bw outside of range(x).
by default, the values of from and to are cut bandwidths beyond the extremes of the data
logical; if TRUE, missing values are removed from x. If FALSE any missing values cause an error.
An object with class "density". See help(density)
for details.
Charpentier, A., & Flachaire, E. (2015). Log-transform kernel density estimation of income distribution. L'Actualite economique, 91(1-2), 141-159.
Cooley, J. W., & Tukey, J. W. (1965). An algorithm for the machine calculation of complex Fourier series. Mathematics of computation, 19(90), 297-301.
Wand, M. P., Marron, J. S., & Ruppert, D. (1991). Transformations in density estimation. Journal of the American Statistical Association, 86(414), 343-353.
density
, plot.density
, logdensity
, bw.nrd
, bw.logCV
, bw.logG
.
# NOT RUN {
logdensity_fft(abs(rnorm(100)), from =0.01, to= 2.5, kernel = 'logistic')
# }
Run the code above in your browser using DataLab