IDL, Mathematics

Standard Deviation in IDL

The built in IDL standard deviation function in IDL, STDDEV, uses the moment function which treats the standard deviation as a sample, rather than a population. A short programme can give us both options. 


When calculating the standard deviation of a set of numbers you either use, \[s_N=\sqrt{\frac{1}{N}\sum_{i=1}^N (x_i-\bar{x})^2},\] if you are calculating for an entire population, or \[s_N=\sqrt{\frac{1}{N-1}\sum_{i=1}^N (x_i-\bar{x})^2},\] if using a sample population using Bessel’s correction.

In IDL the built in STDDEV function always calculates using Bessel’s correction, i.e. it divides by \(N-1\).

A short programme to fix this is: SD.pro

SD is called in the same way as STDDEV, but if you add the /POP keyword then it calculates for an entire population rather than a sample. Without the keyword it is just a wrapper for the STDDEV programme.

Related post

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.