Standard Deviation result wrong or right

54 Views Asked by At

I made two scripts in PHP to calculate the standard deviation. But I am not sure if it works correctly both of my scripts have different results.

first script 1,2,3,4,5,1 = 1.5

second script 1,2,3,4,5,1 = 1.49

or are both wrong if so please tell me what the standard deviation is. Thanks!

2

There are 2 best solutions below

1
On BEST ANSWER

The average of your data is $$ \bar x = \frac{1+2+3+4+5+1}{6}=\frac83.$$ Thus $$s_n^2=\frac1n\sum(x_i-\bar x)^2= \frac16\left(\frac{25}{9}+\frac49+\frac19+\frac{16}9+\frac{49}{9}+\frac{25}{9}\right)=\frac{20}{9}$$ and $$s_{n-1}^2=\frac1{n-1}\sum(x_i-\bar x)^2=\frac 83.$$ This makes $$s_n\approx 1.4907\qquad s_{n-1}\approx 1.63299 $$ It seems you are calculating $s_n$ and just use different rounding.

1
On

With these few values, you can just run the calculation by hand. Alpha gives $\frac {2\sqrt 5}3 \approx 1.4907$