473,545 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($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;
}
}

Aug 29 '05 #1
3 3692
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.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/

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.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>

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
5221
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 le faire que SI le parametre est un pointeur ou une référence. int fct1(const int* i);
1
1800
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
2833
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 Suite('+param+');"><IMG src="tg.gif" ></a></div>' .... document.write(fchaine); }
8
2980
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 process, that keeps going on, until your disk is full. I'm on W2K, DB2 UDB 8.1 FP4. Test case: db2start
0
1175
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 >= '" + MyDateTime.Date.ToShortDateString() + "'" float totalGross = Convert.ToSingle(this.ds.Tables.Compute("SUM(GROSS)", filter2)) float totalEarn =...
8
1388
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 create labels in Tkinter to ease the input of data. With a function def treatment (): requete = "insert into transactions ( date,amount,,....)...
6
1454
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 values of X and Y, it will indicate to me the relation between the two variables, in the other hand if I look to the program x=2 y=4, x=3 y=9 ect......
2
1449
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 = system('ls') ;
0
7473
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7408
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7661
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7433
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1020
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
712
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.