Home arrow PHP arrow Page 4 - Performing Descriptive Statistical Analysis with PHP

Performing calculations with PHP - PHP

Have you ever thought of doing statistical analysis using PHP? Well, as simple as this technology can be, it enables an analyst to do server-side scripting commands which accept data from a web form, and then analyze the data in the server using PHP.

TABLE OF CONTENTS:
  1. Performing Descriptive Statistical Analysis with PHP
  2. Computing descriptive statistics using PHP
  3. Detailed explanation of the scripts
  4. Performing calculations with PHP
By: Codex-M
Rating: starstarstarstarstar / 2
October 06, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

For the average:

return array_sum($data)/count($data);

The above formula computes the total sum of values contained in the array variable, and then divides by the total amount of data in the array.

The standard deviation function is rare in PHP, and very tricky:

function stdev($data){

$average = average($data);

foreach ($data as $value) {

$variance[] = pow($value-$average,2);

}

$standarddeviation = sqrt((array_sum($variance))/((count($data))-1));

return $standarddeviation;

}

Statistical formula:

There is no built-in PHP function for standard deviation currently supported by a lot of PHP programmers, so a user-defined function is more suitable for doing the computation.

First it gets the average of the data contained in the array, and then it will loop the square of the difference between each piece of data and the array average (this is called statistical variance). Finally, all of the variances are added, and then divided by total number of data minus 1.

The easier approach could be to use average instead of

array_sum($variance)/((count($data))-1)

However, it is not accurate because it is NOT actually the "sample" standard deviation. In statistical literature, there are two types of standard deviation, population and sample. If we use the population standard deviation, we can directly use the average instead of the above parameter; however, most scientific experiments are done with sampling.

If we are able to conduct an analysis, the scripts shown earlier in this article will produce a result like the one below:

It will show the summary statistics along with the data analyzed. To see this in action, you can go to:

http://www.php-developer.org/descriptivestats.php

If you would like to download/copy the script, you can go to:

http://www.php-developer.org/wp-content/uploads/scripts/descriptivestats.txt



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: