dtrunc: Density, distribution function, quantile function and random...

Description Usage Arguments Details Examples

View source: R/dtrunc.R

Description

These functions compute the density function defined by the spec argument for the vector of quantile values in x. The random variable is truncated to be in the interval ( a, b )

Usage

1
2
3
4
5
6
7
8
9
dtrunc(x, spec, a = -Inf, b = Inf, params = NULL, ...)

ptrunc(q, spec, a = -Inf, b = Inf, params = NULL, ...)

qtrunc(p, spec, a = -Inf, b = Inf, params = NULL, ...)

rtrunc(n, spec, a = -Inf, b = Inf, params = NULL, ...)

vartrunc(spec, a = -Inf, b = Inf, params = NULL, ...)

Arguments

x, q

A numeric vector of quantiles

spec

A character vector for the name of the distribution (e.g., "norm" or "pois")

a

The minimum value allowed in the distribution (exclusive).

b

The maximum value allowed in the distribution (exclusive).

params

A list of distribution parameter name/value pairs

...

Distribution parameter arguments. Only used if 'params' is NULL.

p

A vector of probabilities

n

number of observations.

Details

The rational for having two different ways to pass the distribution parameters is that the truncdist package originally passed parameters via the '...' argument, but some distributions use x,p,q,n,a, or b as parameter names and that causes issues (e.g. the hypergeometric distribution has an 'n' parameter). Therefore to maintain backwards compatability as well as handle the hypergeometric distribution, two methods exist.

Examples

 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
# All of these are identical calculations
dpois(  2, lambda=3 )
dtrunc( 2, 'pois', lambda=3)
dtrunc( 2, 'pois', params=list(lambda=3) )

dpois(  2, lambda=3 )
dtrunc(2, 'pois', lambda=3)
ppois(  2, lambda=3 )
ptrunc( 2, 'pois', lambda=3)
qpois(  .8, lambda=3 )
qtrunc( .8, 'pois', lambda=3)

# Now consider the Poisson with the zero values removed
dtrunc( 2, 'pois', a=0, lambda=3 )
dtrunc( 2, 'pois', a=0, params=list(lambda=3) )
ptrunc( 2, 'pois', a=0, lambda=3 )
ptrunc( 2, 'pois', a=0, params=list(lambda=3) )
qtrunc( c(.8,.9), 'pois', a=0, lambda=3 )
qtrunc( .8, 'pois', a=0, params=list(lambda=3) )
rtrunc( 10, 'pois', a=0, lambda=2 )
rtrunc( 10, 'pois', a=0, params=list(lambda=2) )

# Now to look at the hypergeometric
dhyper( 3, m=5, n=10, k=4 )
dtrunc( 3, 'hyper', m=5, n=10, k=4 )
dtrunc( 3, 'hyper', params=list(m=5, n=10, k=4) )
# rtrunc( 10, 'hyper', m=5, n=10, k=4 ) # error!
rtrunc( 10, 'hyper', params=list(m=5, n=10, k=4) )

dereksonderegger/truncdist documentation built on May 17, 2019, 1:13 a.m.