Command skewness(x) vs calculating sample skewness by hand

20 vues (au cours des 30 derniers jours)
Benedikt Gasparic
Benedikt Gasparic le 28 Oct 2018
Modifié(e) : John D'Errico le 28 Oct 2018
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?

Réponse acceptée

John D'Errico
John D'Errico le 28 Oct 2018
Modifié(e) : John D'Errico le 28 Oct 2018
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.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by