1
votes

I want to do something very simple in MATLAB. I want to calculate the population standard deviation (i.e. I want the denominator n instead of n-1 as reviewed here).

The MATLAB default is to calculate the sample standard deviation. As in this example:

example = [0.555158185377949    0.572544871140911   0.566844451709150   0.585793022458150   0.577877363402946   0.564285735627449   0.582162844985863   0.576409646607226   0.583718583332482   0.577417064869028]
std(example)
ans =
     0.0096

For MuPad, it appears that adding 'Population' should give me the population standard deviation. In MATLAB, adding 'Population' does give a result different from plain std():

test1=std(example,'Population')
test1 =
       0.0087

But that result does not seem to be the same as the square root of the population variance:

sqrt(var(example,1))
ans =
    0.0091

Note that the 'sample' standard deviation does equal the square root of the 'sample' variance, as you would expect:

sqrt(var(example))
ans =
     0.0096
std(example)
ans =
     0.0096

So the problem is just for population standard deviation. Am I missing something? Is there a MATLAB command to give the population standard deviation (instead of the sample standard deviation)? Or do I always need to take the square root of the population variance to calculate population standard deviation?

1
Have you read the documentation for std? By default, std normalizes by N-1 (var too), not N as you seem to be stating. Switching between the two is just a matter of reading the documentation. Matlab and MuPAD are two separate environments – the functions and documentation are distinct so look at whichever is relevant to you. - horchler
Thanks @horchler. I did read the documentation for std for my version of Matlab (R2014b). It does not say now to normalize by N (which is what I want) instead of N-1. - user2860703
I'm not sure what you mean by "It does not say now to normalize by N". Here's the archived documentation specific to R2014b – normalization is discussed right in the description. Using help std will show you something similar. - horchler
Thanks @horchler. Sure enough, it is there. I somehow missed it the first five times I read that documentation! I'll add the solution below in case it is useful to someone else. - user2860703

1 Answers

0
votes

The 'flag' determines whether you use the sample standard deviation (normalized by n) or population standard deviation (normalized by n-1).

std(example,1)

ans =

    0.0091

Which is the same as sqrt(var(example,1)).