Skip to contents

Modification of ggplot2::stat_density() for kernel density estimates using a combination of the Botev (2010) bandwidth selector and the Abramson (1982) adaptive kernel bandwidth modifier.

Usage

getkde(
  x,
  from = NA,
  to = NA,
  bw = NA,
  adaptive = TRUE,
  log = FALSE,
  n = 512,
  weights = NULL,
  ...
)

Arguments

x

numeric vector. Ages

from

numeric. minimum age of the time axis. If NULL, this is set automatically

to

numeric. maximum age of the time axis. If NULL, this is set automatically

bw

numeric. the bandwidth of the KDE. If NULL, bw will be calculated automatically using the algorithm by Botev et al. (2010).

adaptive

logical flag controlling if the adaptive KDE modifier of Abramson (1982) is used

log

logical. transform the ages to a log scale if TRUE

n

integer. horizontal resolution (i.e., the number of segments) of the density estimate.

weights

numeric vector of non-negative observation weights, hence of same length as x. The default NULL is equivalent to weights = rep(1/nx, nx) where nx is the length of (the finite entries of) x[]. If na.rm = TRUE and there are NA's in x, they and the corresponding weights are removed before computations. In that case, when the original weights have summed to one, they are re-scaled to keep doing so. Will be ignored is adaptive is TRUE.

...

optional arguments to be passed on to R's density function.