dtnorm {ggdmc}R Documentation

Truncated Normal Distribution

Description

Random number generation, probability density and cumulative density functions for truncated normal distribution.

Usage

dtnorm(x, p1, p2, lower, upper, lg = FALSE)

rtnorm(n, p1, p2, lower, upper)

ptnorm(q, p1, p2, lower, upper, lt = TRUE, lg = FALSE)

Arguments

x, q

vector of quantiles;

p1

mean (must be scalar).

p2

standard deviation (must be scalar).

lower

lower truncation value (must be scalar).

upper

upper truncation value (must be scalar).

lg

log probability. If TRUE (default is FALSE) probabilities p are given as log(p).

n

number of observations. n must be a scalar.

lt

lower tail. If TRUE (default) probabilities are P[X <= x], otherwise, P[X > x].

Value

a column vector.

Examples

## rtn example
dat1 <- rtnorm(1e5, 0, 1, 0, Inf)
hist(dat1, breaks = "fd", freq = FALSE, xlab = "",
     main = "Truncated normal distributions")

## dtn example
x <- seq(-5, 5, length.out = 1e3)
dat1 <- dtnorm(x, 0, 1, -2, 2, 0)
plot(x, dat1, type = "l", lwd = 2, xlab = "", ylab= "Density",
     main = "Truncated normal distributions")

## ptn example
x <- seq(-10, 10, length.out = 1e2)
mean <- 0
sd <- 1
lower <- 0
upper <- 5
dat1 <- ptnorm(x, 0, 1, 0, 5, lg = TRUE)

[Package ggdmc version 0.2.6.0 Index]