Percentiles of distribution in Fortran standard library

I was wondering if there is a function/subroutine to compute percentiles of an array in the Fortran standard library. So far I have been able only to find a function to compute the median in the stats module
Thanks!

There is selection – Fortran-lang/stdlib, from which percentiles could be computed:

  • select is used to find the k-th smallest entry of an array. The input array is also modified in-place, and on return will be partially sorted such that all(array(1:k) <= array(k))) and all(array(k) <= array((k+1):size(array))) is true. The user can optionally specify left and right indices to constrain the search for the k-th smallest value. This can be useful if you have previously called select to find a smaller or larger rank (that will have led to partial sorting of array, thus implying some constraints on the location).
  • arg_select is used to find the index of the k-th smallest entry of an array. In this case the input array is not modified, but the user must provide an input index array with the same size as array, having indices that are a permutation of 1:size(array), which is modified instead. On return the index array is modified such that all(array(index(1:k)) <= array(index(k))) and all(array(k) <= array(k+1:size(array))). The user can optionally specify left and right indices to constrain the search for the k-th smallest value. This can be useful if you have previously called arg_select to find a smaller or larger rank (that will have led to partial sorting of index, thus implying some constraints on the location).
1 Like

You might be looking with the wrong terminology. You might try looking for “cumulative distribution function” or “probability distribution function” or other similar terms. Cumulative distribution function - Wikipedia

1 Like

If you are interested in finding sample quantiles, getQuan() is the function you are looking for. The current implementation contains five different approximation methods to the sample quantile (see the interface docs).
If you are interested in the empirical cumulative distribution function of a sample, then setECDF is the functionality you are looking for.
If you are looking for specific cumulative distribution functions, then there are the following distribution functionalities in the ParaMonte library:

Module Functionality
pm_distBand This module contains procedures and generic interfaces for computing the Band photon distribution widely used in modeling the spectra of a class of celestial objects knowns Gamma-Ray Bursts.
pm_distBern This module contains classes and procedures for generating Bernoulli-distributed random numbers.
pm_distBeta This module contains classes and procedures for computing various statistical quantities related to the Beta distribution.
pm_distCosRaised This module contains classes and procedures for computing various statistical quantities related to the Raised Cosine distribution.
pm_distCov This module contains classes and procedures for generating random matrices distributed on the space of positive definite matrices, such that their determinants is uniformly or power-law distributed.
pm_distEggBox This module contains classes and procedures for computing various statistical quantities related to the mathematical EggBox density function.
pm_distExp This module contains classes and procedures for computing various statistical quantities related to the Exponential distribution.
pm_distExpGamma This module contains classes and procedures for computing various statistical quantities related to the ExpGamma distribution.
pm_distGamma This module contains classes and procedures for computing various statistical quantities related to the Gamma distribution.
pm_distGenExpGamma This module contains classes and procedures for computing various statistical quantities related to the GenExpGamma distribution.
pm_distGenGamma This module contains classes and procedures for computing various statistical quantities related to the GenGamma distribution.
pm_distGeom This module contains classes and procedures for computing various statistical quantities related to the Geometric distribution.
pm_distGeomCyclic This module contains classes and procedures for computing various statistical quantities related to the Cyclic Geometric distribution.
pm_distKolm This module contains classes and procedures for computing various statistical quantities related to the Kolmogorov distribution.
pm_distLogNorm This module contains classes and procedures for computing various statistical quantities related to the Lognormal distribution.
pm_distLogUnif This module contains classes and procedures for computing various statistical quantities related to the LogUniform (or Reciprocal) distribution.
pm_distMultiNorm This module contains classes and procedures for computing various statistical quantities related to the MultiVariate Normal (MVN) distribution.
pm_distNegExp This module contains classes and procedures for computing various statistical quantities related to the Negative Exponential distribution.
pm_distNorm This module contains classes and procedures for computing various statistical quantities related to the univariate Normal distribution.
pm_distNormShell This module contains procedures and generic interfaces for computing the Multivariate Normal Shell density function or mixtures of such densities with varying parameters.
pm_distPareto This module contains classes and procedures for computing various statistical quantities related to the (Truncated) Pareto distribution.
pm_distPois This module contains classes and procedures for computing various statistical quantities related to the Poisson distribution.
pm_distPower This module contains classes and procedures for computing various statistical quantities related to the (Truncated) Power distribution.
pm_distPoweto This module contains classes and procedures for computing various statistical quantities related to the (Truncated) Power/Pareto distribution (hence the name Poweto).
pm_distUnif This module contains classes and procedures for computing various statistical quantities related to the univariate Uniform distribution.
pm_distUnifEll This module contains classes and procedures for computing various statistical quantities related to the MultiVariate Uniform Ellipsoid (MVUE) distribution.
pm_distUnifPar This module contains classes and procedures for setting up and computing the properties of the MultiVariate Uniform Parallelepiped (MVUP) Distribution.
pm_distUnifSphere This module contains classes and procedures for computing various statistical quantities related to the Uniform Spherical distribution.

To start using your target functionality, I suggest you download a clone of the library and run the examples supplied with the target functionality to see how the library build and linking works. For example, to build and run examples for getQuan(), you could try:

./install.sh --exam getQuan

in Linux or macOS, or,

install.bat --exam getQuan

in Windows, or using CMake on any platform via,

mkdir bld && cd bld &&  cmake -Dexam="getQuan"

The library functionalities are quite extensive. If you are only interested in a specific functionality, I suggest adding the additional flag --mod pm_sampleQuan to the install scripts command above or -Dmod="pm_sampleQuan" to the CMake build command above.
See the full instructions here. All functionalities are generic and work for all real kinds supported by processors. I hope this helps!

1 Like