# 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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.5893948674201965, "perplexity": 826.1108574719899}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-10/segments/1393999651529/warc/CC-MAIN-20140305060731-00010-ip-10-183-142-35.ec2.internal.warc.gz"}