Clear Filters
Clear Filters

which function I can use?

1 view (last 30 days)
yue li
yue li on 31 Aug 2018
Edited: yue li on 1 Sep 2018
Hello,
There are two matrices.
I want to calculate the p value of each row.
>> x
x =
0.3192 1.0933 -0.0068 -1.0891 -1.4916
0.3129 1.1093 1.5326 0.0326 -0.7423
-0.8649 -0.8637 -0.7697 0.5525 -1.0616
-0.0301 0.0774 0.3714 1.1006 2.3505
-0.1649 -1.2141 -0.2256 1.5442 -0.6156
0.6277 -1.1135 1.1174 0.0859 0.7481
>> y
y =
-0.1924 -0.1774 -0.8045 -1.1480 -0.0825 0.1001 1.7119
0.8886 -0.1961 0.6966 0.1049 -1.9330 -0.5445 -0.1941
-0.7648 1.4193 0.8351 0.7223 -0.4390 0.3035 -2.1384
-1.4023 0.2916 -0.2437 2.5855 -1.7947 -0.6003 -0.8396
-1.4224 0.1978 0.2157 -0.6669 0.8404 0.4900 1.3546
0.4882 1.5877 -1.1658 0.1873 -0.8880 0.7394 -1.0722
function [P] = p_row(x,y)
x1=size(x,1);
y1=size(y,1);
for i=1:x1
if lillietest(x(i,:)) == 1
P(i)=ranksum(x(i,:),y(i,:));
elseif lillietest(y(i,:)) == 1
P(i)=ranksum(x(i,:),y(i,:));
elseif vartest2(x(i,:),y(i,:)) == 1
P(i)=ranksum(x(i,:),y(i,:));
else
[tmpH,tmpP]=ttest2(x(i,:),y(i,:));
P(i)=tmpP(1);
end
end
>> p=p_row(x,y)
p =
0.7961 0.2773 0.1490 0.1877 0.6335 0.6010

Accepted Answer

yue li
yue li on 31 Aug 2018
Edited: yue li on 31 Aug 2018
Hello, Star Strider,
Thank you for your response!
1. I want to calculate the p value of each row in two matrics.
2. I prefer to use ttest2().
3. If the values in each row are not normal distribution, I have to use ranksum().
4. If the values of each row in two matrics are not equal variance, I have to use ranksum().
My output is shown above.
How can I only have the last line of output?
Thank you so much for your help!
Yue

More Answers (0)

Community Treasure Hunt

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

Start Hunting!