public static Tuple <double[], double, double, double> dixond(double[] items, int alpha) { int n = items.Length; if (!(n >= 3 || n <= 30)) { throw new Exception("Dixon function: it is required that count of samples be within [3, 30]."); } if (!(alpha == 1 || alpha == 5)) { throw new Exception("Dixon function: it is required that alpha be 1 or 5."); } double dixon = Dixon.GetValue(alpha, n); double[] x = items.OrderBy(i => i).ToArray(); double r1; double rn; if (n <= 7) { r1 = (x[1] - x[0]) / (x[x.Length - 1] - x[0]); rn = (x[x.Length - 1] - x[x.Length - 2]) / (x[x.Length - 1] - x[0]); } else if (n <= 10) { r1 = (x[1] - x[0]) / (x[x.Length - 2] - x[0]); rn = (x[x.Length - 1] - x[x.Length - 2]) / (x[x.Length - 1] - x[1]); } else if (n <= 13) { r1 = (x[2] - x[0]) / (x[x.Length - 2] - x[0]); rn = (x[x.Length - 1] - x[x.Length - 3]) / (x[x.Length - 1] - x[1]); } else { r1 = (x[2] - x[0]) / (x[x.Length - 3] - x[0]); rn = (x[x.Length - 1] - x[x.Length - 3]) / (x[x.Length - 1] - x[2]); } bool removeFirst = r1 > rn && r1 > dixon; bool removeLast = rn > r1 && rn > dixon; List <double> removedItems = new List <double>(); if (removeFirst) { removedItems.Add(x.First()); } if (removeLast) { removedItems.Add(x.Last()); } return(new Tuple <double[], double, double, double>(removedItems.ToArray(), r1, rn, dixon)); }
public static double tdixon(int n, int alpha) { return(Dixon.GetValue(alpha, n)); }