Command skewness(x) vs calculating sample skewness by hand

14 次查看(过去 30 天)
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