header image

Standard Deviation

Posted by: | July 12, 2011 | No Comment |

Another simple calculation in PowerShell

function get-standarddeviation {            
param (            
$avg = $numbers | Measure-Object -Average | select Count, Average            
$popdev = 0            
foreach ($number in $numbers){            
  $popdev +=  [math]::pow(($number - $avg.Average), 2)            
$sd = [math]::sqrt($popdev / ($avg.Count-1))            

Get the numbers. Calculate the average as we saw last time.

Sum the square of the differences between each value and the mean.  Divide by the number of samples minus 1 (corrects fro assumption we are dealing with a sample) and then take square root.

under: Math, PowerShell Basics