필터 지우기
필터 지우기

Another simple question about standard deviation!

조회 수: 2 (최근 30일)
Helen Kirby
Helen Kirby 2017년 1월 8일
댓글: Helen Kirby 2017년 1월 8일
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.

채택된 답변

John D'Errico
John D'Errico 2017년 1월 8일
편집: John D'Errico 2017년 1월 8일
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
Helen Kirby
Helen Kirby 2017년 1월 8일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by