This is the API documentation for all statistical distribution procedures. There is a probability density function (PDF), cumulative distribution function (CDF), and quantile function or percent point function (PPF) for each distribution.
fsml_norm_pdf
Probability density function for the normal distribution.
The location parameter (mu
) and scale parameter (sigma
) are optional arguments.
result =
fsml_norm_pdf(x [, mu, sigma])
x
: A scalar of type real
.
mu
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
sigma
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_norm_cdf
Cumulative distribution function for normal distribution.
The location parameter (mu
), scale parameter (sigma
), and tail option (tail
) are optional arguments.
result =
fsml_norm_cdf(x [, mu, sigma, tail])
x
: A scalar of type real
.
mu
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
sigma
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
tail
: An optional argument and character
string. If passed, it must be one of the following: "left", "right", "two", or "confidence". If not passed, it will default to "left".
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_norm_ppf
Percent point function/quantile function for normal distribution.
It computes the position (x
) based on the probability (p
).
The location parameter (mu
) and scale parameter (sigma
) are optional arguments.
Note: The procedure uses bisection method. Conditions p=0.0 and p=1.0 cannot return negative and positive infinity; will return large negative or positive numbers (highly dependent on the tolerance threshold).
result =
fsml_norm_ppf(p [, mu, sigma])
p
: A scalar of type real
. It must be between 0.0 and 1.0.
mu
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
sigma
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as p
.
fsml_t_pdf
Probability density function for student t distribution.
Uses intrinsic gamma function (Fortran 2008 and later).
where = degrees of freedom (df
) and is the gamma function.
The location parameter (mu
) and scale parameter (sigma
) are optional arguments.
result =
fsml_t_pdf(x, df [, mu, sigma])
x
: A scalar of type real
.
df
: A scalar of type real
. It must be 1.0 or higher.
mu
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
sigma
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_t_cdf
Cumulative distribution function for student t distribution.
The location parameter (mu
), scale parameter (sigma
), and tail option (tail
) are optional arguments.
result =
fsml_t_cdf(x, df [, mu, sigma, tail])
x
: A scalar of type real
.
df
: A scalar of type real
. It must be 1.0 or higher.
mu
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
sigma
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
tail
: An optional argument and character
string. If passed, it must be one of the following: "left", "right", "two", or "confidence". If not passed, it will default to "left".
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_t_ppf
Percent point function/quantile function for t distribution.
It computes the position (x
) based on the probability (p
) and degrees of freedom (df
).
The location parameter (mu
) and scale parameter (sigma
) are optional arguments.
Note: The procedure uses bisection method. Conditions p=0.0 and p=1.0 cannot return negative and positive infinity; will return large negative or positive numbers (highly dependent on the tolerance threshold).
result =
fsml_t_ppf(p, df [, mu, sigma])
p
: A scalar of type real
. It must be between 0.0 and 1.0.
df
: A scalar of type real
. It must be 1.0 or higher.
mu
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
sigma
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as p
.
fsml_gamma_pdf
Probability density function for gamma distribution. Uses intrinsic exp function.
The equation can also be expressed with the scale parameter , which is the inverse of the rate parameter , so that .
The scale parameters (alpha
) and (beta
) and the location parameter (loc
) are optional arguments. The location parameter will shift the distribution in the manner that does for the normal distribution.
result =
fsml_gamma_pdf(x [, alpha, beta, loc])
x
: A scalar of type real
.
alpha
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
beta
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
loc
: A scalar of type real
.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_gamma_cdf
Cumulative distribution function for gamma distribution.
The scale parameters (alpha
) and (beta
), the location parameter (loc
), and tail option (tail
) are optional arguments. The location parameter will shift the distribution in the manner that does for the normal distribution.
result =
fsml_gamma_cdf(x [, alpha, beta, loc, tail])
x
: A scalar of type real
.
alpha
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
beta
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
loc
: A scalar of type real
.
tail
: An optional argument and character
string. If passed, it must be one of the following: "left", "right", "two", or "confidence". If not passed, it will default to "left".
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_gamma_ppf
Percent point function/quantile function for gamma distribution.
It computes the position (x
) based on the probability (p
).
The scale parameters (alpha
) and (beta
) and the location parameter (loc
) are optional arguments. The location parameter will shift the distribution in the manner that does for the normal distribution.
Note: The procedure uses bisection method.
result =
fsml_gamma_ppf(p [, alpha, beta, loc])
p
: A scalar of type real
. It must be between 0.0 and 1.0.
alpha
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
beta
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
loc
: A scalar of type real
.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as p
.
fsml_exp_pdf
Probability density function for exponential distribution. Uses intrinsic exp function.
The rate parameter (lambda
) and location parameter (loc
) are optional arguments. The location parameter will shift the distribution in the manner that does for the normal distribution.
result =
fsml_exp_pdf(x [, lambda, loc])
x
: A scalar of type real
.
lambda
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
loc
: A scalar of type real
.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_exp_cdf
Cumulative distribution function for exponential distribution.
The rate parameter (lambda
), location parameter (loc
), and tail option (tail
) are optional arguments. The location parameter will shift the distribution in the manner that does for the normal distribution.
result =
fsml_exp_cdf(x [, lambda, loc, tail])
x
: A scalar of type real
.
lambda
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
loc
: A scalar of type real
.
tail
: An optional argument and character
string. If passed, it must be one of the following: "left", "right", "two", or "confidence". If not passed, it will default to "left".
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_exp_ppf
Percent point function/quantile function for exponential distribution.
Procedure uses bisection method. p
should be between 0.0 and 1.0.
It computes the position (x
) based on the probability (p
).
The rate parameter (lambda
) and location parameter (loc
) are optional arguments. The location parameter will shift the distribution in the manner that does for the normal distribution.
result =
fsml_exp_ppf(p [, lambda, loc])
p
: A scalar of type real
.
lambda
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
loc
: A scalar of type real
.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as p
.
fsml_chi2_pdf
Probability density function for the chi-squared distribution.
Uses intrinsic exp and gamma function.
where = degrees of freedom (df
) and is the gamma function.
The procedure calculates the probability based on the provided parameters x
and df
.
The location (loc
) and scale parameter (scale
) are optional arguments. The parameters loc
and scale
shift and scale the distribution, respectively, by a specified factor.
result =
fsml_chi2_pdf(x, df [, loc, scale])
x
: A scalar of type real
.
df
: A scalar of type real
. It must be 1.0 or higher.
loc
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
scale
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_chi2_cdf
Cumulative distribution function for the chi-squared distribution.
The procedure calculates the probability based on the provided parameters x
and df
.
The location (loc
), scale parameter (scale
), and tail option (tail
) arguments are optional arguments. The parameters loc
and scale
shift and scale the distribution, respectively, by a specified factor.
result =
fsml_chi2_cdf(x, df [, loc, scale, tail])
x
: A scalar of type real
.
df
: A scalar of type real
. It must be 1.0 or higher.
loc
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
scale
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
tail
: An optional argument and character
string. If passed, it must be one of the following: "left", "right", "two", or "confidence". If not passed, it will default to "left".
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_chi2_ppf
Percent point function/quantile function for the chi-squared distribution. Uses the bisection method for numerical inversion of the CDF.
It computes the position (x
) based on the probability (p
) and degrees of freedom (df
).
The location (loc
) and scale parameter (scale
) are optional arguments. The parameters loc
and scale
shift and scale the distribution, respectively, by a specified factor.
result =
fsml_chi2_ppf(p, df [, loc, scale])
p
: A scalar of type real
.
df
: A scalar of type real
. It must be 1.0 or higher.
loc
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
scale
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as p
.
fsml_f_pdf
Probability density function for the F distribution. where = numerator degrees of freedom, = denominator degrees of freedom and is the complete beta function. (Uses intrinsic gamma function for beta.)
The F distribution is the distribution of , where and are are random variables with chi-square distributions with (d1
) and (d1
) degrees of freedom, respectively.
The procedure calculates the probability based on the provided parameters x
, d1
, and d2
.
The location (loc
) and scale parameter (scale
) are optional arguments. The parameters loc
and scale
shift and scale the distribution, respectively, by a specified factor.
result =
fsml_f_pdf(x, d1, d2 [, loc, scale])
x
: A scalar of type real
.
d1
: A scalar of type real
. It must be 1.0 or higher.
d2
: A scalar of type real
. It must be 1.0 or higher.
loc
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
scale
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_f_cdf
Cumulative density function for the F distribution.
The procedure calculates the probability based on the provided parameters x
, d1
, and d2
.
The location (loc
), scale parameter (scale
), and tail option (tail
) arguments are optional arguments. The parameters loc
and scale
shift and scale the distribution, respectively, by a specified factor.
result =
fsml_f_cdf(x, d1, d2 [, loc, scale, tail])
x
: A scalar of type real
.
d1
: A scalar of type real
. It must be 1.0 or higher.
d2
: A scalar of type real
. It must be 1.0 or higher.
loc
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
scale
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
tail
: An optional argument and character
string. If passed, it must be one of the following: "left", "right", "two", or "confidence". If not passed, it will default to "left".
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_f_ppf
Percent point function / quantile function for the F distribution. Uses the bisection method to numerically invert the CDF.
It computes the position (x
) based on the probability (p
) and degrees of freedom (d1
and d2
).
The location (loc
) and scale parameter (scale
) are optional arguments. The parameters loc
and scale
shift and scale the distribution, respectively, by a specified factor.
result =
fsml_f_ppf(p, d1, d2 [, loc, scale])
p
: A scalar of type real
.
d1
: A scalar of type real
. It must be 1.0 or higher.
d2
: A scalar of type real
. It must be 1.0 or higher.
loc
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
scale
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as p
.
fsml_gpd_pdf
Probability density function for generalised pareto distribution.
where (xi
) is a shape parameter, (mu
) is the location, and (sigma
) is the scale parameter.
The procedure calculates the probability based on the provided parameters x
and xi
.
The location (mu
) and scale parameter (sigma
) are optional arguments.
result =
fsml_gpd_pdf(x, xi [, mu, sigma])
x
: A scalar of type real
.
xi
: A scalar of type real
.
mu
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
sigma
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_gpd_cdf
Cumulative distribution function for generalised pareto distribution.
The procedure calculates the probability based on the provided parameters x
and xi
.
The location (mu
) and scale parameter (sigma
), and tail option (tail
) are optional arguments.
result =
fsml_gpd_cdf(x, xi [, mu, sigma, tail])
x
: A scalar of type real
.
xi
: A scalar of type real
.
mu
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
sigma
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
tail
: An optional argument and character
string. If passed, it must be one of the following: "left", "right", "two", or "confidence". If not passed, it will default to "left".
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as x
.
fsml_gpd_ppf
Percent point function/quantile function for generalised pareto distribution.
Procedure uses bisection method. p
must be between 0.0 and 1.0.
It computes the position (x
) based on the probability (p
) and xi
.
The location parameter (mu
) and scale parameter (sigma
) are optional arguments.
result =
fsml_gpd_ppf(p, xi [, mu, sigma])
p
: A scalar of type real
.
xi
: A scalar of type real
.
mu
: An optional argument and scalar of type real
. It will default to 0.0 if not passed.
sigma
: An optional argument and positive scalar of type real
. If passed, it must be non-zero positive. It will default to 1.0 if not passed.
Invalid argument values will result in the return of a sentinel value.
The result is a scalar of the same type as p
.
program example_dst
! |--------------------------------------------------------------------|
! | fsml - fortran statistics and machine learning library |
! | |
! | about |
! | ----- |
! | Examples for distributions functions (dst module) |
! | |
! | license : MIT |
! | author : Sebastian G. Mutz (sebastian@sebastianmutz.com) |
! |--------------------------------------------------------------------|
use :: fsml
use :: fsml_ini ! import wp; alternatively: iso_fortran_env, wp => real64
implicit none
print*
! ---- Normal Distribution
print*, "> normal distribution"
! standardised normal pdf with x=1
print*, fsml_norm_pdf(1.0_wp, mu=0.0_wp, sigma=1.0_wp)
! 0.24197072451914337
! normal distribution pdf with x=0.5, mu=0.4 and sigma=1.2
print*, fsml_norm_pdf(0.5_wp, mu=0.4_wp, sigma=1.2_wp)
! 0.33129955521528498
! normal distribution cdf with x=2.3, mu=0.0 and signma=1.0
print*, fsml_norm_cdf(2.3_wp, mu=0.0_wp, sigma=1.0_wp, tail="left")
! 0.98927588997832416
! normal distribution ppf with p=0.3, mu=0.0 and signma=1.0
print*, fsml_norm_ppf(0.3_wp, mu=0.0_wp, sigma=1.0_wp)
! -0.52440051270878030
print*
! ---- Student T Distribution
print*, "> student t distribution"
! standard t pdf with x=1.5 and df=10
print*, fsml_t_pdf(1.5_wp, df=10.0_wp, mu=0.0_wp, sigma=1.0_wp)
! 0.12744479428709160
! t distribution pdf with x=0.5, df=200, ~mu=0.8 and ~sigma=1.2
! similar to norm due to high df
print*, fsml_t_pdf(0.5_wp, df=200.0_wp, mu=0.4_wp, sigma=1.2_wp)
! 0.33087996676641318
! get confidence interval with t distribution cdf with x=2.3, df=10, ~mu=0.0 and ~signma=1.0
print*, fsml_t_cdf(2.3_wp, df=10.0_wp, mu=0.0_wp, sigma=1.0_wp, tail="confidence")
! 0.95574568671571991
! t distribution ppf with p=0.9, df=15, ~mu=0.0 and ~signma=1.0
print*, fsml_t_ppf(0.9_wp, df=15.0_wp, mu=0.0_wp, sigma=1.0_wp)
! 1.3406056078565598
print*
! ---- Gamma Distribution
print*, "> gamma distribution"
! standard gamma pdf with x=2.3, defaults for shape parameters (alpha=1.0, beta=1.0) and loc
print*, fsml_gamma_pdf(2.3_wp, alpha=1.0_wp, beta=1.0_wp, loc=0.0_wp)
! 0.10025884372280375
! standard gamma pdf with x=2.3, defaults for shape parameters and location shift loc=0.5
print*, fsml_gamma_pdf(2.3_wp, alpha=1.0_wp, beta=1.0_wp, loc=0.5_wp)
! 0.16529888822158656
! gamma cdf with x=1.2, alpha=1.2, beta=0.6 and no location shift, and right end of the tail (survival function)
print*, fsml_gamma_cdf(1.2_wp, alpha=1.2_wp, beta=0.6_wp, loc=0.0_wp, tail="right")
! 0.18230123290900657
! gamma ppf for p=0.5, alpha=0.5, beta=1.1 and no location shift
print*, fsml_gamma_ppf(0.5_wp, alpha=0.5_wp, beta=1.1_wp, loc=0.0_wp)
! 0.25021503271636902
print*
! ---- Exponential Distribution
print*, "> exponential distribution"
! standard exponential pdf with x=1.3 and defaults for lambda=1.0 and loc=0.0
print*, fsml_exp_pdf(1.3_wp, lambda=1.0_wp, loc=0.0_wp)
! 0.27253179303401259
! exponential pdf with x=1.3 and defaults for lambda=0.2 and loc=1.0
print*, fsml_exp_pdf(1.3_wp, lambda=0.2_wp, loc=1.0_wp)
! 0.18835290671684976
! exponential cdf with x=0.1 and defaults for lambda=1.0 and loc=0.0
print*, fsml_exp_cdf(1.3_wp, lambda=1.0_wp, loc=0.0_wp)
! 0.72746820696598746
! exponential ppf with p=0.95 and defaults for lambda=1.0 and loc=0.0
print*, fsml_exp_ppf(0.5_wp, lambda=1.0_wp, loc=0.0_wp)
! 0.69314718055931490
print*
! ---- Chi-Squared Distribution
print*, "> chi-squared distribution"
! chi squared pdf with x=20.0, df=20, loc=0.5 and scale=1.0
print*, fsml_chi2_pdf(20.0_wp, df=20.0_wp, loc=0.5_wp, scale=1.0_wp)
! 6.3955413942221373E-002
! chi squared pdf with x=5.1, df=10, loc=0.0 and scale=0.5
print*, fsml_chi2_pdf(5.1_wp, df=10.0_wp, loc=0.0_wp, scale=0.5_wp)
! 0.17185714984072062
! chi squared cdf with x=11.5, df=10, loc=0.0 and scale=1.0
print*, fsml_chi2_cdf(11.5_wp, df=10.0_wp, loc=0.0_wp, scale=1.0_wp)
! 0.68008856946173257
! chi squared ppf with p=0.2, df=10, loc=2.0 and scale=1.2
print*, fsml_chi2_ppf(0.2_wp, df=10.0_wp, loc=2.0_wp, scale=1.2_wp)
! 9.4148951072402269
print*
! ---- F Distribution
print*, "> F distribution"
! f distribution pdf with x=2.0, d1=5.0, d2=2.0, loc=0.5 and scale=1.0
print*, fsml_f_pdf(2.0_wp, d1=5.0_wp, d2=2.0_wp, loc=0.5_wp, scale=1.0_wp)
! 0.19431184938882604
! f distribution pdf with x=1.1, d1=5.0, d2=10, loc=0.0 and scale=0.5
print*, fsml_f_pdf(1.1_wp, d1=5.0_wp, d2=10.0_wp, loc=0.0_wp, scale=0.5_wp)
! 0.25925652075006661
! f distribution cdf with x=11.5, d1=20, d2=10, loc=0.0 and scale=1.0
print*, fsml_f_cdf(11.5_wp, d1=20.0_wp, d2=10.0_wp, loc=0.0_wp, scale=1.0_wp, tail="left")
! 0.99981682497307667
! f distribution ppf with p=0.2, d1=10, d2=20, loc=2.0 and scale=1.2
print*, fsml_f_ppf(0.2_wp, d1=10.0_wp, d2=20.0_wp, loc=0.0_wp, scale=1.2_wp)
! 0.71332945788242341
print*
! ---- Generalised Pareto Distribution
print*, "> generalised pareto distribution"
! GPD pdf with x=1.1, xi=1.2, mu=0.0 and sigma=1.0
print*, fsml_gpd_pdf(1.1_wp, xi=1.2_wp, mu=0.0_wp, sigma=1.0_wp)
! 0.21376603130006952
! GPD pdf with x=1.9, xi=0.2, mu=0.0 and sigma=1.2
print*, fsml_gpd_pdf(1.9_wp, xi=0.2_wp, mu=0.0_wp, sigma=1.2_wp)
! 0.15994243683480086
! GPD cdf with x=2.1, xi=2.7, mu=1.2 and sigma=1.0 (standard left tail)
print*, fsml_gpd_cdf(2.1_wp, xi=2.7_wp, mu=1.2_wp, sigma=1.0_wp, tail="left")
! 0.36650539816689109
! GPD ppf with p=0.2, xi=0.7, mu=0.0 and sigma=1.0 (standard left tail)
print*, fsml_gpd_ppf(0.2_wp, xi=0.7_wp, mu=1.0_wp, sigma=1.0_wp)
! 1.2415150853975381
print*
end program example_dst