kernel_density_1d: 1d dernel density estimate.

Description Usage Arguments Details Examples

Description

1d dernel density estimate.

Usage

1
2
kernel_density_1d(x, weight, bandwidth="bw.nrd",
    kernel="gaussian", n=512, na.rm=FALSE)

Arguments

x

a numeric vector of positions

weight

NULL or a numeric vector providing weights for each observation

bandwidth

the banwidth. Either a numeric vector, or function that computes the binwidth given the data.

kernel

the kernel used for smoothing. Defaults to "gaussian". See density for full list

n

number of points to use for interpolation

na.rm

If TRUE missing values will be silently removed, otherwise they will be removed with a warning.

Details

Offers less flexibility than local_density_1d but can be much faster and has no external dependencies.

1d case uses linear interpolation on the results of density. 2d case uses a modified version of kde2d.

Examples

1
2
3
4
5
data(baseball, package = "plyr")
dens <- kernel_density_1d(baseball$g)
plot(dens)
plot(kernel_density_1d(baseball$g, bandwidth = 4))
plot(kernel_density_1d(baseball$g, bandwidth = 1))

hadley/densityvis documentation built on May 17, 2019, 9:56 a.m.