Perform Rosner's generalized extreme Studentized deviate test for up to \(k\) potential outliers in a dataset, assuming the data without any outliers come from a normal (Gaussian) distribution.

rosnerTest(x, k = 3, alpha = 0.05, warn = TRUE)

Arguments

x

numeric vector of observations. Missing (NA), undefined (NaN), and infinite (Inf, -Inf) values are allowed but will be removed. There must be at least 10 non-missing, finite observations in x.

k

positive integer indicating the number of suspected outliers. The argument k must be between 1 and \(n-2\) where \(n\) denotes the number of non-missing, finite values in the arguemnt x. The default value is k=3.

alpha

numeric scalar between 0 and 1 indicating the Type I error associated with the test of hypothesis. The default value is alpha=0.05.

warn

logical scalar indicating whether to issue a warning (warn=TRUE; the default) when the number of non-missing, finite values in x and the value of k are such that the assumed Type I error level might not be maintained. See the DETAILS section below.

Details

Let \(x_1, x_2, \ldots, x_n\) denote the \(n\) observations. We assume that \(n-k\) of these observations come from the same normal (Gaussian) distribution, and that the \(k\) most “extreme” observations may or may not represent observations from a different distribution. Let \(x^{*}_1, x^{*}_2, \ldots, x^{*}_{n-i}\) denote the \(n-i\) observations left after omiting the \(i\) most extreme observations, where \(i = 0, 1, \ldots, k-1\). Let \(\bar{x}^{(i)}\) and \(s^{(i)}\) denote the mean and standard deviation, respectively, of the \(n-i\) observations in the data that remain after removing the \(i\) most extreme observations. Thus, \(\bar{x}^{(0)}\) and \(s^{(0)}\) denote the mean and standard deviation for the full sample, and in general $$\bar{x}^{(i)} = \frac{1}{n-i}\sum_{j=1}^{n-i} x^{*}_j \;\;\;\;\;\; (1)$$ $$s^{(i)} = \sqrt{\frac{1}{n-i-1} \sum_{j=1}^{n-i} (x^{*}_j - \bar{x}^{(i)})^2} \;\;\;\;\;\; (2)$$

For a specified value of \(i\), the most extreme observation \(x^{(i)}\) is the one that is the greatest distance from the mean for that data set, i.e., $$x^{(i)} = \max_{j=1,2,\ldots,n-i} |x^{*}_j - \bar{x}^{(i)}| \;\;\;\;\;\; (3)$$ Thus, an extreme observation may be the smallest or the largest one in that data set.

Rosner's test is based on the \(k\) statistics \(R_1, R_2, \ldots, R_k\), which represent the extreme Studentized deviates computed from successively reduced samples of size \(n, n-1, \ldots, n-k+1\): $$R_{i+1} = \frac{|x^{(i)} - \bar{x}^{(i)}|}{s^{(i)}} \;\;\;\;\;\; (4)$$ Critical values for \(R_{i+1}\) are denoted \(\lambda_{i+1}\) and are computed as: $$\lambda_{i+1} = \frac{t_{p, n-i-2} (n-i-1)}{\sqrt{(n-i-2 + t_{p, n-i-2}) (n-i)}} \;\;\;\;\;\; (5)$$ where \(t_{p, \nu}\) denotes the \(p\)'th quantile of Student's t-distribution with \(\nu\) degrees of freedom, and in this case $$p = 1 - \frac{\alpha/2}{n - i} \;\;\;\;\;\; (6)$$ where \(\alpha\) denotes the Type I error level.

The algorithm for determining the number of outliers is as follows:

  1. Compare \(R_k\) with \(\lambda_k\). If \(R_k > \lambda_k\) then conclude the \(k\) most extreme values are outliers.

  2. If \(R_k \le \lambda_k\) then compare \(R_{k-1}\) with \(\lambda_{k-1}\). If \(R_{k-1} > \lambda_{k-1}\) then conclude the \(k-1\) most extreme values are outliers.

  3. Continue in this fashion until a certain number of outliers have been identified or Rosner's test finds no outliers at all.

Based on a study using N=1,000 simulations, Rosner's (1983) Table 1 shows the estimated true Type I error of declaring at least one outlier when none exists for various sample sizes \(n\) ranging from 10 to 100, and the declared maximum number of outliers \(k\) ranging from 1 to 10. Based on that table, Roser (1983) declared that for an assumed Type I error level of 0.05, as long as \(n \ge 25\), the estimated \(\alpha\) levels are quite close to 0.05, and that similar results were obtained assuming a Type I error level of 0.01. However, the table below is an expanded version of Rosner's (1983) Table 1 and shows results based on N=10,000 simulations. You can see that for an assumed Type I error of 0.05, the test maintains the Type I error fairly well for sample sizes as small as \(n = 3\) as long as \(k = 1\), and for \(n \ge 15\), as long as \(k \le 2\). Also, for an assumed Type I error of 0.01, the test maintains the Type I error fairly well for sample sizes as small as \(n = 15\) as long as \(k \le 7\).

