dtnorm: Truncated Normal Distribution

Description Usage Arguments Value Examples

View source: R/RcppExports.R

Description

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

Usage

1
2
3
4
5
dtnorm(x, mean, sd, lower, upper, log = FALSE)

rtnorm(n, mean, sd, lower, upper)

ptnorm(q, mean, sd, lower, upper, lt = TRUE, log = FALSE)

Arguments

x, q

vector of quantiles;

mean

mean (must be scalar).

sd

standard deviation (must be scalar).

lower

lower truncation value (must be scalar).

upper

upper truncation value (must be scalar).

log

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## 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(-50, 10, length.out = 1e3)
mean <- 0
sd <- 1
lower <- 0
upper <- 5
dat1 <- ptnorm(x, 0, 1, 0, 5, log = TRUE)

ggdmc documentation built on Sept. 2, 2018, 1:03 a.m.