truncatedDistribution {trdist}R Documentation

Truncated Distributions

Description

Truncated probability density function, truncated cumulative density function, inverse truncated cumulative density function, and random variates from a truncated distribution.

Usage

dtrunc(x, distr, ..., low = -Inf, high = Inf, log = FALSE)

ptrunc(q, distr, ..., low = -Inf, high = Inf, lower.tail = TRUE, log.p = FALSE)

qtrunc(p, distr, ..., low = -Inf, high = Inf, lower.tail = TRUE, log.p = FALSE)

rtrunc(n, distr, ..., low = -Inf, high = Inf)

Arguments

x

Vector of quantiles.

distr

Character value specifying the desired probability distribution.

...

Additional arguments passed to the non-truncated distribution functions.

low

Numeric value specifying the lower truncation bound.

high

Numeric value specifying the upper truncation bound.

log

Logical; if TRUE, log densities are returned.

q

Vector of quantiles.

lower.tail

Logical; if TRUE (default), probabilities are P(X <= x) otherwise, P(X > x).

log.p

Currently ignored.

p

Vector of probabilities.

n

A positive integer specifying the desired number of random variates.

Details

The non truncated distribution functions are assumed to be available. For example if the normal distribution is desired then used distr='norm', the functions then look for 'qnorm', 'pnorm', etc.

The truncation interval is (low, high], which only matters for discrete distribution.

The random variates are produced using the direct method (see Casella and Berger 2002).

Value

dtrunc returns a vector of densities.

ptrunc returns a vector of probabilities.

qtrunc returns a vector of quantiles.

rtrunc returns a vector of random variates.

References

G. Casella and R. L. Berger. Statistical inference. Vol. 2. Duxbury Pacific Grove, CA, 2002.

Examples


## dtrunc
# not truncted
dnorm(5,mean=5)
dtrunc(x=5,distr='norm',mean=5)
# truncated
dtrunc(x=5,distr='norm',mean=5,low=4, high=5.5)



## ptrunc
#not truncated
pgamma(2, shape=3, rate=2)
ptrunc(2, distr = 'gamma', shape=3, rate=2)
# truncated
ptrunc(2, distr = 'gamma', shape=3, rate=2, low=1, high=5)

## upper tail
# not truncated
pgamma(2, shape=3, rate=2,lower.tail=FALSE)
ptrunc(2, distr='gamma', shape=3, rate=2, lower.tail=FALSE)
# truncated
ptrunc(2, distr='gamma', shape=3, rate=2, low=1, high=5, lower.tail=FALSE)



## qtrunc
#not truncated
qnorm(p=.975)
qtrunc(p=.975,distr='norm')
# truncted
qtrunc(p=.975,distr='norm', low=0, high=1)

## upper tail
# not truncted
qnorm(p=.975,lower.tail=FALSE)
qtrunc(p=.975, distr='norm', lower.tail=FALSE)
# truncated
qtrunc(p=.975, distr='norm', low=0, high=1, lower.tail=FALSE)

## rtrunc
rtrunc(n=5, distr = 'gamma', shape=3, rate=2, low=2, high=5)

[Package trdist version 1.0.1 Index]