How to calculate skewness & kurtosis ?
168 次查看(过去 30 天)
显示 更早的评论
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
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 个评论
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)
kt = kurtss(x)
.
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!