How to use prctile within grpstats?

조회 수: 6 (최근 30일)
NT
NT 2014년 9월 29일
편집: Nalini Vishnoi 2014년 10월 1일
Hi, I am trying to find the 5th, 25th, 50th (median), 75th and 95th percentiles for a few different groups in a dataset but unable to do so using grpstats.
fundpercentiles = grpstats(DDD, 'fund', prctile(DDD.pl_vwap_bps, [5 25 50 75 95]), 'DataVars', 'pl_vwap_bps');
Warning: Out of range or non-integer values truncated during conversion to character. > In stats\private\dsgrpstats at 116 In grpstats at 135 Error using dsgrpstats (line 142) WHICHSTATS must be a function handle or name, or a cell array of function handles or names.
Error in grpstats (line 135) [varargout{1:nargout}] = dsgrpstats(x,group,whichstats,varargin{:});

답변 (1개)

Nalini Vishnoi
Nalini Vishnoi 2014년 10월 1일
편집: Nalini Vishnoi 2014년 10월 1일
I understand that you are trying to compute the percentiles on the values grouped using a column. The general syntax of 'grpstats' looks like the following:
statarray = grpstats(tbl,groupvar,whichstats,Name,Value)
where whichstats is the summary statistics to compute, specified as a string or function handle, or a cell array of strings and function handles.
To compute the percentile using grpstats, you need to provide a handle to the 'prctile' function. For example:
x = rand(10,1);
l = logical([zeros(5,1); ones(5,1)]);
stats = grpstats(x, l, @(y) prctile(y, [5 25 50 75 95]'));
This seems to work for me. I hope this solves your issue as well.

카테고리

Help CenterFile Exchange에서 Repeated Measures and MANOVA에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by