hnorm {usefr}R Documentation

Half-Normal distribution

Description

Probability density function (PDF), cummulative density function (CDF), quantile function and random generation for the Half-normal (hnorm) distribution.

Usage

dhnorm(x, theta = 1, log = FALSE)

phnorm(q, theta = 1, lower.tail = TRUE, log.p = FALSE)

qhnorm(p, theta = 1, sigma = NULL, lower.tail = TRUE,
  log.p = FALSE)

rhnorm(n, theta = 1)

theta2sigma(theta)

sigma2theta(sigma)

Arguments

theta

numerical parameter, strictly positive (default 1).

q

numeric vector

lower.tail

logical; if TRUE (default), probabilities are P[X<=x], otherwise, P[X > x]

log.p

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

sigma

Standart deviation of the normal distribution. Here, σ = √ π/(θ√ 2)

n

number of observations

Details

An alternative parametrization to avoid issues when sigma is near zero is applied by using a scaled precision (inverse of the variance) obtained by setting θ=sqrt(π)/σ*sqrt(2). Details about these functions can be found in Wikipedia and in MathWorld. Notice that θ = 1 means σ = √ π/√ 2.

Value

Half-normal PDF values (theta parameter) for dhnorm, Half-normal probability for phnorm, quantiles or Half-normal random generated values for rhnorm.

Author(s)

Robersy Sanchez (https://genomaths.com).

Examples

set.seed(123) # set a seed
sigma = 1.2
theta = sigma2theta(sigma)
x <- rhnorm(n = 1e5, theta = theta)
hist(x, 100, freq = FALSE)
curve(dhnorm(x, theta = theta), col = "red", add = TRUE)

#' # Checking the function outputs for the logarithms of probabilities
x <- rhalfnorm(n = 10, theta = sigma2theta(2))
x1 <- phnorm(x, theta = sigma2theta(2), log = TRUE)
x2 <- phnorm(x, theta = sigma2theta(2), log = FALSE)
all(round(x1, 8) == round(log(x2), 8))

x3 <- dhnorm(x, theta = sigma2theta(2), log = TRUE)
x4 <- dhnorm(x, theta = sigma2theta(2), log = FALSE)
all(round(x3, 8) == round(log(x4), 8))

[Package usefr version 0.1.0 ]