@@ -106,10 +106,43 @@ var y = dist.pmf( 4.0 );
106
106
<!-- eslint no-undef: "error" -->
107
107
108
108
``` javascript
109
- var objectKeys = require ( ' @stdlib/utils/keys' );
110
109
var negativeBinomial = require ( ' @stdlib/stats/base/dists/negative-binomial' );
111
110
112
- console .log ( objectKeys ( negativeBinomial ) );
111
+ /*
112
+ * Let's take an example of flipping a biased coin until getting 5 heads.
113
+ * This situation can be modeled using a Negative Binomial distribution with r = 5 and p = 1/2.
114
+ */
115
+
116
+ var r = 5.0 ;
117
+ var p = 1 / 2 ;
118
+
119
+ // Mean can be used to calculate the average number of trials needed to get 5 heads:
120
+ console .log ( negativeBinomial .mean ( r, p ) );
121
+ // => 5
122
+
123
+ // PMF can be used to calculate the probability of getting heads on a specific trial (say on the 8th trial):
124
+ console .log ( negativeBinomial .pmf ( 8 , r, p ) );
125
+ // => ~0.06
126
+
127
+ // CDF can be used to calculate the probability up to a certain number of trials (say up to 8 trials):
128
+ console .log ( negativeBinomial .cdf ( 8 , r, p ) );
129
+ // => ~0.867
130
+
131
+ // Quantile can be used to calculate the number of trials at which you can be 80% confident that the actual number will not exceed:
132
+ console .log ( negativeBinomial .quantile ( 0.8 , r, p ) );
133
+ // => 7
134
+
135
+ // Standard deviation can be used to calculate the measure of the spread of trials around the mean:
136
+ console .log ( negativeBinomial .stdev ( r, p ) );
137
+ // => ~3.162
138
+
139
+ // Skewness can be used to calculate the asymmetry of the distribution of trials:
140
+ console .log ( negativeBinomial .skewness ( r, p ) );
141
+ // => ~0.949
142
+
143
+ // MGF can be used for more advanced statistical analyses and generating moments of the distribution:
144
+ console .log ( negativeBinomial .mgf ( 0.5 , r, p ) );
145
+ // => ~2277.597
113
146
```
114
147
115
148
</section >
0 commit comments