Based on these results, when warn=TRUE, a warning is issued for the following cases indicating that the assumed Type I error may not be correct:

  • alpha is greater than 0.01, the sample size is less than 15, and k is greater than 1.

  • alpha is greater than 0.01, the sample size is at least 15 and less than 25, and k is greater than 2.

  • alpha is less than or equal to 0.01, the sample size is less than 15, and k is greater than 1.

  • k is greater than 10, or greater than the floor of half of the sample size (i.e., greater than the greatest integer less than or equal to half of the sample size). A warning is given for this case because simulations have not been done for this case.

Table 1a. Observed Type I Error Levels based on 10,000 Simulations, \(n =\) 3 to 5.

Assumed\(\alpha=0.05\)Assumed\(\alpha=0.01\)
\(n\)\(k\)\(\hat{\alpha}\)95% LCL95% UCL\(\hat{\alpha}\)95% LCL95% UCL
310.0470.0430.0510.0090.0070.01
410.0490.0450.0530.0100.0080.012
20.1070.1010.1130.0210.0180.024
510.0480.0440.0530.0080.0060.009
20.0950.0900.1010.0200.0180.023

Table 1b. Observed Type I Error Levels based on 10,000 Simulations, \(n =\) 6 to 10.

Assumed\(\alpha=0.05\)Assumed\(\alpha=0.01\)
\(n\)\(k\)\(\hat{\alpha}\)95% LCL95% UCL\(\hat{\alpha}\)95% LCL95% UCL
610.0480.0440.0530.0100.0090.012
20.0850.0800.0910.0170.0150.020
30.1410.1340.1480.0280.0250.031
710.0480.0440.0530.0130.0110.015
20.0800.0750.0860.0170.0150.020
30.1120.1060.1180.0220.0190.025
810.0480.0440.0530.0110.0090.013
20.0800.0740.0850.0170.0140.019
30.1020.0960.1080.0200.0170.023
40.1430.1360.1500.0280.0250.031
910.0520.0480.0570.0100.0080.012
20.0690.0640.0740.0140.0120.016
30.0970.0910.1030.0180.0150.021
40.1200.1140.1260.0240.0210.027
1010.0510.0470.0560.0100.0080.012
20.0680.0630.0730.0120.0100.014
30.0850.0800.0910.0150.0130.017
40.1060.1000.1120.0210.0180.024
50.1350.1280.1420.0250.0220.028

Table 1c. Observed Type I Error Levels based on 10,000 Simulations, \(n =\) 11 to 15.

Assumed\(\alpha=0.05\)Assumed\(\alpha=0.01\)
\(n\)\(k\)\(\hat{\alpha}\)95% LCL95% UCL\(\hat{\alpha}\)95% LCL95% UCL
1110.0520.0480.0560.0120.0100.014
20.0700.0650.0750.0140.0120.017
30.0820.0770.0880.0140.0110.016
40.1010.0950.1070.0190.0160.021
50.1160.1100.1230.0220.0190.024
1210.0520.0470.0560.0110.0090.013
20.0670.0620.0720.0110.0090.013
30.0740.0690.0800.0160.0130.018
40.0880.0820.0930.0160.0140.019
50.0990.0930.1050.0160.0130.018
60.1170.1110.1230.0210.0180.023
1310.0480.0440.0520.0100.0080.012
20.0640.0590.0690.0140.0120.016
30.0700.0650.0750.0130.0110.015
40.0790.0740.0840.0140.0120.017
50.0880.0830.0940.0150.0130.018
60.1090.1030.1150.0200.0170.022
1410.0460.0420.0510.0090.0070.011
20.0620.0570.0660.0120.0100.014
30.0690.0640.0740.0120.0100.014
40.0770.0720.0820.0150.0130.018
50.0840.0790.0900.0160.0130.018
60.0910.0850.0970.0170.0140.019
70.1070.1010.1130.0180.0160.021
1510.0540.0500.0590.0100.0080.012
20.0570.0530.0620.0100.0080.012
30.0650.0600.0690.0130.0110.016
40.0730.0680.0780.0140.0110.016
50.0740.0690.0790.0120.0100.014
60.0860.0810.0920.0150.0130.017
70.0990.0940.1050.0180.0150.020

Table 1d. Observed Type I Error Levels based on 10,000 Simulations, \(n =\) 16 to 20.

