README.md (6104B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 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 # Bernoulli 22 23 > Bernoulli distribution constructor. 24 25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 26 27 <section class="intro"> 28 29 </section> 30 31 <!-- /.intro --> 32 33 <!-- Package usage documentation. --> 34 35 <section class="usage"> 36 37 ## Usage 38 39 ```javascript 40 var Bernoulli = require( '@stdlib/stats/base/dists/bernoulli/ctor' ); 41 ``` 42 43 #### Bernoulli( \[p] ) 44 45 Returns a [Bernoulli][bernoulli-distribution] distribution object. 46 47 ```javascript 48 var bernoulli = new Bernoulli(); 49 50 var mean = bernoulli.mean; 51 // returns 0.5 52 ``` 53 54 By default, `p = 0.5`. To create a distribution having a different success probability `p`, provide a parameter value. 55 56 ```javascript 57 var bernoulli = new Bernoulli( 0.2 ); 58 59 var mean = bernoulli.mean; 60 // returns 0.2 61 ``` 62 63 * * * 64 65 ## bernoulli 66 67 A [Bernoulli][bernoulli-distribution] distribution object has the following properties and methods... 68 69 ### Writable Properties 70 71 #### bernoulli.p 72 73 Success probability of the distribution. `p` **must** be a probability. 74 75 ```javascript 76 var bernoulli = new Bernoulli( 0.2 ); 77 78 var p = bernoulli.p; 79 // returns 0.2 80 81 bernoulli.p = 0.3; 82 83 p = bernoulli.p; 84 // returns 0.3 85 ``` 86 87 * * * 88 89 ### Computed Properties 90 91 #### Bernoulli.prototype.entropy 92 93 Returns the [differential entropy][entropy]. 94 95 ```javascript 96 var bernoulli = new Bernoulli( 0.4 ); 97 98 var entropy = bernoulli.entropy; 99 // returns ~0.673 100 ``` 101 102 #### Bernoulli.prototype.kurtosis 103 104 Returns the [excess kurtosis][kurtosis]. 105 106 ```javascript 107 var bernoulli = new Bernoulli( 0.4 ); 108 109 var kurtosis = bernoulli.kurtosis; 110 // returns ~-1.833 111 ``` 112 113 #### Bernoulli.prototype.mean 114 115 Returns the [median][expected-value]. 116 117 ```javascript 118 var bernoulli = new Bernoulli( 0.4 ); 119 120 var mu = bernoulli.mean; 121 // returns 0.4 122 ``` 123 124 #### Bernoulli.prototype.median 125 126 Returns the [median][median]. 127 128 ```javascript 129 var bernoulli = new Bernoulli( 0.4 ); 130 131 var median = bernoulli.median; 132 // returns 0.0 133 ``` 134 135 #### Bernoulli.prototype.mode 136 137 Returns the [mode][mode]. 138 139 ```javascript 140 var bernoulli = new Bernoulli( 0.4 ); 141 142 var mode = bernoulli.mode; 143 // returns 0.0 144 ``` 145 146 #### Bernoulli.prototype.skewness 147 148 Returns the [skewness][skewness]. 149 150 ```javascript 151 var bernoulli = new Bernoulli( 0.4 ); 152 153 var skewness = bernoulli.skewness; 154 // returns ~0.408 155 ``` 156 157 #### Bernoulli.prototype.stdev 158 159 Returns the [standard deviation][standard-deviation]. 160 161 ```javascript 162 var bernoulli = new Bernoulli( 0.4 ); 163 164 var s = bernoulli.stdev; 165 // returns ~0.49 166 ``` 167 168 #### Bernoulli.prototype.variance 169 170 Returns the [variance][variance]. 171 172 ```javascript 173 var bernoulli = new Bernoulli( 0.4 ); 174 175 var s2 = bernoulli.variance; 176 // returns 0.24 177 ``` 178 179 * * * 180 181 ### Methods 182 183 #### Bernoulli.prototype.cdf( x ) 184 185 Evaluates the [cumulative distribution function][cdf] (CDF). 186 187 ```javascript 188 var bernoulli = new Bernoulli( 0.2 ); 189 190 var y = bernoulli.cdf( 0.5 ); 191 // returns 0.8 192 ``` 193 194 #### Bernoulli.prototype.mgf( t ) 195 196 Evaluates the [moment-generating function][mgf] (MGF). 197 198 ```javascript 199 var bernoulli = new Bernoulli( 0.2 ); 200 201 var y = bernoulli.mgf( -3.0 ); 202 // returns ~0.81 203 ``` 204 205 #### Bernoulli.prototype.pmf( x ) 206 207 Evaluates the [probability mass function][pmf] (PMF). 208 209 ```javascript 210 var bernoulli = new Bernoulli( 0.2 ); 211 212 var y = bernoulli.pmf( 0.0 ); 213 // returns 0.8 214 215 y = bernoulli.pmf( 1.0 ); 216 // returns 0.2 217 ``` 218 219 #### Bernoulli.prototype.quantile( p ) 220 221 Evaluates the [quantile function][quantile-function] at probability `p`. 222 223 ```javascript 224 var bernoulli = new Bernoulli( 0.2 ); 225 226 var y = bernoulli.quantile( 0.5 ); 227 // returns 0 228 229 y = bernoulli.quantile( 0.9 ); 230 // returns 1 231 ``` 232 233 </section> 234 235 <!-- /.usage --> 236 237 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 238 239 <section class="notes"> 240 241 </section> 242 243 <!-- /.notes --> 244 245 <!-- Package usage examples. --> 246 247 * * * 248 249 <section class="examples"> 250 251 ## Examples 252 253 <!-- eslint no-undef: "error" --> 254 255 ```javascript 256 var Bernoulli = require( '@stdlib/stats/base/dists/bernoulli/ctor' ); 257 258 var bernoulli = new Bernoulli( 0.5 ); 259 260 var mu = bernoulli.mean; 261 // returns 0.5 262 263 var s2 = bernoulli.variance; 264 // returns 0.25 265 266 var y = bernoulli.cdf( 2.0 ); 267 // returns 1.0 268 ``` 269 270 </section> 271 272 <!-- /.examples --> 273 274 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 275 276 <section class="references"> 277 278 </section> 279 280 <!-- /.references --> 281 282 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 283 284 <section class="links"> 285 286 [bernoulli-distribution]: https://en.wikipedia.org/wiki/Bernoulli_distribution 287 288 [cdf]: https://en.wikipedia.org/wiki/Cumulative_distribution_function 289 290 [mgf]: https://en.wikipedia.org/wiki/Moment-generating_function 291 292 [pmf]: https://en.wikipedia.org/wiki/Probability_mass_function 293 294 [quantile-function]: https://en.wikipedia.org/wiki/Quantile_function 295 296 [entropy]: https://en.wikipedia.org/wiki/Entropy_%28information_theory%29 297 298 [expected-value]: https://en.wikipedia.org/wiki/Expected_value 299 300 [kurtosis]: https://en.wikipedia.org/wiki/Kurtosis 301 302 [median]: https://en.wikipedia.org/wiki/Median 303 304 [mode]: https://en.wikipedia.org/wiki/Mode_%28statistics%29 305 306 [skewness]: https://en.wikipedia.org/wiki/Skewness 307 308 [standard-deviation]: https://en.wikipedia.org/wiki/Standard_deviation 309 310 [variance]: https://en.wikipedia.org/wiki/Variance 311 312 </section> 313 314 <!-- /.links -->