grpstats flexibility for additional functions

2 vues (au cours des 30 derniers jours)
Brian
Brian le 6 Mar 2015
Commenté : Brian le 9 Mar 2015
Hi, I am just wondering if the grpstats function can be used with things other than the standard formulas listed on the help page. A perfect example would be if I wanted population standard deviation instead of the canned sample standard deviation. This would then extend to personally written functions as well.
Grpstats appears to be an extremely useful function for statistical analysis if it is indeed more flexible than what I'm see in the help file.
Any advice or alternative recommendations for calculating statistics by group would be greatly appreciated.
Thanks much, Brian

Réponse acceptée

Brendan Hamm
Brendan Hamm le 6 Mar 2015
If you look at the documentation the input variable whichstats can be a function handle. So for your example of the population standard deviation we can do the following:
x = rand(50,1); % Make some random data.
grpVar = logical([ones(25,1);zeros(25,1)]); % Split data into 2 groups
popStd = @(y) std(y,1); % make a function handle that computer pop. std.
myStats = grpstats(x,grpVar,popStd);
Using this method, you can make your own statistical functions. Also the list of stats given in the doc is not exhaustive. For example:
myKurt = grpstats(x,grpVar,'kurtosis');
returns the kurtosis of the groups.
  1 commentaire
Brian
Brian le 9 Mar 2015
Perfect, exactly what I was looking for. Thank you sir.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by