Assumed\(\alpha=0.05\)Assumed\(\alpha=0.01\)
\(n\)\(k\)\(\hat{\alpha}\)95% LCL95% UCL\(\hat{\alpha}\)95% LCL95% UCL
1610.0520.0480.0570.0100.0080.012
20.0550.0510.0590.0110.0090.013
30.0680.0630.0730.0110.0090.013
40.0740.0690.0790.0150.0130.017
50.0770.0720.0820.0150.0130.018
60.0750.0700.0800.0130.0110.016
70.0870.0820.0930.0170.0140.020
80.0960.0900.1010.0160.0140.019
1710.0470.0430.0510.0080.0070.010
20.0590.0540.0630.0110.0090.013
30.0620.0570.0670.0120.0100.014
40.0700.0650.0750.0120.0090.014
50.0690.0640.0740.0120.0100.015
60.0710.0660.0760.0150.0120.017
70.0810.0760.0870.0140.0120.016
80.0830.0780.0880.0150.0130.017
1810.0510.0470.0550.0100.0080.012
20.0560.0520.0610.0120.0100.014
30.0650.0600.0700.0120.0100.015
40.0650.0600.0700.0130.0110.015
50.0690.0640.0740.0120.0100.014
60.0680.0630.0730.0140.0110.016
70.0720.0670.0770.0140.0110.016
80.0760.0710.0810.0120.0100.014
90.0810.0760.0860.0120.0100.014
1910.0510.0460.0550.0080.0060.010
20.0590.0550.0640.0120.0100.014
30.0590.0540.0640.0110.0090.013
40.0610.0570.0660.0120.0100.014
50.0670.0620.0720.0130.0100.015
60.0660.0610.0710.0110.0090.013
70.0690.0640.0740.0130.0110.015
80.0740.0690.0790.0120.0100.014
90.0820.0770.0870.0150.0130.018
2010.0530.0480.0570.0110.0090.013
20.0560.0520.0610.0100.0080.012
30.0600.0560.0650.0090.0070.011
40.0630.0580.0680.0120.0100.014
50.0630.0590.0680.0140.0110.016
60.0630.0580.0670.0110.0090.013
70.0650.0610.0700.0110.0090.013
80.0700.0650.0760.0120.0100.014
90.0760.0700.0810.0130.0110.015
100.0810.0760.0870.0120.0100.014

Table 1e. Observed Type I Error Levels based on 10,000 Simulations, \(n =\) 21 to 25.

Assumed\(\alpha=0.05\)Assumed\(\alpha=0.01\)
\(n\)\(k\)\(\hat{\alpha}\)95% LCL95% UCL\(\hat{\alpha}\)95% LCL95% UCL
2110.0540.0490.0580.0130.0110.015
20.0540.0490.0580.0120.0100.014
30.0580.0540.0630.0120.0100.014
40.0580.0540.0630.0110.0090.013
50.0640.0590.0690.0130.0110.016
60.0660.0610.0710.0120.0100.015
70.0630.0580.0680.0130.0110.015
80.0660.0610.0710.0100.0080.012
90.0730.0680.0780.0130.0110.015
100.0710.0660.0760.0120.0100.014
2210.0470.0420.0510.0100.0080.012
20.0580.0530.0620.0120.0100.015
30.0560.0520.0610.0100.0080.012
40.0590.0550.0640.0120.0100.014
50.0610.0570.0660.0090.0080.011
60.0630.0580.0680.0130.0100.015
70.0650.0600.0700.0130.0100.015
80.0650.0600.0700.0140.0120.016
90.0650.0600.0700.0120.0100.014
100.0670.0620.0720.0120.0090.014
2310.0510.0470.0560.0080.0070.010
20.0560.0520.0610.0100.0090.012
30.0560.0520.0610.0110.0090.013
40.0620.0570.0660.0110.0090.013
50.0610.0560.0650.0100.0090.012
60.0600.0550.0640.0120.0100.014
70.0620.0570.0660.0110.0090.013
80.0630.0580.0680.0120.0100.014
90.0660.0610.0710.0120.0100.014
100.0680.0630.0730.0140.0120.017
2410.0510.0460.0550.0100.0080.012
20.0560.0510.0600.0110.0090.013
30.0580.0530.0620.0100.0080.012
40.0600.0560.0650.0130.0110.015
50.0570.0530.0620.0120.0100.014
60.0650.0600.0690.0110.0090.013
70.0620.0570.0660.0120.0100.014
80.0600.0550.0650.0120.0100.014
90.0660.0610.0710.0120.0100.014
100.0640.0590.0680.0120.0100.015
2510.0540.0500.0590.0120.0090.014
20.0550.0510.0600.0100.0080.012
30.0570.0520.0620.0110.0090.013
40.0550.0510.0600.0110.0090.013
50.0600.0550.0650.0120.0100.014
60.0600.0550.0640.0110.0090.013
70.0570.0520.0610.0110.0090.013
80.0620.0580.0670.0110.0090.013
90.0580.0530.0620.0120.0100.014
100.0610.0570.0660.0100.0080.012

