Summary Statistics Table by group

36 vues (au cours des 30 derniers jours)
mo
mo le 25 Oct 2018
Hi,
I'm new in Matlab and I'm completely lost. I would like to create a table of summary statistics (mean, median, mode, std, max, min, skewness, kurtosis) of different caracteristics such as Common Equity Tier 1 ratio, Leverage ratio..... I imported my data form my excel folder. I already create and define my variables.
Here is my code : %Create and define my date data.return1018=data.data(:,1); data.return1w=data.data(:,2); data.LVGR0617=data.data(:,3); data.CET1R0617=data.data(:,7); data.TLRE0617=data.data(:,11); data.NPA0617=data.data(:,25); data.OBS0617=data.data(:,27);
dsa=({'data.CET1R0617', 'data.LVGR0617', 'data.NPA0617', 'data.OBS0617', 'data.return1w', 'data.return1018'})
statarray = grpstats(dsa,{'mean','median','mode','std','min','max','skewness','kurtosis'})
The problem is that my group stats doesn't work... and I really don't know why.
Thank you in advance for your help,
  1 commentaire
jonas
jonas le 25 Oct 2018
Well, your syntax is wrong and it's not possible to help you with the limited information you have provided. What is dsa? Why is the table not passed to the function? Are all your variables numeric?
Would be easier if you just uploaded your table.

Connectez-vous pour commenter.

Réponses (2)

jonas
jonas le 25 Oct 2018
You need to pass the table as input to grpstats. Assuming that dsa is a cell array with grouping variables, then change your code as follows:
dsa = {'CET1R0617', 'LVGR0617', 'NPA0617', 'OBS0617', 'return1w', 'return1018'}
statarray = grpstats(data,dsa,{'mean','median','mode','std','min','max','skewness','kurtosis'})

Steven Lord
Steven Lord le 25 Oct 2018
Instead of reading your data into a matrix and post-processing to create a struct from that matrix, consider using readtable to read the data directly into a table array.
Once you have your data in a table use groupsummary with one or more of your table variables as a grouping variable, or use findgroups and splitapply, or depending on the specific summary statistics you want to generate call summary on the table.

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by