How to calculate skewness & kurtosis ?

165 ビュー (過去 30 日間)
Mr LE
Mr LE 2015 年 2 月 1 日
コメント済み: SUBHASMITA DASH 2022 年 5 月 31 日
Hi,
I would like to calculate the third and fourth moment with returns data (matrix 1x132)
Do you know the function that can I use for that?
Thanks!

回答 (2 件)

Star Strider
Star Strider 2015 年 2 月 1 日
編集済み: Star Strider 2015 年 2 月 1 日
If you have the Statistics Toolbox, you can calculate the skewness and kurtosis directly with their respective functions.
If you don’t have the Toolbox, it would be relatively easy to code those functions:
skewns = @(x) (sum((x-mean(x)).^3)./length(x)) ./ (var(x,1).^1.5);
kurtss = @(x) (sum((x-mean(x)).^4)./length(x)) ./ (var(x,1).^2);
These work for numeric vectors.
P.S. — Are your data double arrays or cells? If cells, you’ll likely have to use cellfun or cell2mat to work with any of these functions.
  2 件のコメント
Nidhi Singh
Nidhi Singh 2022 年 2 月 11 日
@(x) showing me function handle .. But didn't show any values
Star Strider
Star Strider 2022 年 2 月 11 日
Perhaps evaluating the functions with an argument vector would work?
skewns = @(x) (sum((x-mean(x)).^3)./length(x)) ./ (var(x,1).^1.5);
kurtss = @(x) (sum((x-mean(x)).^4)./length(x)) ./ (var(x,1).^2);
x = randn(1, 5000);
sk = skewns(x)
sk = 0.0412
kt = kurtss(x)
kt = 3.0302
.

サインインしてコメントする。


Image Analyst
Image Analyst 2015 年 2 月 1 日
I have code where I do it from the histogram. You could easily adapt it to handle data not from a histogram. See the function at the bottom of the attached file. Let me know if you can't figure it out.

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by