Table 1f. Observed Type I Error Levels based on 10,000 Simulations, \(n =\) 26 to 30.

Assumed\(\alpha=0.05\)Assumed\(\alpha=0.01\)
\(n\)\(k\)\(\hat{\alpha}\)95% LCL95% UCL\(\hat{\alpha}\)95% LCL95% UCL
2610.0510.0470.0550.0120.0100.014
20.0570.0530.0620.0130.0110.015
30.0550.0500.0590.0120.0100.014
40.0550.0510.0600.0100.0080.012
50.0580.0540.0630.0110.0090.013
60.0610.0560.0660.0120.0100.014
70.0590.0540.0640.0110.0090.013
80.0600.0560.0650.0100.0080.012
90.0600.0560.0650.0110.0090.013
100.0610.0560.0650.0110.0090.013
2710.0500.0460.0540.0090.0070.011
20.0540.0500.0590.0110.0090.013
30.0620.0570.0660.0120.0100.014
40.0630.0580.0680.0110.0090.013
50.0510.0470.0550.0100.0080.012
60.0580.0530.0620.0110.0090.013
70.0600.0560.0650.0100.0080.012
80.0560.0520.0610.0100.0080.012
90.0610.0560.0660.0120.0100.014
100.0550.0510.0600.0080.0060.010
2810.0490.0450.0530.0100.0080.011
20.0570.0520.0610.0110.0090.013
30.0560.0520.0610.0120.0090.014
40.0570.0530.0620.0110.0090.013
50.0570.0530.0620.0100.0080.012
60.0560.0510.0600.0100.0080.012
70.0570.0520.0610.0100.0080.012
80.0580.0540.0630.0110.0090.013
90.0540.0500.0580.0110.0090.013
100.0620.0570.0670.0110.0090.013
2910.0490.0450.0530.0110.0090.013
20.0530.0480.0570.0100.0080.012
30.0560.0510.0600.0100.0090.012
40.0550.0500.0590.0100.0080.012
50.0560.0510.0600.0100.0080.012
60.0570.0530.0620.0120.0100.014
70.0550.0500.0590.0100.0080.012
80.0570.0520.0610.0110.0090.013
90.0560.0510.0610.0110.0090.013
100.0570.0520.0610.0110.0090.013
3010.0500.0460.0540.0090.0070.011
20.0540.0490.0580.0110.0090.013
30.0560.0520.0610.0120.0100.015
40.0540.0490.0580.0100.0080.012
50.0580.0530.0630.0120.0100.014
60.0620.0580.0670.0120.0100.014
70.0560.0520.0610.0120.0100.014
80.0590.0540.0640.0110.0090.013
90.0560.0520.0610.0100.0090.012
100.0580.0530.0620.0120.0100.015

Table 1g. Observed Type I Error Levels based on 10,000 Simulations, n = 31 to 35.

Assumed\(\alpha=0.05\)Assumed\(\alpha=0.01\)
\(n\)\(k\)\(\hat{\alpha}\)95% LCL95% UCL\(\hat{\alpha}\)95% LCL95% UCL
3110.0510.0470.0560.0090.0070.011
20.0540.0500.0590.0100.0090.012
30.0530.0490.0580.0100.0080.012
40.0550.0500.0590.0100.0080.012
50.0530.0490.0570.0110.0090.013
60.0550.0500.0590.0100.0080.012
70.0550.0500.0590.0120.0100.014
80.0560.0510.0600.0100.0080.012
90.0570.0530.0620.0110.0090.013
100.0580.0530.0620.0110.0090.013
3210.0540.0490.0580.0100.0080.012
20.0540.0500.0590.0100.0080.012
30.0520.0470.0560.0090.0070.011
40.0560.0510.0600.0110.0090.013
50.0560.0520.0610.0110.0090.013
60.0550.0510.0600.0110.0090.013
70.0550.0510.0600.0100.0080.012
80.0550.0510.0600.0100.0080.012
90.0570.0530.0620.0120.0100.014
100.0540.0500.0590.0100.0080.012
3310.0510.0460.0550.0110.0090.013
20.0550.0510.0600.0110.0090.013
30.0560.0520.0610.0100.0080.012
40.0520.0480.0570.0100.0080.012
50.0550.0500.0590.0100.0080.012
60.0580.0530.0620.0110.0090.013
70.0570.0520.0610.0100.0080.012
80.0580.0540.0630.0110.0090.013
90.0570.0530.0620.0120.0100.014
100.0550.0510.0600.0110.0090.013
3410.0520.0480.0560.0090.0070.011
20.0530.0490.0580.0110.0090.013
30.0550.0500.0590.0120.0100.014
40.0560.0520.0610.0100.0080.012
50.0530.0480.0570.0090.0070.011
60.0550.0500.0590.0100.0080.012
70.0520.0480.0570.0120.0100.014
80.0550.0500.0590.0090.0080.011
90.0550.0510.0600.0110.0090.013
100.0540.0490.0580.0100.0080.012
3510.0510.0460.0550.0100.0090.012
20.0540.0490.0580.0100.0090.012
30.0550.0500.0590.0100.0090.012
40.0530.0480.0570.0110.0090.013
50.0560.0510.0610.0110.0090.013
60.0550.0510.0590.0120.0100.014
70.0540.0500.0590.0110.0090.013
80.0540.0490.0580.0110.0090.013
90.0610.0560.0660.0120.0100.014
100.0530.0480.0570.0110.0090.013

