dtnorm: Truncated normal distribution

View source: R/tnorm.R

dtnorm_cppR Documentation

Truncated normal distribution

Description

The function dtnorm() computes the density of a truncated normal distribution.

The function rtnorm() samples from a truncated normal distribution.

The function dttnorm() and rttnorm() compute the density and sample from a two-sided truncated normal distribution, respectively.

The functions with suffix ⁠_cpp⁠ perform no input checks, hence are faster.

Usage

dtnorm_cpp(x, mean, sd, point, above, log = FALSE)

dttnorm_cpp(x, mean, sd, lower, upper, log = FALSE)

rtnorm_cpp(mean, sd, point, above, log = FALSE)

rttnorm_cpp(mean, sd, lower, upper, log = FALSE)

dtnorm(x, mean, sd, point, above, log = FALSE)

dttnorm(x, mean, sd, lower, upper, log = FALSE)

rtnorm(mean, sd, point, above, log = FALSE)

rttnorm(mean, sd, lower, upper, log = FALSE)

Arguments

x

[numeric(1)]
A quantile.

mean

[numeric(1)]
The mean.

sd

[numeric(1)]
The non-negative standard deviation.

point, lower, upper

[numeric(1)]
The truncation point.

above

[logical(1)]
Truncate from above? Else, from below.

log

[logical(1)]
Return the logarithm of the density value?

Value

For dtnorm() and dttnorm(): The density value.

For rtnorm() and rttnorm(): The random draw

See Also

Other simulation helpers: correlated_regressors(), ddirichlet_cpp(), dmvnorm_cpp(), dwishart_cpp(), simulate_markov_chain()

Examples

x <- c(0, 0)
mean <- c(0, 0)
Sigma <- diag(2)

# compute density
dmvnorm(x = x, mean = mean, Sigma = Sigma)
dmvnorm(x = x, mean = mean, Sigma = Sigma, log = TRUE)

# sample
rmvnorm(n = 3, mean = mean, Sigma = Sigma)
rmvnorm(mean = mean, Sigma = Sigma, log = TRUE)

oeli documentation built on Oct. 16, 2024, 5:08 p.m.