Another simple question about standard deviation!

3 views (last 30 days)
Could I ask yet another question on the theme of standard deviation? - and yes I have read the documentation and it doesn't answer this question. Say if you have: x = [1,2,3,4,5,6] and w = [5,7,10,8,12,3] and I want to find the weighted std for a population, how do I write the command for a POPULATION? I understand for a sample it is:
StdSamp = std(x,w) If you put 1 as the 3rd parameter, it does not interpret it as pop.

Accepted Answer

John D'Errico
John D'Errico on 8 Jan 2017
Edited: John D'Errico on 8 Jan 2017
std automatically assumes you are doing this for a complete population, NOT as a sample. When you are not sure about something, the best way is to test it! So, how can we test my claim? How might you have done so, and gotten an answer 6 hours earlier?
X = rand(1,5);
First, what does std do, with no weights employed?
std(X)
ans =
0.32851
std(X,1)
ans =
0.29383
So as one should expect, the two are different, by a ratio of
sqrt(5)/2
ans =
1.118
std(X)/std(X,1)
ans =
1.118
That is as expected. std(X) divides by sqrt(n-1) in the formula, but std(X,1) divides by sqrt(n).
Now, lets see what happens when we use weights. A very simple weight vector is sufficient here.
W = ones(1,5);
std(X,W)
ans =
0.29383
This is the population standard deviation, as produced by std(X,1).
std(X,1)
ans =
0.29383
The point is, it makes no sense at all to talk about a sample standard deviation when you have weights. Well, relatively little sense. Given a set of weights, we can only interpret this as the entire population.
I will concede that the documentation (both doc and help) for std should have made this fact explicitly clear, even though it seems clear to me regardless, since the alternative makes no sense. If you have weights, the points are treated as a complete population.
std(X,W,0)
Error using size
Dimension argument must be a positive integer scalar within indexing range.
Error in var (line 109)
n = size(x,dim);
Error in std (line 51)
y = sqrt(var(varargin{:}));
std(X,0,W)
Error using size
Dimension argument must be a positive integer scalar within indexing range.
Error in var (line 109)
n = size(x,dim);
Error in std (line 51)
y = sqrt(var(varargin{:}));
Yep. std agrees with me.
  1 Comment
Helen Kirby
Helen Kirby on 8 Jan 2017
Thank you very, very much, an excellent answer. I was not aware that weights only apply to total populations. If you take exam scores for a whole school (a population) and you give weights to, let's say, homework(10%),project(30%),finals(60%), and apply those rules to every class in the school is not one class a sample and the whole school a population? That is the scenario which confused me. But anyway, I will remember your answer, and thank you again.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!