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 CenterFile Exchange에서 Workspace 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