Summary Statistics Table by group

108 ビュー (過去 30 日間)
mo
mo 2018 年 10 月 25 日
回答済み: Steven Lord 2018 年 10 月 25 日
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 件のコメント
jonas
jonas 2018 年 10 月 25 日
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.

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

回答 (2 件)

jonas
jonas 2018 年 10 月 25 日
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 2018 年 10 月 25 日
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.

Community Treasure Hunt

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

Start Hunting!

Translated by