Learn R Programming

RTMBdist (version 0.1.0)

truncnorm: Truncated normal distribution

Description

Density, distribution function, quantile function, and random generation for the truncated normal distribution.

Usage

dtruncnorm(x, mean = 0, sd = 1, min = -Inf, max = Inf, log = FALSE)

ptruncnorm(q, mean = 0, sd = 1, min = -Inf, max = Inf, lower.tail = TRUE, log.p = FALSE)

qtruncnorm(p, mean = 0, sd = 1, min = -Inf, max = Inf, lower.tail = TRUE, log.p = FALSE)

rtruncnorm(n, mean = 0, sd = 1, min = -Inf, max = Inf)

Value

dtruncnorm gives the density, ptruncnorm gives the distribution function, qtruncnorm gives the quantile function, and rtruncnorm generates random deviates.

Arguments

x, q

vector of quantiles

mean

mean parameter, must be positive.

sd

standard deviation parameter, must be positive.

min, max

truncation bounds.

log, log.p

logical; if TRUE, probabilities/ densities \(p\) are returned as \(\log(p)\).

lower.tail

logical; if TRUE, probabilities are \(P[X \le x]\), otherwise, \(P[X > x]\).

p

vector of probabilities

n

number of random values to return.

Details

This implementation of dtruncnorm allows for automatic differentiation with RTMB.

Examples

Run this code
x <- rtruncnorm(1, mean = 2, sd = 2, min = -1, max = 5)
d <- dtruncnorm(x, mean = 2, sd = 2, min = -1, max = 5)
p <- ptruncnorm(x, mean = 2, sd = 2, min = -1, max = 5)
q <- qtruncnorm(p, mean = 2, sd = 2, min = -1, max = 5)

Run the code above in your browser using DataLab