Learn R Programming

truncgof (version 0.6-0)

cdens: Build a conditional density function

Description

For a given distribution function cdens builds a conditional density function with respect to a relevant treshold.

Usage

cdens(distn, H)

Arguments

distn
character string naming the distribution function for which the conditional density is to be built
H
a treshold value

Value

The conditional density of the specified density function with arguments x, the relevant parameters and the treshold H predefined as the value of cdens' argument H. x can be a numeric value or numeric vector, but must be greater or equal to H.

Details

For $x >= H$ the conditional density $f*$ of a density $f$ is given by $$f^\ast_\theta(x) = f(x|x \geq H)=\frac{f_\theta(x)}{1-F_\theta(H)},$$ with $theta$ the parameters of the distribution, $F$ the cumulative distribution function and $H$ the treshhold value. For $x < H$, $f*$ disappear.

See Also

density functions, e.g. dlnorm, dgamma, etc.

Examples

Run this code
require(MASS)
set.seed(123)
treshold <- 10
xc  <- rlnorm(100, 2, 2)   # complete sample
xt <- xc[xc >= treshold]   # left truncated sample

clnorm <- cdens("plnorm", H = treshold)
args(clnorm)

# mle fitting based on the complete sample
start <- list(meanlog = 2, sdlog = 1)
fitdistr(xc, dlnorm, start = start)

# mle fitting based on the truncated sample
fitdistr(xt, clnorm, start = start)

# in contrast
fitdistr(xt, dlnorm, start = start)

Run the code above in your browser using DataLab