Example #1
0
        /// <summary>
        ///   Computes the circular kurtosis of the given circular angles.
        /// </summary>
        ///
        /// <param name="angles">A double array containing the angles in radians.</param>
        ///
        /// <returns>The circular kurtosis for the given <paramref name="angles"/>.</returns>
        ///
        public static double Kurtosis(double[] angles)
        {
            // Compute mean direction
            double theta = Circular.Mean(angles);

            // Compute central moments
            double rho2 = CentralMoments(angles, 2).Magnitude;
            double mu2  = NoncentralMoments(angles, 2).Phase;

            // compute skewness
            double k = 0;

            for (int i = 0; i < angles.Length; i++) // Pewsey, Metrika, 2004
            {
                k += Math.Cos(2 * Circular.Distance(angles[i], theta));
            }
            k /= angles.Length;

            /*
             * double k0 = 0;
             * double R4 = (R * R * R * R);
             * double omR2 = (1 - R) * (1 - R);
             * for (int i = 0; i < angles.Length; i++) // Fisher, Circular Statistics, p. 34
             *  k0 += (rho2 * Math.Cos(Circular.Distance(mu2, 2 * theta)) - R4) / omR2; // (formula 2.30)
             */

            return(k);
        }
Example #2
0
        /// <summary>
        ///   Computes the circular skewness of the given circular angles.
        /// </summary>
        ///
        /// <param name="angles">A double array containing the angles in radians.</param>
        ///
        /// <returns>The circular skewness for the given <paramref name="angles"/>.</returns>
        ///
        public static double Skewness(double[] angles)
        {
            // compute necessary values
            double theta = Circular.Mean(angles);

            System.Numerics.Complex m = CentralMoments(angles, 2);
            double rho2 = m.Magnitude;
            double mu2  = m.Phase;

            // compute skewness
            double b = 0; // Pewsey, Metrika, 2004

            for (int i = 0; i < angles.Length; i++)
            {
                b += Math.Sin(2 * Distance(angles[i], theta));
            }
            b /= angles.Length;

            /*
             * // alternative skewness measure from Fisher
             * // Statistical Analysis of Circular Data, p. 34
             * double b0 = 0; // (formula 2.29)
             * double omR = Math.Pow(1 - R, 3 / 2.0);
             *
             * for (int i = 0; i < angles.Length; i++)
             *  b0 += rho2 * Math.Sin(Distance(mu2, 2 * theta)) / omR;
             */

            return(b);
        }
Example #3
0
        /// <summary>
        ///   Computes the circular quartiles of the given circular samples.
        ///   The minimum possible value for a sample must be zero and the maximum must
        ///   be indicated in the parameter <paramref name="length"/>.
        /// </summary>
        ///
        /// <param name="samples">A double array containing the circular samples.</param>
        /// <param name="length">The maximum possible value of the samples.</param>
        /// <param name="range">The sample quartiles, as an out parameter.</param>
        /// <param name="median">The median value of the <paramref name="samples"/>, 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 samples.</returns>
        ///
        public static double Quartiles(double[] samples, double length, out DoubleRange range, double median, bool wrap = true)
        {
            double angleMedian = Circular.ToRadians(median, length);
            double q2          = Quartiles(ToRadians(samples, length), out range, angleMedian, wrap);

            range.Min = ToCircular(range.Min, length, wrap);
            range.Max = ToCircular(range.Max, length, wrap);
            return(ToCircular(q2, length));
        }
Example #4
0
        /// <summary>
        ///   Computes the circular quartiles of the given circular samples.
        ///   The minimum possible value for a sample must be zero and the maximum must
        ///   be indicated in the parameter <paramref name="length"/>.
        /// </summary>
        ///
        /// <param name="samples">A double array containing the circular samples.</param>
        /// <param name="length">The maximum possible value of the samples.</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 median value of the <paramref name="samples"/>, 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 samples.</returns>
        ///
        public static double Quartiles(double[] samples, double length, out double q1, out double q3, double median, bool wrap = true)
        {
            double angleMedian = Circular.ToRadians(median, length);
            double q2          = Quartiles(ToRadians(samples, length), out q1, out q3, angleMedian, wrap);

            q1 = ToCircular(q1, length, wrap);
            q3 = ToCircular(q3, length, wrap);
            return(ToCircular(q2, length));
        }