Dixon’s Q Test, often referred to simply as the Q Test, is a statistical test that is used for detecting outliers in a dataset.
The test statistic for the Q test is as follows:
Q = |xa – xb| / R
where xa is the suspected outlier, xb is the data point closest to xa, and R is the range of the dataset. In most cases, xa is the maximum value in the dataset but it can also be the minimum value.
It’s important to note that the Q test is typically performed on small datasets and the test assumes that the data is normally distributed. It’s also important to note that the Q test should only be conducted one time for a given dataset.
How to Conduct Dixon’s Q Test By Hand
Suppose we have the following dataset:
1, 3, 5, 7, 8, 9, 13, 25
We can follow the standard five-step procedure for hypothesis testing to conduct Dixon’s Q Test by hand to determine if the maximum value in this dataset is an outlier:
Step 1. State the hypotheses.
The null hypothesis (H0): The max is not an outlier.
The alternative hypothesis: (Ha): The max is an outlier.
Step 2. Determine a significance level to use.
Common choices are 0.1, 0.05, and 0.01. We will use a .05 level of significance for this example.
Step 3. Find the test statistic.
Q = |xa – xb| / R
In this case, our max value is xa = 25, our next closest value is xb = 13, and our range is R = 25 – 1 = 24.
Thus, Q = |25 – 13| / 24 = 0.5.
Next, we can compare this test statistic to the Q test critical values, which are shown below for various sample sizes (n) and confidence levels:
n 90% 95% 99%
3 0.941 0.970 0.994
4 0.765 0.829 0.926
5 0.642 0.710 0.821
6 0.560 0.625 0.740
7 0.507 0.568 0.680
8 0.468 0.526 0.634
9 0.437 0.493 0.598
10 0.412 0.466 0.568
11 0.392 0.444 0.542
12 0.376 0.426 0.522
13 0.361 0.410 0.503
14 0.349 0.396 0.488
15 0.338 0.384 0.475
16 0.329 0.374 0.463
17 0.320 0.365 0.452
18 0.313 0.356 0.442
19 0.306 0.349 0.433
20 0.300 0.342 0.425
21 0.295 0.337 0.418
22 0.290 0.331 0.411
23 0.285 0.326 0.404
24 0.281 0.321 0.399
25 0.277 0.317 0.393
26 0.273 0.312 0.388
27 0.269 0.308 0.384
28 0.266 0.305 0.380
29 0.263 0.301 0.376
30 0.260 0.290 0.372
The critical value for a sample size of 8 and a confidence level of 95% is 0.526.
Step 4. Reject or fail to reject the null hypothesis.
Since our test statistic Q (0.5) is less than the critical value (0.526), we fail to reject the null hypothesis.
Step 5. Interpret the results.
Since we failed to reject the null hypothesis, we conclude that the max value 25 is not an outlier in this dataset.
How to Conduct Dixon’s Q Test in R
To conduct Dixon’s Q Test on the same dataset in R, we can use the dixon.test() function from the outliers library, which uses the following syntax:
dixon.test(data, , type = 10, opposite = FALSE)
- data: a numeric vector of data values
- type: the type of formula to use to conduct the test statistic Q. Set to 10 to use the formula outlined earlier.
- opposite: If FALSE, the test determines if the maximum value is an outlier. If TRUE, the test determines if the minimum value is an outlier. This is FALSE by default.
Note: Find the complete documentation for dixon.test() here.
The following code illustrates how to conduct Dixon’s Q Test to determine if the maximum value in the dataset is an outlier.
#load the outliers library library(outliers) #create data data <- c(1, 3, 5, 7, 8, 9, 13, 25) #conduct Dixon's Q Test dixon.test(data, type = 10) # Dixon test for outliers # #data: data #Q = 0.5, p-value = 0.06913 #alternative hypothesis: highest value 25 is an outlier
From the output we can see that the test statistic is Q = 0.5 and the corresponding p-value is 0.06913. Thus, we fail to reject the null hypothesis at a 0.05 significance level and conclude that 25 is not an outlier. This matches the result we got by hand.
thank you! finally understood how to interpretate R results)
Zach,
Calculation formula for p-value from Dixon test statistics will be very helpful for my understanding. Would appreciate if you kindly let me any reference for the above. Thanks.
Mahbub
very important point
thank you
I guess I’m a bit confused by what I’ve read on Dixon’s test and your explanation, if I may.
You have identified the largest value as the possible outlier, taken the difference between it and the next (smaller) value…25-13.
I thought that the numerator was supposed to be the minimum difference between sorted, successive values.
Any help?
Thank you for your time.
Hello Benjamin…You’re absolutely right to seek clarity—Dixon’s Q test can be a bit tricky at first, especially with different variants floating around. Let’s straighten this out.
—
### 🔍 **What Is Dixon’s Q Test?**
Dixon’s Q test is used to **detect a single outlier** in a small dataset (usually fewer than 30 values). The idea is to compare the gap between a suspected outlier and its nearest neighbor, relative to the range of the data.
—
### ✅ **The General Formula:**
\[
Q = \frac{\text{Gap}}{\text{Range}}
\]
– **Gap**: The absolute difference between the suspected outlier and its nearest neighbor.
– **Range**: The difference between the largest and smallest values in the dataset.
—
### ⚖️ Which Value Is Suspected?
The suspected outlier is usually **either the smallest or the largest** value in the sorted data. Dixon’s Q test can be applied at either end:
#### If you suspect the **maximum** (e.g., 25 is too high):
\[
Q = \frac{x_{n} – x_{n-1}}{x_n – x_1}
\]
#### If you suspect the **minimum** (e.g., 2 is too low):
\[
Q = \frac{x_2 – x_1}{x_n – x_1}
\]
—
### 🧪 Example:
Let’s say you have this sorted dataset:
“`
2, 5, 6, 7, 13, 25
“`
If we suspect **25** is an outlier:
– Gap = 25 – 13 = **12**
– Range = 25 – 2 = **23**
– Q = 12 / 23 ≈ **0.522**
Compare this Q value to the critical value from Dixon’s Q table (based on sample size and significance level, like 0.05).
—
### 💡 Clarifying Your Confusion:
You wrote:
> “I thought the numerator was supposed to be the minimum difference between sorted, successive values.”
That would be **more like a general measure of uniformity**, **not** Dixon’s Q.
🔁 **In Dixon’s Q**, the numerator is **not** the minimum of all successive differences. It’s the **difference between the suspected outlier and its nearest neighbor**.
—
### Summary:
– Dixon’s test compares **the suspected extreme value** (either the max or min) to its nearest neighbor.
– The **numerator** is **not** the smallest difference in the dataset.
– The **goal** is to see if the gap is unusually large compared to the total spread.
—
Your explanation is clear. After I posted my question, I stepped away, thought about it, and realized that the correct solution was as you described. Thank you for the confirmation.
Your explanation is clear. After I posted my question, I stepped away, thought about it, and realized that the correct solution was as you described. Thank you for the confirmation.
Thank you for the clarification. After I posted my question, I stepped away, thought about it, and resolved the error.
Is there an edge case (rare), by which the upper Q value and the lower Q value could be the same and large enough to be considered outliers?
Great question! Let’s first quickly review the basics of **Dixon’s Q Test**:
—
### 🔍 **Dixon’s Q Test Summary:**
– It’s used to detect **a single outlier** in a **small sample** of data (typically ≤ 30 values).
– The test checks **either the lowest value** (Qmin) **or the highest value** (Qmax) in a dataset — **not both simultaneously**.
– Formula:
– **Q = (gap) / (range)**
– Gap: Distance between suspected outlier and nearest value.
– Range: Max – Min of dataset.
– Compare the Q value to a critical Q table value (based on sample size and confidence level).
—
### ❓ Your Question:
> Is there an edge case where **both** Qmin and Qmax are the **same value** and large enough to be considered outliers?
### ✅ Short Answer:
**Yes**, there is a rare edge case **where Qmin and Qmax can be equal**, and both values **appear to be outliers**, but **Dixon’s Q Test is not designed to test both ends simultaneously**.
—
### 🔬 Example:
Let’s say you have the sorted dataset:
“`
[2, 3, 3, 4, 4, 5, 50]
“`
– **n = 7**
– Suspect **2** (low) and **50** (high) are outliers.
Compute Qmin:
– Gap = 3 – 2 = 1
– Range = 50 – 2 = 48
– **Qmin = 1 / 48 ≈ 0.021**
Compute Qmax:
– Gap = 50 – 5 = 45
– Range = 50 – 2 = 48
– **Qmax = 45 / 48 ≈ 0.938**
🟢 In this case, **Qmax is large**, and **Qmin is small**, so only **50** might be an outlier.
—
### 🧪 Edge Case Example:
Now consider this dataset:
“`
[2, 5, 6, 6, 6, 7, 10]
“`
– n = 7
– Range = 10 – 2 = 8
Qmin = (5 – 2) / 8 = **3 / 8 = 0.375**
Qmax = (10 – 7) / 8 = **3 / 8 = 0.375**
🟡 Both Q values are **identical**, and if the **critical value is below 0.375**, then **both could be considered outliers** in **separate tests**.
—
### 🚧 But Here’s the Catch:
– Dixon’s Q Test assumes **only one outlier**.
– Even if both Qmin and Qmax are large, **you cannot simultaneously flag both** as outliers with this test.
– If you want to test both ends, you must:
1. Run the test separately on each extreme.
2. If one is removed, re-run the test to see if the other is still significant.
—
### ✅ Conclusion:
Yes, **in rare cases**, both ends can have **equal and high enough Q values**, but **Dixon’s Q Test only allows one value to be tested at a time**. For handling **two outliers**, you’d need other methods (e.g., **Grubbs’ Test**, **Generalized ESD Test**, or **visual inspection**).