*! version 1.0.0 16Jul2024

Title

halfnorm dist -- half-normal distribution functions

Syntax

The half-normal density distribution function using data stored in memory

halfnormden newvarname [if] [in] , x(varname) [ theta(varname) mean(varname) sd(varname) ]

Immediate form of halfnormden

halfnormdeni x [, theta(#) mean(#) sd(#) ]

where x is the value to be evaluated

The inverse cumulative standard half-normal distribution function using data stored in memory

halfinvnorm newvarname [if] [in] , p(varname) [ theta(varname) mean(varname) sd(varname) ]

Immediate form of halfinvnorm

halfinvnormi p [, theta(#) mean(#) sd(#) ]

where p represents the significance level

The cumulative standard half-normal distribution using data stored in memory

halfnorm newvarname [if] [in] , z(varname) [ theta(varname) mean(varname) sd(varname) ]

Immediate form of halfnorm

halfnormi z [, theta(#) mean(#) sd(#) ]

where z represents the z score

halfnormden
x(varname) variable containing the x values to be evaluated; required

theta(varname) variable containing the theta parameter values; default is sqrt(pi/2)

mean(varname) variable containing the distribution means; default is means set at 0

sd(varname) variable containing the distribution standard deviations; default is sd set at 1

halfinvnorm
p(varname) variable containing the p values; required

theta(varname) variable containing the theta parameter values; default is sqrt(pi/2)

mean(varname) variable containing the distribution means; default is means set at 0

sd(varname) variable containing the distribution standard deviations; default is sd set at 1

halfnorm
z(varname) variable containing the z scores; required

theta(varname) variable containing the theta parameter values; default is sqrt(pi/2)

mean(varname) variable containing the distribution means; default is means set at 0

sd(varname) variable containing the distribution standard deviations; default is sd set at 1

halfnormdeni, halfinvnormi, halfnormi
theta(#) specify the theta parameter value; default is sqrt(pi/2)

mean(#) specify the mean of the distribution; default is mean(0)

sd(#) specify the standard deviation of the distribution; default is sd(1)

Description

halfnormden computes the half-normal density distribution function, halfinvnorm computes the inverse cumulative standard half-normal distribution function,
and halfnorm computes the cumulative standard half-normal distribution. The half-normal distribution is a Normal distribution truncated to only have a nonzero
density for values to the right of the peak. In the half-normal distribution, the parameter theta is related to the standard deviation (sd) of the corresponding normal
distribution by the equation theta = sqrt(pi/2)/sd. The default theta is sqrt(pi/2) which corresponds to sd = 1.
(see https://en.wikipedia.org/wiki/Half-normal_distribution).

halfnormdeni, halfinvnormi and halfnormi are the immediate forms of halfnormden, invnorm and normd, respectively; see immed.

Examples

halfnormden using data stored in memory

set-up

. clear

. set obs 501

. gen x = 0 + (_n - 1) * .01

compute half-normal density distribution using defaults of mean = 0, sd = 1 and graph results

. halfnormden halfnormden, x(x)

. line halfnormden x

compute normal density distribution for comparison and graph results

. gen x2 = -5 + (_n - 1) * .02

. gen normden = normalden(x2)

. tw(line halfnormden x)(line normden x2)

halfnormdeni to specify values manually

using defaults; mean = 0 and sd = 1

. halfnormdeni 0.10

set mean = 2 and sd = 4

. halfnormdeni 0.10, m(2) s(4)

halfinvnorm using data stored in memory

set-up

. clear

. set obs 501

. gen p = 0 + (_n - 1) * .002

compute inverse half-normal density distribution using defaults of mean = 0, sd = 1 and graph results

. halfinvnorm halfinvnorm, p(p)

. line halfinvnorm p

generate values specifying means and sds

. generate mean = 2

. generate sd = 4

. halfinvnorm halfinvnorm2, p(p) mean(mean) sd(sd)

halfinvnormi to specify values manually

using defaults; mean = 0 and sd = 1

. halfinvnormi 0.50

specifying values for mean and sd

. halfinvnormi 0.50, m(2) s(4)

halfnorm using data stored in memory

set-up

. clear

. set obs 501

. gen z = 0 + (_n - 1) * .01

compute cumulative standard half-normal distribution using defaults of mean = 0, sd = 1 and graph results

. halfnorm halfnorm, z(z)

. line halfnorm z

compute cumulative standard normal distribution for comparison and graph results

. gen z2 = -5 + (_n - 1) * .02

. gen normal = normal(z2)

. tw(line halfnorm z)(line normal z2)

halfnormi to specify values manually

using defaults; mean = 0 and sd = 1

. halfnormi 1.2

specifying values for mean and sd

. halfnormi 1.2, m(0) s(4)

Stored results

halfnormdeni, halfinvnormi and halfnormi store the following in r(), respectively:

Scalars

r(halfnormden) half-normal density distribution

r(halfinvnorm) inverse cumulative standard half-normal distribution

r(halfnorm) cumulative standard half-normal distribution

Citation of halfnorm dist

halfnorm dist is not an official Stata command. It is a free contribution
to the research community, like a paper. Please cite it as such:

Linden, Ariel (2024). HALFNORM DIST: Stata module for computing half-normal distribution functions

Author

Ariel Linden

President, Linden Consulting Group, LLC

alinden@lindenconsulting.org

Acknowledgments

I wish to thank John Moran for advocating that I write this package.

Also see

Online: normalden(), invnormal(), normal(), norm dist (if installed)