Articles

Statistiques en PHP

  • Ecrit par Damien Seguy
  • jeudi 02 août 2007
Image pour le titre du contenu

Les statistiques sont partout, y compris en PHP. On s'en sert pour détailler le trafic sur un site Web, mesurer l'évolution de PHP sur internet ou simplement faire des calculs financiers. Elles sont tellement ubiquitaires qu'il est étonnant de voir que la distribution standard inclut si peu de fonctions par défaut pour traiter ces problèmes.

Pour utiliser ces outils mathématiques très populaires, il y a plusieurs options. Quelques fonctions standards, des paquets PHP, des extensions. et des services Web.


Les fonctions standard

Pour aller vite en besogne, vous pouvez utiliser quelques fonctions telles que :
Il n'y a pas de fonction de moyenne ou de variance.

Les paquets PHP

Plusieurs paquets existent pour vous simplifiier la tâche :

L'extension stat

Enfin, il y existe une extension PECL  qui porte le nom de stats. Elle est disponible sur PECL pour la compilation ou sur PECL4WIN pour l'inclusion dans Windows. C'est l'oeuvre de Andrey Hristov.

Aucune documentation n'est disponible pour cette extension, sauf peut être le PDF de la version initiale, ainsi que les tests unitaires d'exempe (dans le code source). Pour comléter le tout,  vous trouverez en fin d'article les fonctions et les descriptions issues du code source.

Andrey a principalement nettoyé l'extension initiale pour en faire une version PECL valide.

Et les services Web

Enfin, il y a toujours la possibilité d'utiliser un service Web pour réaliser vos calculs, si jamais vous pouvez passer outre les aspects sécurité.



Notes finales


  • Merci à Bernard Mayer, qui a posé la question sur la liste AFUP : cet article est basé sur les recherches initiées par la question.
  • Le contenu de cet article n,est pas exhaustif. Si vous avez mieux, mailez-nous.

