# Possible to Solve a LocationEquivalenceTest?

I have 5 groups, each containing around 20 elements. These elements are all dependent on x. For example: Set1 = {1.5x + 1, 2x + 0.5, 1 x + 1, ...} etc. Now, I want to compare these 5 groups and see if there is a significant difference between one or more of these groups (for 0 < x < 1). As my data does not follow normal distribution, I use the Kruskal-Wallis test.

To try and visualise this, I plugged this into Mathematica

Plot[LocationEquivalenceTest[{Set1, Set2, Set3, Set4, Set5}], {x, 0, 1}]


which, unexpectedly, gives a nice plot of the p-value set out over x. Now, I want to determine for what values of x the p-value is <0.05, so I thought that, since the Plot worked out nicely, I might be able to achieve that by using

Solve[LocationEquivalenceTest[{Set1, Set2, Set3, Set4 ,Set5}] == 0.05, x]


Unfortunately, that just gives me a bunch of errors saying that

The argument list of the elements of set1 at position 1 should be a list containing two or more vectors of real numbers with length greater than 2.

Is there a function in Mathematica that does allow me to determine for which values of x the p-value would be 0.05?

-

First I'll generate some data in the spirit of what you show.

sets = Table[RandomChoice[x Range[1, 2, .5], 20] +
RandomChoice[Range[0, 1.5, .5], 20], {i, 5}
];


The issue you are having is a very common one. You must require that only numbers get tried for x if you want this to work because LocationEquivalenceTest cannot work symbolically.

Here I create a function f which requires numeric input. I've also restricted it to use a particular test and avoid testing assumptions. This will make things much faster and the resulting curve will be smoother since it won't pick different tests for different values of x.

f[z_?NumericQ] := LocationEquivalenceTest[sets/. x -> z,
"KSampleT", VerifyTestAssumptions -> None]


Before looking for the place where the curve is 0.05 we should visually verify that this is expected to occur.

Plot[f[x], {x, -5, 5}]


Now use FindRoot to determine the actual value.

FindRoot[f[x] == 0.05, {x, 0}]

(* {x -> -0.68174} *)


We should verify that it found the right value...

f[%[[1, 2]]]

(* 0.05 *)

-
Your solution does work, but in your example you defined the LocationEquivalencTest as being a k-sample T-test, whereas I need to use the Kruskal-Wallis test. When applying the rest of your solution with it defined as a Kruskal-Wallis test, using FindRoot gives the error FindRoot::jsing : Encountered a singular Jacobian at the point {x} = {5.69181x10^-6}. Try perturbing the initial point(s). –  LPAS Jul 10 '13 at 10:40
Notice if you set the test to "KruskalWallis" the curve is a step function. It is unlikely that the p-value will ever be exactly 0.05 in this case and it isn't surprising that FindRoot would complain. –  Andy Ross Jul 10 '13 at 13:14
This is true, and in the end I found the cut-off point by simple trial and error. Thanks so much for your input though! –  LPAS Jul 10 '13 at 13:15