473,327 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

fonction ecarttype en php

mat
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($datas);

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

function ecarttype($array, $nbdecimals=2) {

if (is_array($array))
{
//moyenne des valeurs
reset($array);
$somme=0;
$nbelement=count($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;
}
}

Aug 29 '05 #1
3 3678
mat wrote:
Je l'ai cherché partout, je ne l'ai pas trouvé, alors je l'ai
écrite.

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

<snip>

Thanks. Would be nice, if you could use English in future. Got it
translated with Google:
<Google translation
url="http://translate.google.com/translate?u=http://groups.google.com/group/comp.lang.php/msg/b4524aca9cf1ca5d&langpair=fr%7Cen&hl=en&ie=UTF8">

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

If that can be used for others...

echo "Calculation of a standard deviation";
echo "< Br >";

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

$$ecart = ecarttype($datas);

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

else
{
echo "incoherent Set of values!";

}

function ecarttype($array, $$nbdecimals=2) {

yew (is_array($array))
{
// average of the values
reset($array);
$$somme=0;
$$nbelement=count($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/

Aug 30 '05 #2
On Tue, 30 Aug 2005 07:33:03 -0700, R. Rajesh Jeba Anbiah wrote:
mat wrote:
Je l'ai cherché partout, je ne l'ai pas trouvé, alors je l'ai
écrite.

Si ça peut servir Ã* d'autres ...

<snip>

Thanks. Would be nice, if you could use English in future. Got it
translated with Google:
<Google translation
url="http://translate.google.com/translate?u=http://groups.google.com/group/comp.lang.php/msg/b4524aca9cf1ca5d&langpair=fr%7Cen&hl=en&ie=UTF8">

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

If that can be used for others...

echo "Calculation of a standard deviation";
echo "< Br >";

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

$$ecart = ecarttype($datas);

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

else
{
echo "incoherent Set of values!";

}

function ecarttype($array, $$nbdecimals=2) {

yew (is_array($array))
{
// average of the values
reset($array);
$$somme=0;
$$nbelement=count($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>

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
Aug 31 '05 #3
Hello,

on 08/30/2005 11:09 PM Christopher Pomasl said the following:
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.


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

http://www.phpclasses.org/probabilistic
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Aug 31 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Philippe Mesmeur | last post by:
J'ai eu une longue discussion hier au sujet des parametres de fonction const. La personne etait pour mettre "const" devant TOUS les parametres ne devant pas etre modifies. A mon avis, il faut...
1
by: Aurélien REGAT-BARREL | last post by:
Bonjour, dans mon programme j'ai défini le type SmartPtr ainsi : #include <boost/shared_ptr.hpp> template<typename T> struct SmartPtr { typedef boost::shared_ptr<T> Type ;
3
by: Chris | last post by:
function Main(param) { alert("test "+param); <<<<<<<<<<< Ici tout se passe bien : le contenu de param est bien affiché fchaine='' .... +'<div ><a href="#" onclick="javascript:return...
8
by: Jean-Marc Blaise | last post by:
Dear all, It seems there is a problem with some snapshot table functions, if you try to divide by some element that is unset or equal to 0. This generates a trap file with the db2fmp.exe...
0
by: Jenny C. | last post by:
Hi I am trying to do a SUM on a DataSet column with the following code // ds is the DataSet that I need to calculate data fro String filter2 = "EmpNo = " + this.EmpNo + " AND WEEK_ENDING >= '"...
8
by: jean-jeanot | last post by:
I am writing a prototype program whose aim is to collect bookkeeping transactions in a Database ( Gadfly). After creating the table I create the variables with varAmount = StringVar() I then...
6
by: aliassaf | last post by:
Hello, If we write = x^2 and if I give to the program the values of x, it will going to calculate the values of y, and also for x. But it is possible ? that is if I give to the program the...
2
by: alexandre.suc | last post by:
Bonjour Je désire utiliser un str_replace sur une variable qui contient le résultat d'une commande system(). Bizarrement le STR_REPLACE semble sans effet exemple de mon code $entree =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.