dpqr: Generate the d/p/q/r family for an arbitrary distribution

View source: R/dpqr.R

dpqrR Documentation

Generate the d/p/q/r family for an arbitrary distribution

Description

Generates the standard d, p, q, and r functions associated with an arbitrary one-dimensional probability density function, analogous to dnorm/pnorm/qnorm/rnorm and related families.

Usage

dpqr(fun, min, max)

Arguments

fun

A non-negative, vectorised function proportional to a probability density. It does not need to be normalised.

min, max

Lower and upper bounds of the support. The density is assumed to be zero outside this interval.

Value

Returns a list with the following functions:

d(x)

Probability density function (PDF), i.e. a normalised version of fun on the domain [min,max].

p(x)

Cumulative distribution function (CDF).

q(p)

Quantile function.

r(n)

Generates n random samples from the distribution.

Author(s)

Danail Obreschkow

See Also

rng, contourlevel

Examples

f = function(x) sin(x)
dist = dpqr(f, 0, pi)

x = dist$r(1000)
hist(x, probability = TRUE)
curve(dist$d(x), add = TRUE)


cooltools documentation built on Sept. 11, 2026, 5:06 p.m.