Description Usage Arguments Value References See Also Examples
logdensity.fit
is intended to be called from within
logdensity
, after performing basic argument verification. Use
caution when calling logdensity.fit
directly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | logdensity(
data,
x,
h,
g,
dg,
m = "epanechnikov",
minx = -Inf,
maxx = Inf,
S = 1,
logf = TRUE,
mc.cores = 1L,
...
)
logdensity.fit(data, x, h, g, dg, m, minx, maxx, logf, exact, ...)
|
data |
numeric vector of observations |
x |
points at which to estimate (if shorter than h, recycled to length
of h). |
h |
bandwidth (if shorter than x, recycled to the length of x). |
g |
function of |
dg |
function that evaluates derivative of |
m |
kernel function used to compute the density. Can be a function,
symbol, or character string that matches the name of a function or one of the
kernels allowed in evalkernel. If |
minx |
lower bound of support of |
maxx |
upper bound of support of |
S |
degree of polynomial expansion of log-density to be used with
default |
logf |
logical indicating whether the log-density should be compute, in addition to its derivative(s). |
mc.cores |
integer number of cores to use with |
... |
Further arguments supplied to |
exact |
logical indicating whether an exact solution should be used (if available) or numerical integration. Exact solution currently only available with epanechnikov kernel and local linear approximation. |
logdensity
returns an object of class logdensity
which inherits from matrix
.
The S+1
by length(x)
matrix of estimated log-densities (NA
unless logf
is TRUE
) and derivatives has the following additional attributes:
x
vector of points at which the estimates were computed,
n
number of non-missing observations used in estimation,
h
bandwidth(s) used,
call
matched call
logdensity.fit
returns a numeric vector containing the log-density (if logf == TRUE
) and its derivatives.
Pinkse, J. and Schurter, K. (2020) "Estimates of derivatives of (log) densities and related objects."
mapply
, mcmapply
, integrate
, bellpoly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | dat <- rchisq(n = 100, df = 2)
x <- seq(from = 0, to = 2, length.out = 20)
## fixed bandwidth
ld <- logdensity(data = dat, x = x, h = 0.5, minx = 0, S = 1)
print(ld)
plot(ld)
## variable bandwidth
h <- pmax(1-x, 0.5)
ld <- logdensity(data = dat, x = x, h = h, minx = 0, S = 2)
ld
plot(ld)
## Faa di Bruno's formula for the density and its derivatives
deriv <- 0L # integer between 0 and S (=2 for most recent estimation)
exp(ld[1, ]) * colSums(bellpoly(ld[-1, ], n = deriv))
### verify formula for deriv = 0, 1, and 2
exp(ld[1, ]) * colSums(bellpoly(ld[-1, ], n = 0L)) # density (0th derivative)
exp(ld[1, ]) # equivalent
exp(ld[1, ]) * colSums(bellpoly(ld[-1, ], n = 1L)) # 1st derivative of density
exp(ld[1, ]) * ld[2,] # equivalent
exp(ld[1, ]) * colSums(bellpoly(ld[-1, ], n = 2L)) # 2nd derivative of density
exp(ld[1, ]) * (ld[2,]^2 + ld[3, ]) # equivalent
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.