Exemple #1
0
        /// <summary>
        /// Estimates the tau-th quantile from the provided samples.
        /// The tau-th quantile is the data value where the cumulative distribution
        /// function crosses tau.
        /// Approximately median-unbiased regardless of the sample distribution (R8).
        /// </summary>
        /// <param name="data">The data sample sequence.</param>
        public static Func <double, double> QuantileFunc(this IEnumerable <double> data)
        {
            var array = data.ToArray();

            Array.Sort(array);
            return(tau => SortedArrayStatistics.Quantile(array, tau));
        }
Exemple #2
0
        /// <summary>
        /// Estimates the tau-th quantile from the provided samples.
        /// The tau-th quantile is the data value where the cumulative distribution
        /// function crosses tau.
        /// Approximately median-unbiased regardless of the sample distribution (R8).
        /// </summary>
        /// <param name="data">The data sample sequence.</param>
        public static Func <double, double> QuantileFunc(this IEnumerable <double?> data)
        {
            var array = data.Where(d => d.HasValue).Select(d => d.Value).ToArray();

            Array.Sort(array);
            return(tau => SortedArrayStatistics.Quantile(array, tau));
        }
Exemple #3
0
        /// <summary>
        /// Estimates the tau-th quantile from the provided samples.
        /// The tau-th quantile is the data value where the cumulative distribution
        /// function crosses tau.
        /// Approximately median-unbiased regardless of the sample distribution (R8).
        /// </summary>
        /// <param name="data">The data sample sequence.</param>
        public static Func <double, double> QuantileFunc(this IEnumerable <double?> data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            var array = data.Where(d => d.HasValue).Select(d => d.Value).ToArray();

            Array.Sort(array);
            return(tau => SortedArrayStatistics.Quantile(array, tau));
        }
        /// <summary>
        /// Computes the percentile.
        /// </summary>
        /// <param name="percentile">The percentile, must be between 0.0 and 1.0 (inclusive).</param>
        /// <returns>the requested percentile.</returns>
        public double Compute(double percentile)
        {
            switch (Method)
            {
            case PercentileMethod.Nist:
                return(SortedArrayStatistics.QuantileCustom(_data, percentile, QuantileDefinition.Nist));

            case PercentileMethod.Nearest:
                return(SortedArrayStatistics.QuantileCustom(_data, percentile, QuantileDefinition.R3));

            case PercentileMethod.Interpolation:
                return(SortedArrayStatistics.QuantileCustom(_data, percentile, QuantileDefinition.R5));

            case PercentileMethod.Excel:
                return(SortedArrayStatistics.QuantileCustom(_data, percentile, QuantileDefinition.Excel));

            default:
                return(SortedArrayStatistics.Quantile(_data, percentile));
            }
        }