p_fun: Kernel Distribution Functions

Description Usage Arguments Value Examples

View source: R/distribution_functions.R

Description

A set of functions to generate p-, d-, q- or r-prefix functions, as are available for standard probability distributions, but for distributions defined by a kernel density estimate.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
p_fun(x, ...)

## S3 method for class 'kde'
p_fun(x, ...)

## S3 method for class 'numeric'
p_fun(x, ...)

d_fun(x, ...)

## S3 method for class 'kde'
d_fun(x, ...)

## S3 method for class 'numeric'
d_fun(x, ...)

q_fun(x, ...)

## S3 method for class 'kde'
q_fun(x, ...)

## S3 method for class 'numeric'
q_fun(x, ...)

r_fun(x, ...)

## S3 method for class 'kde'
r_fun(x, ...)

## S3 method for class 'numeric'
r_fun(x, ...)

## S3 method for class 'density'
p_fun(x, ...)

## S3 method for class 'density'
d_fun(x, ...)

## S3 method for class 'density'
q_fun(x, ...)

## S3 method for class 'density'
r_fun(x, ...)

Arguments

x

Either a kde object or a numeric vector from which a kde object can be generated.

...

Additional arguments forwarded to the kde function.

Value

An R function for probabilities, densities, quantiles or simulated samples, as indicated by the prefix.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
set.seed(1234)
x <- rnorm(10000)
kx <- kde(x)
pkx <- p_fun(kx)
dkx <- d_fun(kx)
qkx <- q_fun(kx)
rkx <- r_fun(kx)
rbind(quantile(x, 0:10/10), qkx(0:10/10))
pkx(qkx(1:9/10))
    par(mar = c(3, 3, 1, 1) + 0.1, las = 1, mgp = c(1.5, 0.5, 0),
        cex.axis = 0.7, cex.lab = 0.8, tck = -0.015)
curve(dkx, xlim = qkx(0:1), col = 2)
curve(dnorm, add = TRUE)
grid()
rx <- rkx(x)
qqplot(x, rx, pch = ".")
abline(0, 1, col=2)
grid()
rm(x, rx)

BillVenables/kdeR documentation built on April 12, 2021, 1:51 p.m.