tidyst_kdcde {eks}R Documentation

Tidy and geospatial kernel deconvolved density estimates

Description

Tidy and geospatial versions of kernel deconvolved density estimates for 1- and 2-dimensional data.

Usage

tidy_kdcde(data, ...)
st_kdcde(x,...)

Arguments

data

data frame/tibble of data values

x

sf object with point geometry

...

other parameters in ks::kdcde function

Details

A deconvolved kernel density estimate is a modification of the standard density estimate for data observed with error. This version is based on a weighted kernel density estimate. For details of the computation of the kernel deconvolved density estimate and the bandwidth selector procedure, see ?ks::kdcde.

Value

The output from *_kdcde have the same structure as the standard kernel density estimate from *_kde.

Examples

## tidy 2-d deconvolved density estimate
data(air, package="ks")
air <- na.omit(air[, c("time","co2","pm10")])
air <- dplyr::filter(air, time=="20:00")
air <- dplyr::select(air, co2, pm10)
## for details on computation of Sigma.air, see ?ks::kdcde
Sigma.air <- diag(c(6705.765, 957.664)) 

t1 <- tidy_kde(air)
t2 <- tidy_kdcde(air, Sigma=Sigma.air, reg=0.00021)
t3 <- dplyr::bind_rows(dplyr::mutate(t1, group=1L), dplyr::mutate(t2, group=2L))
t3$group <- factor(t3$group, label=c("Standard KDE","Deconvolved KDE"))
t3 <- as_tidy_ks(t3)

## deconvolved estimate is more clearly bimodal than standard KDE 
gt <- ggplot2::ggplot(t3, ggplot2::aes(x=co2,y=pm10)) 
gt + geom_contour_filled_ks(colour=1) + 
    colorspace::scale_fill_discrete_sequential() +
    ggplot2::facet_wrap(~group) 

[Package eks version 1.0.4 Index]