Table 1h. Observed Type I Error Levels based on 10,000 Simulations, n = 36 to 40.

Assumed\(\alpha=0.05\)Assumed\(\alpha=0.01\)
\(n\)\(k\)\(\hat{\alpha}\)95% LCL95% UCL\(\hat{\alpha}\)95% LCL95% UCL
3610.0470.0430.0510.0100.0080.012
20.0580.0530.0620.0120.0100.015
30.0520.0470.0560.0090.0070.011
40.0520.0480.0560.0120.0100.014
50.0520.0480.0570.0100.0080.012
60.0550.0510.0590.0120.0100.014
70.0530.0480.0570.0110.0090.013
80.0560.0510.0600.0120.0100.014
90.0560.0510.0600.0110.0090.013
100.0560.0510.0600.0110.0090.013
3710.0500.0460.0550.0100.0080.012
20.0540.0490.0580.0110.0090.013
30.0540.0490.0580.0110.0090.013
40.0540.0500.0580.0100.0080.012
50.0540.0490.0580.0100.0080.012
60.0540.0500.0580.0110.0090.013
70.0550.0510.0600.0100.0080.012
80.0550.0500.0590.0110.0090.013
90.0530.0490.0580.0110.0090.013
100.0490.0450.0540.0090.0070.011
3810.0490.0450.0530.0090.0070.011
20.0520.0470.0560.0080.0070.010
30.0540.0500.0590.0110.0090.013
40.0550.0500.0590.0110.0090.013
50.0560.0520.0610.0120.0100.014
60.0550.0500.0590.0110.0090.013
70.0490.0450.0530.0090.0070.011
80.0520.0480.0570.0100.0080.012
90.0540.0500.0590.0100.0090.012
100.0550.0500.0590.0110.0090.013
3910.0470.0430.0510.0100.0080.012
20.0550.0510.0590.0100.0080.012
30.0530.0490.0570.0100.0080.012
40.0530.0490.0580.0100.0090.012
50.0520.0480.0570.0100.0080.012
60.0530.0490.0580.0100.0080.012
70.0570.0520.0610.0110.0090.013
80.0570.0530.0620.0120.0100.014
90.0500.0460.0550.0100.0080.012
100.0560.0510.0600.0110.0090.013
4010.0490.0450.0540.0100.0080.012
20.0520.0480.0570.0100.0090.012
30.0550.0500.0590.0110.0090.013
40.0540.0500.0590.0110.0090.013
50.0540.0500.0590.0100.0080.012
60.0490.0450.0530.0100.0080.012
70.0560.0510.0600.0110.0090.013
80.0540.0500.0590.0110.0090.013
90.0470.0430.0520.0100.0080.011
100.0580.0540.0630.0100.0080.012

Value

A list of class "gofOutlier" containing the results of the hypothesis test. See the help file for gofOutlier.object for details.

References

Barnett, V., and T. Lewis. (1995). Outliers in Statistical Data. Third Edition. John Wiley & Sons, Chichester, UK, pp. 235–236.

Gilbert, R.O. (1987). Statistical Methods for Environmental Pollution Monitoring. Van Nostrand Reinhold, NY, pp.188–191.

McBean, E.A, and F.A. Rovers. (1992). Estimation of the Probability of Exceedance of Contaminant Concentrations. Ground Water Monitoring Review Winter, pp. 115–119.

McNutt, M. (2014). Raising the Bar. Science 345(6192), p. 9.

