Showing posts with label population deviation. Show all posts
Showing posts with label population deviation. Show all posts

Saturday, April 16, 2022

Population vs Standard: Deviation and Covariance

 Population vs Standard: Deviation and Covariance



Population Deviation vs Standard Deviation


How is the population deviation related to the standard deviation?


Population Deviation (of a data set x_i):


σx = √( Σ(x_i - mean(x)) / n)


where mean(x) is the arithmetic mean of the data set over x_i


Standard Deviation:


sx = √( Σ(x_i - mean(x)) / (n - 1))


n is the size of the data set x_i.  


Suppose we can calculate the standard deviation by multiplying a factor (let's call it ß for the purpose of this example) to the population deviation.   


ß * σx = sx


ß * √( Σ(x_i - mean(x)) / n) = √( Σ(x_i - mean(x)) / (n - 1))


ß  * √( Σ(x_i - mean(x))) /  √n = √( Σ(x_i - mean(x))) / √(n - 1)


ß * √( Σ(x_i - mean(x)))  / √( Σ(x_i - mean(x))) = √n / √(n - 1)


ß  = √n / √(n - 1)


ß  = √(n/(n - 1))


Hence:


sx =  √(n/(n - 1)) * σx


and


σx = sx * √((n-1)/n)



Example:


x = {4, 7, 10, 16, 38}   

n = 5


σx = 12.16552506

sx = 12.16552506 * √(5/4) = 13.60147051



Population Covariance vs Standard Covariance


For the data sets x_i and y_i, population covariance:


cov_σ = 1/n * Σ((x_i - mean(x)) * (y_i - mean(y)))


And the sample covariance:


cov_s = 1/(n - 1) * Σ((x_i - mean(x)) * (y_i - mean(y)))


We will use the similar tactic above to find a relationship between population covariance and sample covariance:


ß * cov_σ = cov_s


ß * 1/n * Σ((x_i - mean(x)) * (y_i - mean(y))) = 

1/(n - 1) * Σ((x_i - mean(x)) * (y_i - mean(y)))


ß * Σ((x_i - mean(x)) * (y_i - mean(y))) / Σ((x_i - mean(x)) * (y_i - mean(y))) =

n/(n - 1)


ß = n/(n - 1)



Hence:


cov_ s = n/(n - 1) * cov_σ 


and


cov_σ = (n - 1)/n * cov_s



Example:


x = {4, 5, 6, 8}

y = {-2, -1, 2, 0}

n = 4


mean(x) = 5.75

mean(y) = -0.25


cov_σ = 1.1875

cov_s = 1.1875 * 4/3 = 1.5833333333


Hope you find this helpful,


Eddie 


All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Sunday, December 8, 2019

HP 71B: Population Deviation Derivation and Program

HP 71B:  Population Deviation Derivation and Program 

Derivation

The standard formula for the population deviation for a set of statistical data is given by:

σx = √( Σ(x - μ)^2 / n)

where μ is the mean, where μ = Σx / n

Σx = the sum of all the data points
 n = the number of data points

If this function needs to be programmed, using the definition as will probably require the use of two FOR structures: one for the mean, and one for the deviation.  Is there a way to use a formula where a FOR structure can be saved?

Turns out, the answer is yes. 

σx = √( Σ(x - μ)^2 / n)
= √( Σ(x^2 - 2*x*μ + μ^2) / n)

Note that:
Σ( f(x) + g(x) ) = Σ f(x) + Σ g(x)
For a constant, a:   Σ( a * f(x) ) = a * Σ f(x)
And:  Σ a = a * n   (sum from 1 to n)

Then:

σx = √( Σ(x - μ)^2 / n)
= √( Σ(x^2 - 2*x*μ + μ^2) / n)
= √( (Σ(x^2) -  2*μ*Σx + Σ( μ^2 )) / n)
= √( (Σ(x^2) -  2*μ*Σx + n*μ^2) / n) 
= √( (Σ(x^2) -  2*Σx*Σx/n + n*(Σx)^2/n^2 ) / n) 
= √( (Σ(x^2) -  2*(Σx)^2/n + (Σx)^2/n) / n)
= √( (Σ(x^2) -  (Σx)^2/n ) / n)

The above formula allows to use a sum and sum of square of data points in calculating population deviation, eliminating the need for an additional FOR structure. 
 
Standard deviation follows a similar formula:
sx = √( (Σ(x^2) -  (Σx)^2/n ) / (n - 1))

HP 71B Program:  Population Deviation

File:  PDEV
20 N=0
22 A=0
24 B=0
30 INPUT "X? ";X
40 N=N+1
50 A=A+X
60 B=B+X^2
70 INPUT "DONE? NO=0"; C
80 IF C=0 THEN 30
90 M=A/N
95 S=SQR((B-A^2/N)/N)
100 DISP "MEAN= ";M
105 PAUSE
110 DISP "PDEV= ";S
120 END

Example

Data Set:  150, 178, 293, 426, 508, 793, 1024

MEAN = 481.7142857
PDEV = 300.6320553

Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...