Documentation de ext/stats




  • stats_cdf_t ( float par1, float par2, int which )
    Retourne : float
    Utilisation: Calculates any one parameter of the T distribution given values for the others.
  • stats_stat_gennch ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Calculates any one parameter of the normal distribution given values for thee others.
  • stats_cdf_gamma ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Calculates any one parameter of the gamma distribution given values for the others.
  • stats_cdf_chisquare ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Calculates any one parameter of the chi-square distribution given values for the others.
  • stats_cdf_beta ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Calculates any one parameter of the beta distribution given values for the others.
  • stats_cdf_binomial ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Calculates any one parameter of the binomial distribution given values for the others.
  • stats_cdf_noncentral_chisquare ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Calculates any one parameter of the non-central chi-square distribution given values for the others.
  • stats_cdf_f ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Calculates any one parameter of the F distribution given values for the others.
  • stats_cdf_noncentral_f ( float par1, float par2, float par3, float par4, int which )
    Retourne : float
    Utilisation: Calculates any one parameter of the Non-central F distribution given values for the others.
  • stats_stat_noncentral_t ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Calculates any one parameter of the noncentral t distribution give values for the others.
  • stats_cdf_negative_binomial ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Calculates any one parameter of the negative binomial distribution given values for the others.
  • stats_cdf_poisson ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Calculates any one parameter of the Poisson distribution given values for the others.
  • stats_cdf_laplace ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Not documented
  • stats_cdf_cauchy ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Not documented
  • stats_cdf_logistic ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Not documented
  • stats_cdf_weibull ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Not documented
  • stats_cdf_uniform ( float par1, float par2, float par3, int which )
    Retourne : float
    Utilisation: Not documented
  • stats_cdf_exponential ( float par1, float par2, int which )
    Retourne : float
    Utilisation: Not documented
  • stats_rand_setall ( int iseed1, int iseed2 )
    Retourne : void
    Utilisation: Not documented
  • stats_rand_get_seeds ( void )
    Retourne : array
    Utilisation: Not documented
  • stats_rand_gen_iuniform ( int low, int high )
    Retourne : int
    Utilisation: Generates integer uniformly distributed between LOW (inclusive) and HIGH (inclusive)
  • stats_rand_gen_funiform ( float low, float high )
    Retourne : float
    Utilisation: Generates uniform float between low (exclusive) and high (exclusive)
  • stats_rand_gen_int ( void )
    Retourne : int
    Utilisation: Generates random integer between 1 and 2147483562
  • stats_rand_ranf ( void )
    Retourne : float
    Utilisation: Returns a random floating point number from a uniform distribution over 0 - 1 (endpoints of this interval are not returned) using the current generator
  • stats_rand_gen_beta ( float a, float b )
    Retourne : float
    Utilisation: Generates beta random deviate. Returns a random deviate from the beta distribution with parameters A and B. The density of the beta is x^(a-1) * (1-x)^(b-1) / B(a,b) for 0<1. aa - first parameter of the beta distribution. bb - second parameter of the beta distribution. Method R. C. H. Cheng
  • stats_rand_gen_chisquare ( float df )
    Retourne : float
    Utilisation: Generates random deviate from the distribution of a chisquare with "df" degrees of freedom random variable.
  • stats_rand_gen_exponential ( float av )
    Retourne : float
    Utilisation: Generates a single random deviate from an exponential distribution with mean "av"
  • stats_rand_gen_f ( float dfn, float dfd )
    Retourne : float
    Utilisation: Generates a random deviate from the F (variance ratio) distribution with "dfn" degrees of freedom in the numerator and "dfd" degrees of freedom in the denominator. Method : directly generates ratio of chisquare variates
  • stats_rand_gen_gamma ( float a, float r )
    Retourne : float
    Utilisation: Generates random deviates from the gamma distribution whose density is (A**R)/Gamma(R) * X**(R-1) * Exp(-A*X). Parameters : a - location parameter of Gamma distribution (a > 0), r - shape parameter of Gamma distribution (r > 0)
  • stats_rand_gen_noncenral_chisquare ( float df, float xnonc )
    Retourne : float
    Utilisation: Generates random deviate from the distribution of a noncentral chisquare with "df" degrees of freedom and noncentrality parameter "xnonc". d must be >= 1.0, xnonc must >= 0.0
  • stats_rand_gen_noncentral_f ( float dfn, float dfd, float xnonc )
    Retourne : float
    Utilisation: Generates a random deviate from the noncentral F (variance ratio) distribution with "dfn" degrees of freedom in the numerator, and "dfd" degrees of freedom in the denominator, and noncentrality parameter "xnonc". Method : directly generates ratio of noncentral numerator chisquare variate to central denominator chisquare variate.
  • stats_rand_gen_normal ( float av, float sd )
    Retourne : float
    Utilisation: Generates a single random deviate from a normal distribution with mean, av, and standard deviation, sd (sd >= 0). Method : Renames SNORM from TOMS as slightly modified by BWB to use RANF instead of SUNIF.
  • stats_rand_phrase_to_seeds ( string phrase )
    Retourne : array
    Utilisation: Uses a phrase (characted string) to generate two seeds for the RGN random number generator. Trailing blanks are eliminated before the seeds are generated. Generated seed values will fall in the range 1..2^30.
  • stats_rand_gen_ibinomial ( int n, float pp )
    Retourne : int
    Utilisation: Generates a single random deviate from a binomial distribution whose number of trials is "n" (n >= 0) and whose probability of an event in each trial is "pp" ([0;1]). Method : algorithm BTPE
  • stats_rand_gen_ibinomial_negative ( int n, float p )
    Retourne : int
    Utilisation: Generates a single random deviate from a negative binomial distribution. Arguments : n - the number of trials in the negative binomial distribution from which a random deviate is to be generated (n > 0), p - the probability of an event (0 < p < 1)).
  • stats_rand_gen_ipoisson ( float mu )
    Retourne : int
    Utilisation: Generates a single random deviate from a Poisson distribution with mean "mu" (mu >= 0.0).
  • stats_rand_gen_noncentral_t ( float df, float xnonc )
    Retourne : float
    Utilisation: Generates a single random deviate from a noncentral T distribution. xnonc - noncentrality parameter. df must be >= 0.0
  • stats_rand_gen_t ( float df )
    Retourne : float
    Utilisation: Generates a single random deviate from a T distribution. df must be >= 0.0
  • stats_dens_normal ( float x, float ave, float stdev )
    Retourne : float
    Utilisation: Not documented
  • stats_dens_cauchy ( float x, float ave, float stdev )
    Retourne : float
    Utilisation: Not documented
  • stats_dens_laplace ( float x, float ave, float stdev )
    Retourne : float
    Utilisation: Not documented
  • stats_dens_logistic ( float x, float ave, float stdev )
    Retourne : float
    Utilisation: Not documented
  • stats_dens_beta ( float x, float a, float b )
    Retourne : float
    Utilisation: Not documented
  • stats_dens_weibull ( float x, float a, float b )
    Retourne : float
    Utilisation: Not documented
  • stats_den_uniform ( float x, float a, float b )
    Retourne : float
    Utilisation: Not documented
  • stats_dens_chisquare ( float x, float dfr )
    Retourne : float
    Utilisation: Not documented
  • stats_dens_t ( float x, float dfr )
    Retourne : float
    Utilisation: Not documented
  • stats_dens_gamma ( float x, float shape, float scale )
    Retourne : float
    Utilisation: Not documented
  • stats_dens_exponential ( float x, float scale )
    Retourne : float
    Utilisation: Not documented
  • stats_dens_f ( float x, float dfr1, float dfr2 )
    Retourne : float
    Utilisation:
  • stats_dens_pmf_binomial ( float x, float n, float pi )
    Retourne : float
    Utilisation: Not documented
  • stats_dens_pmf_poisson ( float x, float lb )
    Retourne : float
    Utilisation: Not documented
  • stats_dens_negative_binomial ( float x, float n, float pi )
    Retourne : float
    Utilisation: Not documented
  • stats_dens_pmf_hypergeometric ( float n1, float n2, float N1, float N2 )
    Retourne : float
    Utilisation:
  • stats_stat_powersum ( array arr, float power )
    Retourne : float
    Utilisation: Not documented
  • stats_stat_innerproduct ( array arr1, array arr2 )
    Retourne : float
    Utilisation:
  • stats_stat_independent_t ( array arr1, array arr2 )
    Retourne : float
    Utilisation: Not documented
  • stats_stat_paired_t ( array arr1, array arr2 )
    Retourne : float
    Utilisation: Not documented
  • stats_stat_percentile ( float df, float xnonc )
    Retourne : float
    Utilisation: Not documented
  • stats_stat_correlation ( array arr1, array arr2 )
    Retourne : float
    Utilisation: Not documented
  • stats_stat_binomial_coef ( int x, int n )
    Retourne : float
    Utilisation: Not documented
  • stats_stat_gennch ( int n )
    Retourne : float
    Utilisation: Not documented
  • stats_variance ( array a [, bool sample] )
    Retourne : float
    Utilisation: Returns the population variance
  • stats_standard_deviation ( array a[, bool sample = false] )
    Retourne : float
    Utilisation: Returns the standard deviation
  • stats_absolute_deviation ( array a )
    Retourne : float
    Utilisation: Returns the absolute deviation of an array of values
  • stats_harmonic_mean ( array a )
    Retourne : float
    Utilisation: Returns the harmonic mean of an array of values
  • stats_skew ( array a )
    Retourne : float
    Utilisation: Computes the skewness of the data in the array
  • stats_kurtosis ( array a )
    Retourne : float
    Utilisation: Computes the kurtosis of the data in the array
  • stats_covariance ( array a, array b )
    Retourne : float
    Utilisation: Computes the covariance of two data sets
< Précédent   Suivant >

Commentaires

Vous pouvez ajouter votre commentaire!


Vous devez vous connecter pour commenter