Rosner, B. (1975). On the Detection of Many Outliers. Technometrics 17, 221–227.

Rosner, B. (1983). Percentage Points for a Generalized ESD Many-Outlier Procedure. Technometrics 25, 165–172.

USEPA. (2006). Data Quality Assessment: A Reviewer's Guide. EPA QA/G-9R. EPA/240/B-06/002, February 2006. Office of Environmental Information, U.S. Environmental Protection Agency, Washington, D.C.

USEPA. (2009). Statistical Analysis of Groundwater Monitoring Data at RCRA Facilities, Unified Guidance. EPA 530/R-09-007, March 2009. Office of Resource Conservation and Recovery Program Implementation and Information Division. U.S. Environmental Protection Agency, Washington, D.C., pp. 12-10 to 12-14.

USEPA. (2013a). ProUCL Version 5.0.00 Technical Guide. EPA/600/R-07/041, September 2013. Office of Research and Development. U.S. Environmental Protection Agency, Washington, D.C., pp. 190–195.

USEPA. (2013b). ProUCL Version 5.0.00 User Guide. EPA/600/R-07/041, September 2013. Office of Research and Development. U.S. Environmental Protection Agency, Washington, D.C., pp. 190–195.

Author

Steven P. Millard (EnvStats@ProbStatInfo.com)

Note

Rosner's test is a commonly used test for “outliers” when you are willing to assume that the data without outliers follows a normal (Gaussian) distribution. It is designed to avoid masking, which occurs when an outlier goes undetected because it is close in value to another outlier.

Rosner's test is a kind of discordancy test (Barnett and Lewis, 1995). The test statistic of a discordancy test is usually a ratio: the numerator is the difference between the suspected outlier and some summary statistic of the data set (e.g., mean, next largest observation, etc.), while the denominator is always a measure of spread within the data (e.g., standard deviation, range, etc.). Both USEPA (2009) and USEPA (2013a,b) discuss two commonly used discordancy tests: Dixon's test and Rosner's test. Both of these tests assume that all of the data that are not outliers come from a normal (Gaussian) distribution.

There are many forms of Dixon's test (Barnett and Lewis, 1995). The one presented in USEPA (2009) and USEPA (20013a,b) assumes just one outlier (Dixon, 1953). This test is vulnerable to "masking" in which the presence of several outliers masks the fact that even one outlier is present. There are also other forms of Dixon's test that allow for more than one outlier based on a sequence of sub-tests, but these tests are also vulnerable to masking.

Rosner's test allows you to test for several possible outliers and avoids the problem of masking. Rosner's test requires you to set the number of suspected outliers, \(k\), in advance. As in the case of Dixon's test, there are several forms of Rosner's test, so you need to be aware of which one you are using. The form of Rosner's test presented in USEPA (2009) is based on the extreme Studentized deviate (ESD) (Rosner, 1975), whereas the form of Rosner's test performed by the EnvStats function rosnerTest and presented in USEPA (2013a,b) is based on the generalized ESD (Rosner, 1983; Gilbert, 1987). USEPA (2013a, p. 190) cites both Rosner (1975) and Rosner (1983), but presents only the test given in Rosner (1983). Rosner's test based on the ESD has the appropriate Type I error level if there are no outliers in the dataset, but if there are actually say \(m\) outliers, where \(m < k\), then the ESD version of Rosner's test tends to declare more than \(m\) outliers with a probability that is greater than the stated Type I error level (referred to as “swamping”). Rosner's test based on the generalized ESD fixes this problem. USEPA (2013a, pp. 17, 191) incorrectly states that the generalized ESD version of Rosner's test is vulnerable to masking. Surprisingly, the well-known book on statistical outliers by Barnett and Lewis (1995) does not discuss Rosner's generalized ESD test.

As noted, using Rosner's test requires specifying the number of suspected outliers, \(k\), in advance. USEPA (2013a, pp.190-191) states: “A graphical display (Q-Q plot) can be used to identify suspected outliers needed to perform the Rosner test”, and USEPA (2009, p. 12-11) notes: “A potential drawback of Rosner's test is that the user must first identify the maximum number of potential outliers (k) prior to running the test. Therefore, this requirement makes the test ill-advised as an automatic outlier screening tool, and somewhat reliant on the user to identify candidate outliers.”

When observations contain non-detect values (NDs), USEPA (2013a, p. 191) states: “one may replace the NDs by their respective detection limits (DLs), DL/2, or may just ignore them ....” This is bad advice, as this method of dealing with non-detects will produce Type I error rates that are not correct.

