|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# Half-Normal |
| 22 | + |
| 23 | +> Half-normal distribution. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var halfnormal = require( '@stdlib/stats/base/dists/halfnormal' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### halfnormal |
| 34 | + |
| 35 | +Half-normal distribution. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var dist = halfnormal; |
| 39 | +// returns {...} |
| 40 | +``` |
| 41 | + |
| 42 | +The namespace contains the following distribution functions: |
| 43 | + |
| 44 | +<!-- <toc pattern="*+(cdf|pdf|mgf|quantile)*"> --> |
| 45 | + |
| 46 | +<div class="namespace-toc"> |
| 47 | + |
| 48 | +- <span class="signature">[`cdf( x, sigma )`][@stdlib/stats/base/dists/halfnormal/cdf]</span><span class="delimiter">: </span><span class="description">half-normal distribution cumulative distribution function.</span> |
| 49 | +- <span class="signature">[`logcdf( x, sigma )`][@stdlib/stats/base/dists/halfnormal/logcdf]</span><span class="delimiter">: </span><span class="description">evaluate the natural logarithm of the cumulative distribution function (CDF) for a half-normal distribution.</span> |
| 50 | +- <span class="signature">[`logpdf( x, sigma )`][@stdlib/stats/base/dists/halfnormal/logpdf]</span><span class="delimiter">: </span><span class="description">evaluate the natural logarithm of the probability density function (PDF) for a half-normal distribution.</span> |
| 51 | +- <span class="signature">[`mgf( t, sigma )`][@stdlib/stats/base/dists/halfnormal/mgf]</span><span class="delimiter">: </span><span class="description">half-normal distribution moment-generating function (MGF).</span> |
| 52 | +- <span class="signature">[`pdf( x, sigma )`][@stdlib/stats/base/dists/halfnormal/pdf]</span><span class="delimiter">: </span><span class="description">half-normal distribution probability density function (PDF).</span> |
| 53 | +- <span class="signature">[`quantile( p, sigma )`][@stdlib/stats/base/dists/halfnormal/quantile]</span><span class="delimiter">: </span><span class="description">half-normal distribution quantile function.</span> |
| 54 | + |
| 55 | +</div> |
| 56 | + |
| 57 | +<!-- </toc> --> |
| 58 | + |
| 59 | +The namespace contains the following functions for calculating distribution properties: |
| 60 | + |
| 61 | +<!-- <toc pattern="*+(entropy|kurtosis|mean|median|mode|skewness|stdev|variance)*"> --> |
| 62 | + |
| 63 | +<div class="namespace-toc"> |
| 64 | + |
| 65 | +- <span class="signature">[`entropy( sigma )`][@stdlib/stats/base/dists/halfnormal/entropy]</span><span class="delimiter">: </span><span class="description">half-normal distribution differential entropy.</span> |
| 66 | +- <span class="signature">[`kurtosis( sigma )`][@stdlib/stats/base/dists/halfnormal/kurtosis]</span><span class="delimiter">: </span><span class="description">half-normal distribution excess kurtosis.</span> |
| 67 | +- <span class="signature">[`mean( sigma )`][@stdlib/stats/base/dists/halfnormal/mean]</span><span class="delimiter">: </span><span class="description">half-normal distribution expected value.</span> |
| 68 | +- <span class="signature">[`median( sigma )`][@stdlib/stats/base/dists/halfnormal/median]</span><span class="delimiter">: </span><span class="description">half-normal distribution median.</span> |
| 69 | +- <span class="signature">[`mode( sigma )`][@stdlib/stats/base/dists/halfnormal/mode]</span><span class="delimiter">: </span><span class="description">half-normal distribution mode.</span> |
| 70 | +- <span class="signature">[`skewness( sigma )`][@stdlib/stats/base/dists/halfnormal/skewness]</span><span class="delimiter">: </span><span class="description">half-normal distribution skewness.</span> |
| 71 | +- <span class="signature">[`stdev( sigma )`][@stdlib/stats/base/dists/halfnormal/stdev]</span><span class="delimiter">: </span><span class="description">half-normal distribution standard deviation.</span> |
| 72 | +- <span class="signature">[`variance( sigma )`][@stdlib/stats/base/dists/halfnormal/variance]</span><span class="delimiter">: </span><span class="description">half-normal distribution variance.</span> |
| 73 | + |
| 74 | +</div> |
| 75 | + |
| 76 | +<!-- </toc> --> |
| 77 | + |
| 78 | +The namespace contains a constructor function for creating a [half-normal][halfnormal-distribution] distribution object. |
| 79 | + |
| 80 | +<!-- <toc pattern="*ctor*"> --> |
| 81 | + |
| 82 | +<div class="namespace-toc"> |
| 83 | + |
| 84 | +- <span class="signature">[`HalfNormal( [sigma] )`][@stdlib/stats/base/dists/halfnormal/ctor]</span><span class="delimiter">: </span><span class="description">half-normal distribution constructor.</span> |
| 85 | + |
| 86 | +</div> |
| 87 | + |
| 88 | +<!-- </toc> --> |
| 89 | + |
| 90 | +```javascript |
| 91 | +var HalfNormal = require( '@stdlib/stats/base/dists/halfnormal' ).HalfNormal; |
| 92 | + |
| 93 | +var dist = new HalfNormal( 2.0 ); |
| 94 | + |
| 95 | +var y = dist.pdf( 1.0 ); |
| 96 | +// returns 0.3520653267642996 |
| 97 | +``` |
| 98 | + |
| 99 | +</section> |
| 100 | + |
| 101 | +<!-- /.usage --> |
| 102 | + |
| 103 | +<section class="examples"> |
| 104 | + |
| 105 | +## Examples |
| 106 | + |
| 107 | +<!-- eslint no-undef: "error" --> |
| 108 | + |
| 109 | +```javascript |
| 110 | +var halfnormal = require( '@stdlib/stats/base/dists/halfnormal' ); |
| 111 | + |
| 112 | +/* |
| 113 | +A quality control engineer is analyzing the absolute deviations of product measurements from their target specification. |
| 114 | +
|
| 115 | +The absolute deviations follow a half-normal distribution with scale parameter σ (sigma) = 2.0 mm. |
| 116 | +
|
| 117 | +We can model these absolute deviations using a half-normal distribution with σ = 2.0. |
| 118 | +*/ |
| 119 | + |
| 120 | +var sigma = 2.0; |
| 121 | + |
| 122 | +var halfnormalDist = new halfnormal.HalfNormal( sigma ); |
| 123 | + |
| 124 | +// Output the scale parameter: |
| 125 | +console.log( halfnormalDist.sigma ); |
| 126 | +// => 2.0 |
| 127 | + |
| 128 | +// Mean absolute deviation: |
| 129 | +console.log( halfnormalDist.mean ); |
| 130 | +// => ~1.596 |
| 131 | + |
| 132 | +// Median absolute deviation: |
| 133 | +console.log( halfnormalDist.median ); |
| 134 | +// => ~1.349 |
| 135 | + |
| 136 | +// Mode (most common deviation): |
| 137 | +console.log( halfnormalDist.mode ); |
| 138 | +// => 0.0 |
| 139 | + |
| 140 | +// Variance of absolute deviations: |
| 141 | +console.log( halfnormalDist.variance ); |
| 142 | +// => 1.4535209105296745 |
| 143 | + |
| 144 | +// Probability density function at 1.0 mm deviation: |
| 145 | +console.log( halfnormal.pdf( 1.0, sigma ) ); |
| 146 | +// => 0.3520653267642996 |
| 147 | + |
| 148 | +// Cumulative distribution function at 2.0 mm (portion of deviations ≤ 2.0 mm): |
| 149 | +console.log( halfnormal.cdf( 2.0, sigma ) ); |
| 150 | +// => ~0.683 |
| 151 | + |
| 152 | +// 90th percentile of absolute deviations: |
| 153 | +console.log( halfnormal.quantile( 0.9, sigma ) ); |
| 154 | +// => 3.289707253902946 |
| 155 | + |
| 156 | +// Moment-generating function value at 0.5: |
| 157 | +console.log( halfnormal.mgf( 0.5, sigma ) ); |
| 158 | +// => 2.7742859576700094 |
| 159 | + |
| 160 | +// Entropy (measure of uncertainty): |
| 161 | +console.log( halfnormal.entropy( sigma ) ); |
| 162 | +// => 1.4189385332046727 |
| 163 | + |
| 164 | +// Skewness (measure of asymmetry): |
| 165 | +console.log( halfnormal.skewness( sigma ) ); |
| 166 | +// => ~0.995 |
| 167 | + |
| 168 | +// Excess kurtosis (measure of tail heaviness): |
| 169 | +console.log( halfnormal.kurtosis( sigma ) ); |
| 170 | +// => ~0.869 |
| 171 | + |
| 172 | +var myquantile = halfnormal.quantile.factory( 2.0 ); |
| 173 | + |
| 174 | +// 25th percentile: |
| 175 | +console.log( myquantile( 0.25 ) ); |
| 176 | +// => 0.6372787279287504 |
| 177 | + |
| 178 | +// 75th percentile: |
| 179 | +console.log( myquantile( 0.75 ) ); |
| 180 | +// => 2.300698760752016 |
| 181 | + |
| 182 | +var mylogpdf = halfnormal.logpdf.factory( 2.0 ); |
| 183 | + |
| 184 | +// Logarithm of PDF at 1.0 mm: |
| 185 | +console.log( mylogpdf( 1.0 ) ); |
| 186 | +// => -1.0439385332046727 |
| 187 | + |
| 188 | +// Logarithm of PDF at 3.0 mm: |
| 189 | +console.log( mylogpdf( 3.0 ) ); |
| 190 | +// => -2.0439385332046727 |
| 191 | +``` |
| 192 | + |
| 193 | +</section> |
| 194 | + |
| 195 | +<!-- /.examples --> |
| 196 | + |
| 197 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 198 | + |
| 199 | +<section class="related"> |
| 200 | + |
| 201 | +</section> |
| 202 | + |
| 203 | +<!-- /.related --> |
| 204 | + |
| 205 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 206 | + |
| 207 | +<section class="links"> |
| 208 | + |
| 209 | +[halfnormal-distribution]: https://en.wikipedia.org/wiki/Half-normal_distribution |
| 210 | + |
| 211 | +<!-- <toc-links> --> |
| 212 | + |
| 213 | +[@stdlib/stats/base/dists/halfnormal/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/ctor |
| 214 | + |
| 215 | +[@stdlib/stats/base/dists/halfnormal/entropy]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/entropy |
| 216 | + |
| 217 | +[@stdlib/stats/base/dists/halfnormal/kurtosis]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/kurtosis |
| 218 | + |
| 219 | +[@stdlib/stats/base/dists/halfnormal/mean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/mean |
| 220 | + |
| 221 | +[@stdlib/stats/base/dists/halfnormal/median]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/median |
| 222 | + |
| 223 | +[@stdlib/stats/base/dists/halfnormal/mode]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/mode |
| 224 | + |
| 225 | +[@stdlib/stats/base/dists/halfnormal/skewness]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/skewness |
| 226 | + |
| 227 | +[@stdlib/stats/base/dists/halfnormal/stdev]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/stdev |
| 228 | + |
| 229 | +[@stdlib/stats/base/dists/halfnormal/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/variance |
| 230 | + |
| 231 | +[@stdlib/stats/base/dists/halfnormal/cdf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/cdf |
| 232 | + |
| 233 | +[@stdlib/stats/base/dists/halfnormal/logcdf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/logcdf |
| 234 | + |
| 235 | +[@stdlib/stats/base/dists/halfnormal/logpdf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/logpdf |
| 236 | + |
| 237 | +[@stdlib/stats/base/dists/halfnormal/mgf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/mgf |
| 238 | + |
| 239 | +[@stdlib/stats/base/dists/halfnormal/pdf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/pdf |
| 240 | + |
| 241 | +[@stdlib/stats/base/dists/halfnormal/quantile]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/dists/halfnormal/quantile |
| 242 | + |
| 243 | +<!-- </toc-links> --> |
| 244 | + |
| 245 | +</section> |
| 246 | + |
| 247 | +<!-- /.links --> |
0 commit comments