You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixesstdlib-js#5747
Address commit comments in `11e8a56`.
* Remove extra space between `logpmf` and `(` in `lib/node_modules/@stdlib/stats/base/dists/hypergeometric/logpmf/README.md`.
* Add Oxford comma after `K` and before `and` in `lib/node_modules/@stdlib/stats/base/dists/hypergeometric/logpmf/src/main.c`.
* Change test description to "returns expected value" in `lib/node_modules/@stdlib/stats/base/dists/hypergeometric/logpmf/test/test.native.js`.
---
For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/stdlib-js/stdlib/issues/5747?shareId=XXXX-XXXX-XXXX-XXXX).
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
-
# Logarithm of Probability Mass Function
22
-
23
-
> Evaluate the natural logarithm of the [probability mass function][pmf] (PMF) for a [hypergeometric][hypergeometric-distribution] distribution.
24
-
25
-
<sectionclass="intro">
26
-
27
-
Imagine a scenario with a population of size `N`, of which a subpopulation of size `K` can be considered successes. We draw `n` observations from the total population. Defining the random variable `X` as the number of successes in the `n` draws, `X` is said to follow a [hypergeometric distribution][hypergeometric-distribution]. The [probability mass function][pmf] (PMF) for a [hypergeometric][hypergeometric-distribution] random variable is given by
28
-
29
-
<!-- <equation class="equation" label="eq:hypergeometric_pmf" align="center" raw="f(x;N,K,n)=P(X=x;N,K,n)=\begin{cases} {{{K \choose x} {N-K \choose {n-x}}}\over {{N} \choose n}} & \text{ for } x = 0,1,2,\ldots \\ 0 & \text{ otherwise} \end{cases}" alt="Probability mass function (PMF) for a hypergeometric distribution."> -->
<!-- <div class="equation" align="center" data-raw-text="f(x;N,K,n)=P(X=x;N,K,n)=\begin{cases} {{{K \choose x} {N-K \choose {n-x}}}\over {{N} \choose n}} & \text{ for } x = 0,1,2,\ldots \\ 0 & \text{ otherwise} \end{cases}" data-equation="eq:hypergeometric_pmf">
36
-
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/logpmf/docs/img/equation_hypergeometric_pmf.svg" alt="Probability mass function (PMF) for a hypergeometric distribution.">
37
-
<br>
38
-
</div> -->
39
-
40
-
<!-- </equation> -->
41
-
42
-
</section>
43
-
44
-
<!-- /.intro -->
45
-
46
-
<sectionclass="usage">
47
-
48
-
## Usage
49
-
50
-
```javascript
51
-
var logpmf =require( '@stdlib/stats/base/dists/hypergeometric/logpmf' );
52
-
```
53
-
54
-
#### logpmf( x, N, K, n )
55
-
56
-
Evaluates the natural logarithm of the [probability mass function][pmf] (PMF) for a [hypergeometric][hypergeometric-distribution] distribution with parameters `N` (population size), `K` (subpopulation size), and `n` (number of draws).
57
-
58
-
```javascript
59
-
var y =logpmf( 1.0, 8, 4, 2 );
60
-
// returns ~-0.56
61
-
62
-
y =logpmf( 2.0, 8, 4, 2 );
63
-
// returns ~-1.54
64
-
65
-
y =logpmf( 0.0, 8, 4, 2 );
66
-
// returns ~-1.54
67
-
68
-
y =logpmf( 1.5, 8, 4, 2 );
69
-
// returns -Infinity
70
-
```
71
-
72
-
If provided `NaN` as any argument, the function returns `NaN`.
73
-
74
-
```javascript
75
-
var y =logpmf( NaN, 10, 5, 2 );
76
-
// returns NaN
77
-
78
-
y =logpmf( 0.0, NaN, 5, 2 );
79
-
// returns NaN
80
-
81
-
y =logpmf( 0.0, 10, NaN, 2 );
82
-
// returns NaN
83
-
84
-
y =logpmf( 0.0, 10, 5, NaN );
85
-
// returns NaN
86
-
```
87
-
88
-
If provided a population size `N`, subpopulation size `K`, or draws `n` which is not a nonnegative integer, the function returns `NaN`.
89
-
90
-
```javascript
91
-
var y =logpmf( 2.0, 10.5, 5, 2 );
92
-
// returns NaN
93
-
94
-
y =logpmf( 2.0, 10, 1.5, 2 );
95
-
// returns NaN
96
-
97
-
y =logpmf( 2.0, 10, 5, -2.0 );
98
-
// returns NaN
99
-
```
100
-
101
-
If the number of draws `n` or the subpopulation size `K` exceed population size `N`, the function returns `NaN`.
102
-
103
-
```javascript
104
-
var y =logpmf( 2.0, 10, 5, 12 );
105
-
// returns NaN
106
-
107
-
y =logpmf( 2.0, 8, 3, 9 );
108
-
// returns NaN
109
-
```
110
-
111
-
#### logpmf.factory( N, K, n )
112
-
113
-
Returns a function for evaluating the natural logarithm of the [probability mass function][pmf] (PMF) of a [hypergeometric ][hypergeometric-distribution] distribution with parameters `N` (population size), `K` (subpopulation size), and `n` (number of draws).
114
-
115
-
```javascript
116
-
var mylogpmf =logpmf.factory( 30, 20, 5 );
117
-
var y =mylogpmf( 4.0 );
118
-
// returns ~-1.079
119
-
120
-
y =mylogpmf( 1.0 );
121
-
// returns ~-3.524
122
-
```
123
-
124
-
</section>
125
-
126
-
<!-- /.usage -->
127
-
128
-
<sectionclass="examples">
129
-
130
-
## Examples
131
-
132
-
<!-- eslint no-undef: "error" -->
133
-
134
-
```javascript
135
-
var randu =require( '@stdlib/random/base/randu' );
136
-
var round =require( '@stdlib/math/base/special/round' );
137
-
var logpmf =require( '@stdlib/stats/base/dists/hypergeometric/logpmf' );
138
-
139
-
var i;
140
-
varN;
141
-
varK;
142
-
var n;
143
-
var x;
144
-
var y;
145
-
146
-
for ( i =0; i <10; i++ ) {
147
-
x =round( randu() *5.0 );
148
-
N=round( randu() *20.0 );
149
-
K=round( randu() *N );
150
-
n =round( randu() *N );
151
-
y =logpmf( x, N, K, n );
152
-
console.log( 'x: %d, N: %d, K: %d, n: %d, ln(P(X=x;N,K,n)): %d', x, N, K, n, y.toFixed( 4 ) );
153
-
}
154
-
```
155
-
156
-
</section>
157
-
158
-
<!-- /.examples -->
159
-
160
-
<!-- C interface documentation. -->
161
-
162
-
* * *
163
-
164
-
<sectionclass="c">
165
-
166
-
## C APIs
167
-
168
-
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
#### stdlib_base_dists_hypergeometric_logpmf( x, N, K, n )
187
-
188
-
Evaluates the natural logarithm of the [probability mass function][pmf] (PMF) for a [hypergeometric][hypergeometric-distribution] distribution with parameters `N` (population size), `K` (subpopulation size), and `n` (number of draws).
189
-
190
-
```c
191
-
double out = stdlib_base_dists_hypergeometric_logpmf( 1.0, 8, 4, 2 );
192
-
// returns ~-0.56
193
-
```
194
-
195
1
The function accepts the following arguments:
196
2
197
3
-**x**: `[in] double` input value.
@@ -200,82 +6,11 @@ The function accepts the following arguments:
200
6
-**n**: `[in] int32_t` number of draws.
201
7
202
8
```c
203
-
doublestdlib_base_dists_hypergeometric_logpmf( const double x, const int32_t N, const int32_t K, const int32_t n );
9
+
doublestdlib_base_dists_hypergeometric_logpmf( const double x, const int32_t N, const int32_t K, const int32_t n );
204
10
```
205
11
206
12
</section>
207
13
208
14
<!-- /.usage -->
209
15
210
16
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
* Evaluates the natural logarithm of the probability mass function (PMF) for a hypergeometric distribution with population size `N`, subpopulation size `K` and number of draws `n`.
4
+
* Evaluates the natural logarithm of the probability mass function (PMF) for a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`.
30
5
*
31
6
* @param x input value
32
7
* @param N population size
@@ -35,27 +10,18 @@
35
10
* @return evaluated logPMF
36
11
*
37
12
* @example
38
-
* double y = stdlib_base_dists_hypergeometric_logpmf( 1.0, 8, 4, 2 );
39
-
* // returns ~-0.56
13
+
* double y = stdlib_base_dists_hypergeometric_logpmf( 1.0, 10, 5, 3 );
0 commit comments