akde: This is a wrapper for the 'akj' adaptive kernel density...

Description Usage Arguments Details Value Examples

View source: R/akde.R

Description

This function calls quantreg::akj and formats its return value as a list with x & y elements, consistent with other kernel density estimation functions. It also provides arguments for defining the x-grid that the PDF is estimated on.

Usage

1
2
akde(x, n = 2 * length(x), extend = 3 * stats::bw.nrd(x),
  min.x = min(x) - extend, max.x = max(x) + extend)

Arguments

x

The data to estimate a PDF for.

n

The size of the x-grid to estimate the density on. Defaults to twice the length of x, which is the default used by akj.

extend

The distance beyond the range of the data to extend the x-grid. Defaults to 3 times the bandwidth calculated by bw.nrd, which is close to the default values used by both density and bkde.

min.x

The minimum value of x to compute the density on. Defaults to the minimum data value minus extend.

max.x

The maximum value of x to compute the density on. Defaults to the maximum data value plus extend.

Details

The documentation for akj says that the data values are assumed to be sorted. Although it doesn't appear to matter in practice, this function sorts them just in case.

Value

A list with following components:

x: the x-values where the density is estimated.

y: the estimated density values at each x.

Examples

1
2
3
4
5
6
7
library(KernSmooth)
set.seed(222)
x <- rgamma(300, shape=3, scale=2)
d <- namelist(density, bkde, akde)
p <- lapply(d, do.call, list(x=x))
mplot(p)
legend("topright", names(d), lty=seq(3), col=seq(3))

sethmcg/climod documentation built on Nov. 19, 2021, 11:12 p.m.