# Q-Test in mathematica

I want to use the Q-test to determine outlier in my dataset. However, I cannot find a function to do this is in Mathematica. Does anyone know if there is a function which does this in Mathematica?

Thanks.

-
Maybe you could describe the $Q$-test a little? –  Dilip Sarwate Jan 20 '12 at 22:42
Not my idea of recreational mathematics, so I'm re-tagging as statistics. Maybe there's a better tag. –  Gerry Myerson Jan 20 '12 at 23:05
@GerryMyerson If $Q$ means the complementary Gaussian cumulative distribution function, probability distributions and normal distribution might also be appropriate tags. –  Dilip Sarwate Jan 21 '12 at 1:50
@Dilip, go for it. OP can always change it if it's wrong. –  Gerry Myerson Jan 21 '12 at 2:10
Did you mean the Dixon Q-test? –  Ｊ. Ｍ. Jan 26 '12 at 11:47

## 1 Answer

If it's Dixon's Q-test that you are referring to, it's not too hard to compute the statistic; it's the CDFs and quantiles that are a bit troublesome to do. As can be seen here, the formulae for the CDF are rather complicated, which is why Rorabacher just chooses to use spline interpolation on pretabulated values (which I presume were a bit difficult to generate). I am however told that the use of Dixon's test and other such procedures is passé, however.

Anyway, as I said the statistic itself is not too hard to compute:

qstat[data_?VectorQ, mode : Min | Max] :=
With[{sd = Sort[data]}, (#2 - #1) & @@
Take[sd, 4 Boole[mode === Min] - 2]]/(Max[data] - Min[data])


Choose mode as Min or Max, depending on whether you want to test the lowest value or the highest one as an outlier. Remember that once you've decided to remove one, it is poor form to reapply the test on the edited data.

-