How to use ranksum with splitapply?

1 回表示 (過去 30 日間)
Filipa Torrao
Filipa Torrao 2019 年 10 月 20 日
回答済み: Asvin Kumar 2019 年 10 月 29 日
Hi everybody!
I just started with Matllab last week. I am trying to use the ranksum function with splitapply in order to get the p-value for my 2 different groups, but it is not working. Basically I have an excel file where the first column has a set of on/off parameters and on the 18th column I have the values I want to analyse. I want to get the p-value between on and off values (see below)
Column 1 Column 18
ON 4.3
OFF 7.2
OFF 5.6
ON 8.9
OFF 3.7
(etc) (etc)
I want to get the p-value between datasets [4.3, 8.9] and [7.2 , 5.6 , 3.7], any idea on how to do this?
Thanks in advance!
[num,text,raw]=xlsread('d1_m2_filipa.xlsx');
i=text(:,1);
o=[1:length(y)];
w=[2:length(i)];
k=text(w,1);
y=num(:,18);
grpNums=findgroups(k);
q=splitapply(@mean,y,grpNums);
err=splitapply(@std,y,grpNums);
d=splitapply(@jbtest,y,grpNums);
e=0;
if d==0
e=splitapply(@ranksum,y,grpNums)
else e=0
end

回答 (1 件)

Asvin Kumar
Asvin Kumar 2019 年 10 月 29 日
The splitapply function applies the function mentioned as an argument to each group. For the ranksum function we would need to provide two sets of data. We can provide these by partitioning the data using findgroups.
You can use the following code for reference and adapt it to your use case:
[grpNums, grps] = findgroups(k);
off = y(k==grps(1));
on = y(k==grps(2));
[p,h] = ranksum(on,off);
Here’s the documentation of findgroups for reference:

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by