fonction ecarttype en php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mat

    fonction ecarttype en php

    Je l'ai cherché partout, je ne l'ai pas trouvé, alors je l'ai
    écrite.

    Si ça peut servir à d'autres ...

    echo "Calcul d'un ecart type";
    echo "<br>";

    $datas = array("11","22" ,"45","67","21" ,"3","20");

    $ecart = ecarttype($data s);

    if ($ecart)
    {
    echo $ecart;
    }
    else
    {
    echo "Jeu de valeurs incohérent !";
    }

    function ecarttype($arra y, $nbdecimals=2) {

    if (is_array($arra y))
    {
    //moyenne des valeurs
    reset($array);
    $somme=0;
    $nbelement=coun t($array);
    foreach ($array as $value) {
    $somme += floatval($value );
    }
    $moyenne = $somme/$nbelement;
    //numerateur
    reset($array);
    $sigma=0;
    foreach ($array as $value) {
    $sigma += pow((floatval($ value)-$moyenne),2);
    }
    //denominateur = $nbelement
    $ecarttype = sqrt($sigma/$nbelement);
    return number_format($ ecarttype, $nbdecimals);
    }
    else
    {
    return false;
    }
    }

  • R. Rajesh Jeba Anbiah

    #2
    Caclulation of standard deviation (Was Re: fonction ecarttype en php)

    mat wrote:[color=blue]
    > Je l'ai cherché partout, je ne l'ai pas trouvé, alors je l'ai
    > écrite.
    >
    > Si ça peut servir à d'autres ...[/color]
    <snip>

    Thanks. Would be nice, if you could use English in future. Got it
    translated with Google:
    <Google translation
    url="http://translate.googl e.com/translate?u=htt p://groups.google.c om/group/comp.lang.php/msg/b4524aca9cf1ca5 d&langpair=fr%7 Cen&hl=en&ie=UT F8">

    I sought it everywhere, I did not find it, then I have it
    written.

    If that can be used for others...

    echo "Calculatio n of a standard deviation";
    echo "< Br >";

    $$datas = array("11", "22"," 45", "67"," 21 ", "3"," 20");

    $$ecart = ecarttype($data s);

    yew ($$ecart)
    {
    echo $$ecart;
    }

    else
    {
    echo "incoherent Set of values!";

    }

    function ecarttype($arra y, $$nbdecimals=2) {

    yew (is_array($arra y))
    {
    // average of the values
    reset($array);
    $$somme=0;
    $$nbelement=cou nt($array);
    foreach ($$array have $$value) {
    $$somme + = floatval($value );
    }
    $$moyenne = $$somme/$nbelement;
    // numerator
    reset($array);
    $$sigma=0;
    foreach ($$array have $$value) {
    $$sigma + = pow((floatval($ value)-$moyenne),2);
    }
    // denominator = $$nbelement
    $$ecarttype = sqrt($sigma/$nbelement);
    return number_format($ ecarttype, $$nbdecimals);
    }
    else
    {
    return false;
    }
    }
    </Google translation>

    --
    <?php echo 'Just another PHP saint'; ?>
    Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

    Comment

    • Christopher Pomasl

      #3
      Re: Caclulation of standard deviation (Was Re: fonction ecarttype en php)

      On Tue, 30 Aug 2005 07:33:03 -0700, R. Rajesh Jeba Anbiah wrote:
      [color=blue]
      > mat wrote:[color=green]
      >> Je l'ai cherché partout, je ne l'ai pas trouvé, alors je l'ai
      >> écrite.
      >>
      >> Si ça peut servir à d'autres ...[/color]
      > <snip>
      >
      > Thanks. Would be nice, if you could use English in future. Got it
      > translated with Google:
      > <Google translation
      > url="http://translate.googl e.com/translate?u=htt p://groups.google.c om/group/comp.lang.php/msg/b4524aca9cf1ca5 d&langpair=fr%7 Cen&hl=en&ie=UT F8">
      >
      > I sought it everywhere, I did not find it, then I have it
      > written.
      >
      > If that can be used for others...
      >
      > echo "Calculatio n of a standard deviation";
      > echo "< Br >";
      >
      > $$datas = array("11", "22"," 45", "67"," 21 ", "3"," 20");
      >
      > $$ecart = ecarttype($data s);
      >
      > yew ($$ecart)
      > {
      > echo $$ecart;
      > }
      >
      > else
      > {
      > echo "incoherent Set of values!";
      >
      > }
      >
      > function ecarttype($arra y, $$nbdecimals=2) {
      >
      > yew (is_array($arra y))
      > {
      > // average of the values
      > reset($array);
      > $$somme=0;
      > $$nbelement=cou nt($array);
      > foreach ($$array have $$value) {
      > $$somme + = floatval($value );
      > }
      > $$moyenne = $$somme/$nbelement;
      > // numerator
      > reset($array);
      > $$sigma=0;
      > foreach ($$array have $$value) {
      > $$sigma + = pow((floatval($ value)-$moyenne),2);
      > }
      > // denominator = $$nbelement
      > $$ecarttype = sqrt($sigma/$nbelement);
      > return number_format($ ecarttype, $$nbdecimals);
      > }
      > else
      > {
      > return false;
      > }
      > }
      > </Google translation>[/color]


      Also Note there are two calculations for standard deviation.
      The first as shown above is called the "population " deviation and implies
      that the sample used to calculate the deviation is the entire sample.

      This is defined as sqrt( sum ((x - mean(x))**2) / N)

      There is a weighted "sample" deviation calculation which implies that the
      sample used is just that, a sample and NOT the entire population.

      This is defined as sqrt( sum ((x - mean(2))**2) / N - 1)

      In this case, the code shown above should subtract 1 from $nbelement
      before the sqtr() function near the bottom.

      Chris

      Comment

      • Manuel Lemos

        #4
        Re: Caclulation of standard deviation (Was Re: fonction ecarttypeen php)

        Hello,

        on 08/30/2005 11:09 PM Christopher Pomasl said the following:[color=blue]
        > Also Note there are two calculations for standard deviation.
        > The first as shown above is called the "population " deviation and implies
        > that the sample used to calculate the deviation is the entire sample.
        >
        > This is defined as sqrt( sum ((x - mean(x))**2) / N)
        >
        > There is a weighted "sample" deviation calculation which implies that the
        > sample used is just that, a sample and NOT the entire population.
        >
        > This is defined as sqrt( sum ((x - mean(2))**2) / N - 1)
        >
        > In this case, the code shown above should subtract 1 from $nbelement
        > before the sqtr() function near the bottom.[/color]

        You may also want to take a look at this class that computes standard
        deviation:




        --

        Regards,
        Manuel Lemos

        PHP Classes - Free ready to use OOP components written in PHP
        Free PHP Classes and Objects 2025 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials


        PHP Reviews - Reviews of PHP books and other products


        Metastorage - Data object relational mapping layer generator

        Comment

        Working...