|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 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 | +# Cumulative Distribution Function |
| 22 | + |
| 23 | +> [Log-logistic][log-logistic-distribution] distribution [cumulative distribution function (CDF)][cdf]. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +The [cumulative distribution function][cdf] (CDF) for a [log-logistic][log-logistic-distribution] random variable is |
| 28 | + |
| 29 | +<!-- <equation class="equation" label="eq:log-logistic_cdf" align="center" raw="F(x;\alpha,\beta) = \frac{1}{1+\left(\dfrac{x}{\alpha}\right)^{-\beta}}" alt="Cumulative distribution function (CDF) for a log-logistic distribution."> --> |
| 30 | + |
| 31 | +```math |
| 32 | +F(x;\alpha,\beta) = \frac{1}{1+\left(\dfrac{x}{\alpha}\right)^{-\beta}} |
| 33 | +``` |
| 34 | + |
| 35 | +<!-- <div class="equation" align="center" data-raw-text="F(x;\alpha,\beta) = \frac{1}{1+\left(\dfrac{x}{\alpha}\right)^{-\beta}}" data-equation="eq:log_logistic_cdf"> |
| 36 | + <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@.../lib/node_modules/@stdlib/stats/base/dists/log-logistic/cdf/docs/img/equation_log_logistic_cdf.svg" alt="Cumulative distribution function (CDF) for a log-logistic distribution."> |
| 37 | + <br> |
| 38 | +</div> --> |
| 39 | + |
| 40 | +<!-- </equation> --> |
| 41 | + |
| 42 | +where `alpha` is the scale parameter and `beta` is the shape parameter. |
| 43 | + |
| 44 | +</section> |
| 45 | + |
| 46 | +<!-- /.intro --> |
| 47 | + |
| 48 | +<section class="usage"> |
| 49 | + |
| 50 | +## Usage |
| 51 | + |
| 52 | +```javascript |
| 53 | +var cdf = require( '@stdlib/stats/base/dists/log-logistic/cdf' ); |
| 54 | +``` |
| 55 | + |
| 56 | +#### cdf( x, alpha, beta ) |
| 57 | + |
| 58 | +Evaluates the [cumulative distribution function][cdf] (CDF) for a [log-logistic][log-logistic-distribution] distribution with parameters `alpha` (scale parameter) and `beta` (shape parameter). |
| 59 | + |
| 60 | +```javascript |
| 61 | +var y = cdf( 2.0, 1.0, 1.0 ); |
| 62 | +// returns ~0.667 |
| 63 | + |
| 64 | +y = cdf( 4.0, 2.0, 3.0 ); |
| 65 | +// returns ~0.889 |
| 66 | +``` |
| 67 | + |
| 68 | +If provided `NaN` as any argument, the function returns `NaN`. |
| 69 | + |
| 70 | +```javascript |
| 71 | +var y = cdf( NaN, 1.0, 1.0 ); |
| 72 | +// returns NaN |
| 73 | + |
| 74 | +y = cdf( 1.0, NaN, 1.0 ); |
| 75 | +// returns NaN |
| 76 | + |
| 77 | +y = cdf( 1.0, 1.0, NaN ); |
| 78 | +// returns NaN |
| 79 | +``` |
| 80 | + |
| 81 | +If provided `alpha <= 0`, the function returns `NaN`. |
| 82 | + |
| 83 | +```javascript |
| 84 | +var y = cdf( 2.0, -1.0, 1.0 ); |
| 85 | +// returns NaN |
| 86 | +``` |
| 87 | + |
| 88 | +If provided `beta <= 0`, the function returns `NaN`. |
| 89 | + |
| 90 | +```javascript |
| 91 | +var y = cdf( 2.0, 1.0, -1.0 ); |
| 92 | +// returns NaN |
| 93 | +``` |
| 94 | + |
| 95 | +#### cdf.factory( alpha, beta ) |
| 96 | + |
| 97 | +Returns a function for evaluating the [cumulative distribution function][cdf] (CDF) of a [log-logistic][log-logistic-distribution] distribution with parameters `alpha` (scale parameter) and `beta` (shape parameter). |
| 98 | + |
| 99 | +```javascript |
| 100 | +var mycdf = cdf.factory( 1.0, 1.0 ); |
| 101 | + |
| 102 | +var y = mycdf( 2.0 ); |
| 103 | +// returns ~0.667 |
| 104 | + |
| 105 | +y = mycdf( -1.0 ); |
| 106 | +// returns 0.0 |
| 107 | +``` |
| 108 | + |
| 109 | +</section> |
| 110 | + |
| 111 | +<!-- /.usage --> |
| 112 | + |
| 113 | +<section class="examples"> |
| 114 | + |
| 115 | +## Examples |
| 116 | + |
| 117 | +<!-- eslint no-undef: "error" --> |
| 118 | + |
| 119 | +```javascript |
| 120 | +var uniform = require( '@stdlib/random/array/uniform' ); |
| 121 | +var logEachMap = require( '@stdlib/console/log-each-map' ); |
| 122 | +var cdf = require( '@stdlib/stats/base/dists/log-logistic/cdf' ); |
| 123 | + |
| 124 | +var opts = { |
| 125 | + 'dtype': 'float64' |
| 126 | +}; |
| 127 | +var x = uniform( 10, 0.1, 10.0, opts ); |
| 128 | +var alpha = uniform( 10, 0.1, 10.0, opts ); |
| 129 | +var beta = uniform( 10, 0.1, 10.0, opts ); |
| 130 | + |
| 131 | +logEachMap( 'x: %0.4f, alpha: %0.4f, beta: %0.4f, F(x;alpha,beta): %0.4f', x, alpha, beta, cdf ); |
| 132 | +``` |
| 133 | + |
| 134 | +</section> |
| 135 | + |
| 136 | +<!-- /.examples --> |
| 137 | + |
| 138 | +<!-- C interface documentation. --> |
| 139 | + |
| 140 | +* * * |
| 141 | + |
| 142 | +<section class="c"> |
| 143 | + |
| 144 | +## C APIs |
| 145 | + |
| 146 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 147 | + |
| 148 | +<section class="intro"> |
| 149 | + |
| 150 | +</section> |
| 151 | + |
| 152 | +<!-- /.intro --> |
| 153 | + |
| 154 | +<!-- C usage documentation. --> |
| 155 | + |
| 156 | +<section class="usage"> |
| 157 | + |
| 158 | +### Usage |
| 159 | + |
| 160 | +```c |
| 161 | +#include "stdlib/stats/base/dists/log-logistic/cdf.h" |
| 162 | +``` |
| 163 | + |
| 164 | +#### stdlib_base_dists_log_logistic_cdf( x, alpha, beta ) |
| 165 | + |
| 166 | +Evaluates the [cumulative distribution function][cdf] (CDF) for a [log-logistic][log-logistic-distribution] distribution with parameters `alpha` (scale parameter) and `beta` (shape parameter). |
| 167 | + |
| 168 | +```c |
| 169 | +double out = stdlib_base_dists_log_logistic_cdf( 2.0, 1.0, 1.0 ); |
| 170 | +// returns ~0.667 |
| 171 | +``` |
| 172 | + |
| 173 | +The function accepts the following arguments: |
| 174 | + |
| 175 | +- **x**: `[in] double` input parameter. |
| 176 | +- **alpha**: `[in] double` scale parameter. |
| 177 | +- **beta**: `[in] double` shape parameter. |
| 178 | + |
| 179 | +```c |
| 180 | +double stdlib_base_dists_log_logistic_cdf( const double x, const double alpha, const double beta ); |
| 181 | +``` |
| 182 | +
|
| 183 | +</section> |
| 184 | +
|
| 185 | +<!-- /.usage --> |
| 186 | +
|
| 187 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 188 | +
|
| 189 | +<section class="notes"> |
| 190 | +
|
| 191 | +</section> |
| 192 | +
|
| 193 | +<!-- /.notes --> |
| 194 | +
|
| 195 | +<!-- C API usage examples. --> |
| 196 | +
|
| 197 | +<section class="examples"> |
| 198 | +
|
| 199 | +### Examples |
| 200 | +
|
| 201 | +```c |
| 202 | +#include "stdlib/stats/base/dists/log-logistic/cdf.h" |
| 203 | +#include <stdlib.h> |
| 204 | +#include <stdio.h> |
| 205 | +
|
| 206 | +static double random_uniform( const double min, const double max ) { |
| 207 | + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); |
| 208 | + return min + ( v * ( max-min ) ); |
| 209 | +} |
| 210 | +
|
| 211 | +int main( void ) { |
| 212 | + double alpha; |
| 213 | + double beta; |
| 214 | + double x; |
| 215 | + double y; |
| 216 | + int i; |
| 217 | +
|
| 218 | + for ( i = 0; i < 25; i++ ) { |
| 219 | + x = random_uniform( 0.1, 10.0 ); |
| 220 | + alpha = random_uniform( 0.1, 10.0 ); |
| 221 | + beta = random_uniform( 0.1, 10.0 ); |
| 222 | + y = stdlib_base_dists_log_logistic_cdf( x, alpha, beta ); |
| 223 | + printf( "x: %lf, alpha: %lf, beta: %lf, F(x;alpha,beta): %lf\n", x, alpha, beta, y ); |
| 224 | + } |
| 225 | +} |
| 226 | +``` |
| 227 | + |
| 228 | +</section> |
| 229 | + |
| 230 | +<!-- /.examples --> |
| 231 | + |
| 232 | +</section> |
| 233 | + |
| 234 | +<!-- /.c --> |
| 235 | + |
| 236 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 237 | + |
| 238 | +<section class="related"> |
| 239 | + |
| 240 | +</section> |
| 241 | + |
| 242 | +<!-- /.related --> |
| 243 | + |
| 244 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 245 | + |
| 246 | +<section class="links"> |
| 247 | + |
| 248 | +[log-logistic-distribution]: https://en.wikipedia.org/wiki/Log-logistic_distribution |
| 249 | + |
| 250 | +[cdf]: https://en.wikipedia.org/wiki/Cumulative_distribution_function |
| 251 | + |
| 252 | +</section> |
| 253 | + |
| 254 | +<!-- /.links --> |
0 commit comments