Command skewness(x) vs calculating sample skewness by hand

조회 수: 14 (최근 30일)
Benedikt Gasparic
Benedikt Gasparic 2018년 10월 28일
편집: John D'Errico 2018년 10월 28일
Task is to calculate sample skewness(x) by hand in Matlab to show that you understand the mathematical concept aka:
My solution was: skewness_x=((1/numel(x))*(sum((x-mean(x)).*(x-mean(x)).*(x-mean(x))))/(std(x)^3)) except this value is 3*10^-4 off the value which i get from skewness(x).
(x being a (1,300) vektor with 300 random values)
Did i make a mistake in my formula? Or does Matlab round somewhere?

채택된 답변

John D'Errico
John D'Errico 2018년 10월 28일
편집: John D'Errico 2018년 10월 28일
This is not a rounding issue.
The answer is almost always to check the docs for the function in question.
doc skewness
If you do read that doc, in the algorithms section, you will quickly see that skewness does something slightly different. That difference probably comes about because of a degrees of freedom thing. Think of it like this: when you compute the SAMPLE standard deviation, it needs to use the mean, as if the mean were known. So a sample standard deviation (what you get from std(x,0), or just the default std(x)) has a factor if 1/sqrt(n-1) in there, instead of 1/sqrt(n). This is the classically seen difference between a population estimator versus a bias corrected sample standard deviation.
But when you compute skewness, it also uses the sample standard deviation. So skewness(x,0) needs to tweak those factors of n in the formula to give a bias corrected estimator.

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by