/// <summary> /// Computes the circular quartiles of the given circular angles. /// </summary> /// /// <param name="angles">A double array containing the angles in radians.</param> /// <param name="q1">The first quartile, as an out parameter.</param> /// <param name="q3">The third quartile, as an out parameter.</param> /// <param name="median">The angular median, if already known.</param> /// <param name="wrap"> /// Whether range values should be wrapped to be contained in the circle. If /// set to false, range values could be returned outside the [+pi;-pi] range. /// </param> /// /// <returns>The median of the given angles.</returns> /// public static double Quartiles(double[] angles, out double q1, out double q3, double median, bool wrap = true) { double[] x = new double[angles.Length]; for (int i = 0; i < angles.Length; i++) { x[i] = Accord.Math.Tools.Mod(angles[i] - median, 2 * Math.PI); } for (int i = 0; i < x.Length; i++) { x[i] = (x[i] < -Math.PI) ? (x[i] + (2 * Math.PI)) : (x[i]); x[i] = (x[i] > +Math.PI) ? (x[i] - (2 * Math.PI)) : (x[i]); } Tools.Quartiles(x, out q1, out q3, alreadySorted: false); q1 = q1 + median; q3 = q3 + median; if (wrap) { q1 = Accord.Math.Tools.Mod(q1, 2 * Math.PI); q3 = Accord.Math.Tools.Mod(q3, 2 * Math.PI); } return(median); }
public void QuartileTest3() { double[] values = new double[] { 102, 104, 105, 107, 108, 109, 110, 112, 115, 116, 118 }; double q1, q3, actual; actual = Tools.Quartiles(values, out q1, out q3, false); Assert.AreEqual(105, q1); Assert.AreEqual(109, actual); Assert.AreEqual(115, q3); }
public void QuartileTest2() { double[] values = new double[] { 1, 3, 3, 4, 5, 6, 6, 7, 8, 8 }; double q1, q3, actual; actual = Tools.Quartiles(values, out q1, out q3, false); Assert.AreEqual(3, q1); Assert.AreEqual(5.5, actual); Assert.AreEqual(7, q3); }
public void QuartileTest1() { double[] values = new double[] { 3, 4, 8 }; double q1, q3, actual; actual = Tools.Quartiles(values, out q1, out q3, false); Assert.AreEqual(3, q1); Assert.AreEqual(4, actual); Assert.AreEqual(8, q3); }
public void QuartileTest4() { // This is equivalent to R's type 6. This is the // same algorithm used by Minitab and SPSS. It is // not the same used by R and S. double[] values = { -0.309882133, -0.640157313179586, 0.00470721699999999, -0.709738241179586, 0.328021416, -1.95662033217959, 0.618215405, 0.113038781, 0.311043694,-0.0662271140000001, -0.314138172179586, 0, -0.220574326, 0.078498723, 0.287448082 }; double q1, q3, actual; actual = Tools.Quartiles(values, out q1, out q3, false); Assert.AreEqual(-0.31413817217958601, q1); Assert.AreEqual(0, actual); Assert.AreEqual(0.28744808199999999, q3); }