Azzera filtri
Azzera filtri

Another simple question about standard deviation!

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

John D'Errico
John D'Errico il 8 Gen 2017
Modificato: John D'Errico il 8 Gen 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 Commento
Helen Kirby
Helen Kirby il 8 Gen 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by