OUTLIERS ARE NOT NECESSARILY INCORRECT VALUES
Whether an observation is an “outlier” depends on the underlying assumed statistical model. McBean and Rovers (1992) state:
“It may be possible to ignore the outlier if a physical rationale is available but, failing that, the value must be included .... Note that the use of statistics does not interpret the facts, it simply makes the facts easier to see. Therefore, it is incumbent on the analyst to identify whether or not the high value ... is truly representative of the chemical being monitored or, instead, is an outlier for reasons such as a result of sampling or laboratory error.”

USEPA (2006, p.51) states:
“If scientific reasoning does not explain the outlier, it should not be discarded from the data set.”

Finally, an editorial by the Editor-in-Chief of the journal Science deals with this topic (McNutt, 2014).

You can use the functions qqPlot and gofTest to explore other possible statistical models for the data, or you can use nonparametric statistics if you do not want to assume a particular distribution.

Examples

  # Combine 30 observations from a normal distribution with mean 3 and 
  # standard deviation 2, with 3 observations from a normal distribution 
  # with mean 10 and standard deviation 1, then run Rosner's Test on these 
  # data, specifying k=4 potential outliers based on looking at the 
  # normal Q-Q plot. 
  # (Note: the call to set.seed simply allows you to reproduce 
  # this example.)

  set.seed(250) 

  dat <- c(rnorm(30, mean = 3, sd = 2), rnorm(3, mean = 10, sd = 1)) 

  dev.new()
  qqPlot(dat)

  rosnerTest(dat, k = 4)
#> 
#> Results of Outlier Test
#> -------------------------
#> 
#> Test Method:                     Rosner's Test for Outliers
#> 
#> Hypothesized Distribution:       Normal
#> 
#> Data:                            dat
#> 
#> Sample Size:                     33
#> 
#> Test Statistics:                 R.1 = 2.848514
#>                                  R.2 = 3.086875
#>                                  R.3 = 3.033044
#>                                  R.4 = 2.380235
#> 
#> Test Statistic Parameter:        k = 4
#> 
#> Alternative Hypothesis:          Up to 4 observations are not
#>                                  from the same Distribution.
#> 
#> Type I Error:                    5%
#> 
#> Number of Outliers Detected:     3
#> 
#>   i   Mean.i     SD.i      Value Obs.Num    R.i+1 lambda.i+1 Outlier
#> 1 0 3.549744 2.531011 10.7593656      33 2.848514   2.951949    TRUE
#> 2 1 3.324444 2.209872 10.1460427      31 3.086875   2.938048    TRUE
#> 3 2 3.104392 1.856109  8.7340527      32 3.033044   2.923571    TRUE
#> 4 3 2.916737 1.560335 -0.7972275      25 2.380235   2.908473   FALSE
#> 
#> 

  #Results of Outlier Test
  #-------------------------
  #
  #Test Method:                     Rosner's Test for Outliers
  #
  #Hypothesized Distribution:       Normal
  #
  #Data:                            dat
  #
  #Sample Size:                     33
  #
  #Test Statistics:                 R.1 = 2.848514
  #                                 R.2 = 3.086875
  #                                 R.3 = 3.033044
  #                                 R.4 = 2.380235
  #
  #Test Statistic Parameter:        k = 4
  #
  #Alternative Hypothesis:          Up to 4 observations are not
  #                                 from the same Distribution.
  #
  #Type I Error:                    5%
  #
  #Number of Outliers Detected:     3
  #
  #  i   Mean.i     SD.i      Value Obs.Num    R.i+1 lambda.i+1 Outlier
  #1 0 3.549744 2.531011 10.7593656      33 2.848514   2.951949    TRUE
  #2 1 3.324444 2.209872 10.1460427      31 3.086875   2.938048    TRUE
  #3 2 3.104392 1.856109  8.7340527      32 3.033044   2.923571    TRUE
  #4 3 2.916737 1.560335 -0.7972275      25 2.380235   2.908473   FALSE

  #----------
  # Clean up

  rm(dat)
  graphics.off()

  #--------------------------------------------------------------------

  # Example 12-4 of USEPA (2009, page 12-12) gives an example of 
  # using Rosner's test to test for outliers in napthalene measurements (ppb)
  # taken at 5 background wells over 5 quarters.  The data for this example 
  # are stored in EPA.09.Ex.12.4.naphthalene.df.

  EPA.09.Ex.12.4.naphthalene.df
