knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

densdpqr

Lifecycle: experimental

The goal of densdpqr is to make a minimal package for applying the[dpqr]*() distribution functions (e.g. dnorm(), pnorm(), qnorm(), rnorm()), for any arbitrary output from the stats::density() function.

Example

  1. Call stats::density() on your data to get an estimate for a density function.
  2. Call densdpr::smooth_density() to smooth your density function and create the needed distribution functions for ddens(), pdens(), qdens() and rdens().
  3. Pass output from smooth_density() and other required parameter into [dpqr]dens() function(s).
# devtools::install_github("brshallo/densdpqr")
library(densdpqr)

set.seed(123)
data <- rnorm(10000)
dens <- density(data)
sdens <- smooth_density(dens)

ddens(sdens, 2)
pdens(sdens, 2)
qdens(sdens, 0.977)
rdens(sdens, 10L)

Problems

Inspiration & Other Resources

Thank you to spatstat authors as well as William Huber whose comment on How to find probability density function from density function... inspired the approach in densdpqr.

In most simple univariate cases could just use the logspline::[dpqr]logspline() functions which are set-up the same way as densdpqr::[dpqr]dens() but without the same [Problems]. The advantages with densdpqr are it allows the use of the base stats::density() function, it has fewer dependencies, and is likely faster.



brshallo/densdpqr documentation built on Dec. 19, 2021, 11:49 a.m.