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)See also
Other simulation helpers:
Simulator,
correlated_regressors(),
ddirichlet_cpp(),
dmixnorm_cpp(),
dmvnorm_cpp(),
dwishart_cpp(),
gaussian_tv(),
simulate_markov_chain()
Examples
x <- c(0, 0)
mean <- c(0, 0)
Sigma <- diag(2)
# compute density
dmvnorm(x = x, mean = mean, Sigma = Sigma)
#> [1] 0.1591549
dmvnorm(x = x, mean = mean, Sigma = Sigma, log = TRUE)
#> [1] -1.837877
# sample
rmvnorm(n = 3, mean = mean, Sigma = Sigma)
#> [,1] [,2]
#> [1,] -2.1739333 1.5957503
#> [2,] 1.4067293 -0.3436295
#> [3,] -0.2064392 0.5327578
rmvnorm(mean = mean, Sigma = Sigma, log = TRUE)
#> [1] 1.530003 4.872182