#>    Quarter Well Naphthalene.ppb
#> 1        1 BW.1            3.34
#> 2        2 BW.1            5.39
#> 3        3 BW.1            5.74
#> 4        4 BW.1            6.88
#> 5        5 BW.1            5.85
#> 6        1 BW.2            5.59
#> 7        2 BW.2            5.96
#> 8        3 BW.2            1.47
#> 9        4 BW.2            2.57
#> 10       5 BW.2            5.39
#> 11       1 BW.3            1.91
#> 12       2 BW.3            1.74
#> 13       3 BW.3           23.23
#> 14       4 BW.3            1.82
#> 15       5 BW.3            2.02
#> 16       1 BW.4            6.12
#> 17       2 BW.4            6.05
#> 18       3 BW.4            5.18
#> 19       4 BW.4            4.43
#> 20       5 BW.4            1.00
#> 21       1 BW.5            8.64
#> 22       2 BW.5            5.34
#> 23       3 BW.5            5.53
#> 24       4 BW.5            4.42
#> 25       5 BW.5           35.45
  #   Quarter Well Naphthalene.ppb
  #1        1 BW.1            3.34
  #2        2 BW.1            5.39
  #3        3 BW.1            5.74
  # ...
  #23       3 BW.5            5.53
  #24       4 BW.5            4.42
  #25       5 BW.5           35.45

  longToWide(EPA.09.Ex.12.4.naphthalene.df, "Naphthalene.ppb", "Quarter", "Well", 
    paste.row.name = TRUE)
#>           BW.1 BW.2  BW.3 BW.4  BW.5
#> Quarter.1 3.34 5.59  1.91 6.12  8.64
#> Quarter.2 5.39 5.96  1.74 6.05  5.34
#> Quarter.3 5.74 1.47 23.23 5.18  5.53
#> Quarter.4 6.88 2.57  1.82 4.43  4.42
#> Quarter.5 5.85 5.39  2.02 1.00 35.45
  #          BW.1 BW.2  BW.3 BW.4  BW.5
  #Quarter.1 3.34 5.59  1.91 6.12  8.64
  #Quarter.2 5.39 5.96  1.74 6.05  5.34
  #Quarter.3 5.74 1.47 23.23 5.18  5.53
  #Quarter.4 6.88 2.57  1.82 4.43  4.42
  #Quarter.5 5.85 5.39  2.02 1.00 35.45


  # Look at Q-Q plots for both the raw and log-transformed data
  #------------------------------------------------------------

  dev.new()
  with(EPA.09.Ex.12.4.naphthalene.df, 
    qqPlot(Naphthalene.ppb, add.line = TRUE, 
      main = "Figure 12-6.  Naphthalene Probability Plot"))

  dev.new()
  with(EPA.09.Ex.12.4.naphthalene.df, 
    qqPlot(Naphthalene.ppb, dist = "lnorm", add.line = TRUE, 
      main = "Figure 12-7.  Log Naphthalene Probability Plot"))


  # Test for 2 potential outliers on the original scale:
  #-----------------------------------------------------

  with(EPA.09.Ex.12.4.naphthalene.df, rosnerTest(Naphthalene.ppb, k = 2))
#> 
#> Results of Outlier Test
#> -------------------------
#> 
#> Test Method:                     Rosner's Test for Outliers
#> 
#> Hypothesized Distribution:       Normal
#> 
#> Data:                            Naphthalene.ppb
#> 
#> Sample Size:                     25
#> 
#> Test Statistics:                 R.1 = 3.930957
#>                                  R.2 = 4.160223
#> 
#> Test Statistic Parameter:        k = 2
#> 
#> Alternative Hypothesis:          Up to 2 observations are not
#>                                  from the same Distribution.
#> 
#> Type I Error:                    5%
#> 
#> Number of Outliers Detected:     2
#> 
#>   i  Mean.i     SD.i Value Obs.Num    R.i+1 lambda.i+1 Outlier
#> 1 0 6.44240 7.379271 35.45      25 3.930957   2.821681    TRUE
#> 2 1 5.23375 4.325790 23.23      13 4.160223   2.801551    TRUE
#> 
#> 

  #Results of Outlier Test
  #-------------------------
  #
  #Test Method:                     Rosner's Test for Outliers
  #
  #Hypothesized Distribution:       Normal
  #
  #Data:                            Naphthalene.ppb
  #
  #Sample Size:                     25
  #
  #Test Statistics:                 R.1 = 3.930957
  #                                 R.2 = 4.160223
  #
  #Test Statistic Parameter:        k = 2
  #
  #Alternative Hypothesis:          Up to 2 observations are not
  #                                 from the same Distribution.
  #
  #Type I Error:                    5%
  #
  #Number of Outliers Detected:     2
  #
  #  i  Mean.i     SD.i Value Obs.Num    R.i+1 lambda.i+1 Outlier
  #1 0 6.44240 7.379271 35.45      25 3.930957   2.821681    TRUE
  #2 1 5.23375 4.325790 23.23      13 4.160223   2.801551    TRUE

  #----------
  # Clean up

  graphics.off()