ranksum returns NaN when comparing two vectors with a single identical entry when sum of lengths is greater than 20

1 次查看(过去 30 天)
I'm running a ranksum hypothesis test on multiple vectors.
Each test takes a column of a matrix and compares the top third to the rest of the column
ranksum(col(1:500),col(501:1500))
This is fine except when the column has only a single entry; it then returns NaN.
Consider the following simple example:
x=ones(20,1); y=ones(20,1); ranksum(x,y)
NaN
BUT I've noticed the following returns the expected result
x=ones(9,1); y=ones(9,1); ranksum(x,y)
ans = 1
I may be misunderstanding something about the way ranksum is calculated. Thanks in advance.
R2012b (64bit)

回答(2 个)

Andrew Reibold
Andrew Reibold 2013-6-3
编辑:Andrew Reibold 2013-6-3
Hello Connor,
This is because the method of calculation changes depending on your inputs. (Exact Solution, Approximate Solution, or Old Exact Solution)
First it checks your inputs to see if needs to used the Old Exact solution which is a solution method that was more or less grandfathered in to this modern version of the function.
Aside from that
.
If the number of elements in both X and Y vectors combined is GREATER THAN 20
AND IF
One of the vectors has less than 10 elements
.
Then the EXACT method is used.
If it doesnt not meet these criteria, the Approximation method is used.
The exact details can be a bit lengthy, but if you want to see exactly how they are calculating it, go to the command window and type:
open ranksum
I hope his helps!
-Andrew

Conor
Conor 2013-6-4
Thanks for the answer, Andrew. I'll open it up and have a look. I'll post if I figure out a solution, for future reference.
-Conor

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by