public void ValidateCumulativeDistribution(double location, double scale, double dof, double x, double p)
        {
            var dist = new StudentT(location, scale, dof);

            Assert.That(dist.CumulativeDistribution(x), Is.EqualTo(p).Within(1e-13));
            Assert.That(StudentT.CDF(location, scale, dof, x), Is.EqualTo(p).Within(1e-13));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Two-sided or one-sided test for whether statitics of two variables are equal in the true population, var1 and var2 are paired and dependent
        ///
        /// Hypotheses are:
        /// H_0: mu_var1 = mu_var2
        /// H_1: mu_var1 != mu_var2
        ///
        /// The hypotheses can be written as
        /// H_0: mu_var1 - mu_var2 = 0
        /// H_1: mu_var1 - mu_var2 != 0
        ///
        /// By Central Limt Theorem:
        /// sample_mean_var1 - sample_mean_var2 ~ N(0, SE), where null_value = 0 and SE is the standard error of the sampling distribution
        ///
        /// p-value = (sample_mean is at least ||null_value-point_estimate|| away from the null_value) | mu = null_value)
        /// </summary>
        /// <param name="sample_for_paired_data">a random sample consisting data paired together, var1 and var2, var1 and var2 are not independent</param>
        /// <param name="one_sided">True if the test is one-sided</param>
        /// <param name="significance_level"></param>
        /// <returns></returns>
        public bool RejectH0_PairedData(Tuple <double, double>[] sample_for_paired_data, out double pValue, double significance_level = 0.05, bool one_sided = false, bool useStudentT = false)
        {
            int sample_size = sample_for_paired_data.Length;

            double[] diff = new double[sample_size];
            for (int i = 0; i < sample_size; ++i)
            {
                diff[i] = sample_for_paired_data[i].Item1 - sample_for_paired_data[i].Item2;
            }
            double point_estimate = Mean.GetMean(diff);
            double null_value     = 0;
            double SE             = StandardError.GetStandardError(diff);
            double test_statistic = System.Math.Abs(point_estimate - null_value) / SE;

            double percentile = 0;

            if (sample_for_paired_data.Length < 30 || useStudentT) //if sample size is smaller than 30, then CLT for population statistics such as sample mean no longer holds and Student's t distribution should be used in place of the normal distribution
            {
                percentile = StudentT.GetPercentile(test_statistic, sample_for_paired_data.Length - 1);
            }
            else
            {
                percentile = Gaussian.GetPercentile(test_statistic);
            }

            pValue = (1 - percentile) * (one_sided ? 1 : 2);
            return(pValue < significance_level);
        }
 public void CanCreateStudentT(double location, double scale, double dof)
 {
     var n = new StudentT(location, scale, dof);
     AssertEx.AreEqual<double>(location, n.Location);
     AssertEx.AreEqual<double>(scale, n.Scale);
     AssertEx.AreEqual<double>(dof, n.DegreesOfFreedom);
 }
        /// <summary>
        /// Get the confidence interval for the difference between two classes
        ///
        /// Note that this is for variables with continuous values
        /// </summary>
        /// <param name="sample_for_var1">random sample drawn for class 1</param>
        /// <param name="sample_for_var2">random sample drawn for class 2</param>
        /// <param name="confidence_level">confidencen level</param>
        /// <returns>The confidence interval for the difference between two classes in the population given the confidence level</returns>
        public static double[] GetConfidenceIntervalForDiff(double[] sample_for_var1, double[] sample_for_var2, double confidence_level, bool useStudentT = false, double correlation = 0)
        {
            double point_estimate, SE;

            LinearCombination.Diff(sample_for_var1, sample_for_var2, correlation, out point_estimate, out SE);

            double p1 = (1 - confidence_level) / 2;
            double p2 = 1 - p1;

            double critical_value1 = 0;
            double critical_value2 = 0;

            if (sample_for_var1.Length < 30 || sample_for_var2.Length < 30 || useStudentT) //if sample size is smaller than 30, then CLT for population statistics such as sample mean no longer holds and Student's t distribution should be used in place of the normal distribution
            {
                int df = System.Math.Min(sample_for_var1.Length - 1, sample_for_var2.Length - 1);
                critical_value1 = StudentT.GetQuantile(p1, df);
                critical_value2 = StudentT.GetQuantile(p2, df);
            }
            else
            {
                critical_value1 = Gaussian.GetQuantile(p1);
                critical_value2 = Gaussian.GetQuantile(p2);
            }

            return(new double[] { point_estimate + critical_value1 * SE, point_estimate + critical_value2 * SE });
        }
 public void CanCreateStandardStudentT()
 {
     var n = new StudentT();
     AssertEx.AreEqual<double>(0.0, n.Location);
     AssertEx.AreEqual<double>(1.0, n.Scale);
     AssertEx.AreEqual<double>(1.0, n.DegreesOfFreedom);
 }
        /// <summary>
        /// Return the confidence interval of the population mean (measured on a continuous random variable) given a random sample
        ///
        /// Note that this is for a variable whose values are continuous
        /// </summary>
        /// <param name="sampleMean">point estimate sample mean given by the random sample</param>
        /// <param name="sampleStdDev">point estimate sample standard deviation given by the random sample</param>
        /// <param name="sampleSize">size of the random sample</param>
        /// <param name="confidence_level"></param>
        /// <returns></returns>
        public static double[] GetConfidenceInterval(double sampleMean, double sampleStdDev, int sampleSize, double confidence_level, bool useStudentT = false)
        {
            double standard_error = StandardError.GetStandardError(sampleStdDev, sampleSize);

            double[] confidence_interval = new double[2];

            double p1 = (1 - confidence_level) / 2.0;
            double p2 = 1 - p1;

            double critical_value1 = 0;
            double critical_value2 = 0;

            if (sampleSize < 30 || useStudentT) //if sample size is smaller than 30, then CLT for population statistics such as sample mean no longer holds and Student's t distribution should be used in place of the normal distribution
            {
                int df = sampleSize - 1;
                critical_value1 = StudentT.GetQuantile(p1, df);
                critical_value2 = StudentT.GetQuantile(p2, df);
            }
            else
            {
                critical_value1 = Gaussian.GetQuantile(p1);
                critical_value2 = Gaussian.GetQuantile(p2);
            }

            confidence_interval[0] = sampleMean + critical_value1 * standard_error;
            confidence_interval[1] = sampleMean + critical_value2 * standard_error;

            return(confidence_interval);
        }
        public void ValidateInverseCumulativeDistribution(double location, double scale, double dof, double x, double p)
        {
            var dist = new StudentT(location, scale, dof);

            Assert.That(dist.InverseCumulativeDistribution(p), Is.EqualTo(x).Within(1e-6));
            Assert.That(StudentT.InvCDF(location, scale, dof, p), Is.EqualTo(x).Within(1e-6));
        }
Ejemplo n.º 8
0
 public void SetDofFailsWithNonPositiveDoF(double dof)
 {
     {
         var n = new StudentT();
         n.DegreesOfFreedom = dof;
     }
 }
Ejemplo n.º 9
0
 public void SetScaleFailsWithNonPositiveScale(double scale)
 {
     {
         var n = new StudentT();
         n.Scale = scale;
     }
 }
Ejemplo n.º 10
0
        public override string ToString()
        {
            if (count < 1)
            {
                return(name + ": <no data>");
            }

            if (times)
            {
                double total_sec = total * 1.0 / Stopwatch.Frequency;
                if (count == 1)
                {
                    return(name + ": " + total_sec.ToString());
                }
                double average_sec = total_sec / count;
                double sumsq_sec   = sumsq / Stopwatch.Frequency / Stopwatch.Frequency;
                double variance    = (sumsq_sec - total_sec * total_sec / count) / (count - 1);
                double stdev       = Math.Sqrt(variance);
                double conf95      = StudentT.InvCDF(0, stdev, count - 1, 0.975) / Math.Sqrt(count);
                return(string.Format("Aggregate {0}: avg_usec {1} conf95plusorminus {2} stdev {3} count {4} sum {5}", name, average_sec * Math.Pow(10, 6), conf95 * Math.Pow(10, 6), stdev * Math.Pow(10, 6), count, total_sec * Math.Pow(10, 6)));
            }
            else
            {
                if (count == 1)
                {
                    return(total.ToString());
                }
                double average  = total * 1.0 / count;
                double variance = (sumsq - (total * 1.0 * total) / count) / (count - 1);
                double stdev    = Math.Sqrt(variance);
                double conf95   = StudentT.InvCDF(0, stdev, count - 1, 0.975) / Math.Sqrt(count);
                return(string.Format("Aggregate {0}: avg_usec {1} conf95plusorminus {2} stdev {3} count {4} sum {5}", name, average * Math.Pow(10, 6), conf95 * Math.Pow(10, 6), stdev * Math.Pow(10, 6), count, total * Math.Pow(10, 6)));
            }
        }
Ejemplo n.º 11
0
 public void CanCreateStudentT([Values(0.0, -5.0, 10.0)] double location, [Values(0.1, 1.0, 10.0)] double scale, [Values(1.0, 3.0, Double.PositiveInfinity)] double dof)
 {
     var n = new StudentT(location, scale, dof);
     Assert.AreEqual(location, n.Location);
     Assert.AreEqual(scale, n.Scale);
     Assert.AreEqual(dof, n.DegreesOfFreedom);
 }
Ejemplo n.º 12
0
        public void CanSampleSequence()
        {
            var n   = new StudentT();
            var ied = n.Samples();

            ied.Take(5).ToArray();
        }
Ejemplo n.º 13
0
        public void ValidateToString()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            var n = new StudentT(1.0, 2.0, 1.0);

            Assert.AreEqual("StudentT(μ = 1, σ = 2, ν = 1)", n.ToString());
        }
Ejemplo n.º 14
0
        public Distribution(String DistributionName, params double[] vs) // 构造函数 根据名字初始化分布
        {
            switch (DistributionName.ToUpper())
            {
            case "NORMAL":
                normalDis = new Normal(vs[0], vs[1]);     // double mean, double stddev
                break;

            case "CONTINUOUS":
                continuousUniformDis = new ContinuousUniform(vs[0], vs[1]);     // int lower, int upper
                break;

            case "TRIANGULAR":
                triangularDis = new Triangular(vs[0], vs[1], vs[2]);     //double lower, double upper, double mode  (lower ≤ mode ≤ upper)
                break;

            case "STUDENTT":
                studentTDis = new StudentT(vs[0], vs[1], vs[2]);    //double location, double scale, double freedom
                break;

            case "BERNOULLI":
                bernoulliDis = new Bernoulli(vs[0]);
                break;

            case "DISCRETEUNIFORM":
                discreteUniform = new DiscreteUniform((int)vs[0], (int)vs[1]);     // int lower, int upper
                break;
            }
            this.DistributionName = DistributionName;
        }
Ejemplo n.º 15
0
 /// <param name="degFreedom"> The number of degrees of freedom, not negative or zero </param>
 /// <param name="engine"> A generator of uniform random numbers, not null </param>
 public StudentTDistribution(double degFreedom, RandomEngine engine)
 {
     ArgChecker.isTrue(degFreedom > 0, "degrees of freedom");
     ArgChecker.notNull(engine, "engine");
     _degFreedom = degFreedom;
     _dist       = new StudentT(degFreedom, engine);
     _beta       = new InverseIncompleteBetaFunction(degFreedom / 2.0, 0.5);
 }
Ejemplo n.º 16
0
        public void CanCreateStandardStudentT()
        {
            var n = new StudentT();

            Assert.AreEqual <double>(0.0, n.Location);
            Assert.AreEqual <double>(1.0, n.Scale);
            Assert.AreEqual <double>(1.0, n.DegreesOfFreedom);
        }
Ejemplo n.º 17
0
        public Vector <double> PValues()
        {
            Vector <double> result = TStatistics();
            int             df     = intercept ? N - k - 1 : N - k;

            result.PointwiseAbs().Map(t => 2 * (1 - StudentT.CDF(0, 1, df, t)), result);
            return(result);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Tau distribucija (razdioba)
        /// </summary>
        /// <param name="alfa">Nivo signifikantnosti (znacajnosti) -> 1 > alfa > 0</param>
        /// <param name="f">Stupanj slobode</param>
        /// <returns>double</returns>
        /// <remarks>
        ///     <para/>Distribucija interno studentiziranih mjerenja
        ///     <para/>Popravci i njihove standardne su korelirani
        ///     <para/>Allan J. Pope 1976.
        /// </remarks>
        public static double Tau(double alfa, int f)
        {
            double t = StudentT.InvCDF(0, 1, f - 1, 1 - alfa / 2);

            double tau = t * Math.Sqrt(f) / Math.Sqrt(f - 1 + Math.Pow(t, 2));

            return(tau);
        }
Ejemplo n.º 19
0
        public static double[] studentT(double v1, double v2, double v3, int num)
        {
            var t = new StudentT(v1, v2, v3);

            double[] ret = new double[num];
            t.Samples(ret);
            return(ret);
        }
Ejemplo n.º 20
0
        public void CanCreateStudentT([Values(0.0, -5.0, 10.0)] double location, [Values(0.1, 1.0, 10.0)] double scale, [Values(1.0, 3.0, Double.PositiveInfinity)] double dof)
        {
            var n = new StudentT(location, scale, dof);

            Assert.AreEqual(location, n.Location);
            Assert.AreEqual(scale, n.Scale);
            Assert.AreEqual(dof, n.DegreesOfFreedom);
        }
Ejemplo n.º 21
0
        public void CanCreateStudentT(double location, double scale, double dof)
        {
            var n = new StudentT(location, scale, dof);

            Assert.AreEqual <double>(location, n.Location);
            Assert.AreEqual <double>(scale, n.Scale);
            Assert.AreEqual <double>(dof, n.DegreesOfFreedom);
        }
Ejemplo n.º 22
0
 public StudentTPrimitive(double location, double scale, double normality, Random gen)
 {
     Location  = location;
     Scale     = scale;
     Normality = normality;
     Gen       = gen;
     dist      = new StudentT(Location, Scale, Normality, Gen);
 }
Ejemplo n.º 23
0
        private void CalculaICTStudent(double media, double variancia, int n, ref IntervaloConfianca ic)
        {
            StudentT ts        = new StudentT(0, 1, n - 1);
            var      percentil = ts.InverseCumulativeDistribution(0.975);

            ic.U = media + percentil * Math.Sqrt(variancia / n);
            ic.L = media - percentil * Math.Sqrt(variancia / n);
        }
Ejemplo n.º 24
0
        public IList <LinearFitResult> Fit(double[] observations)
        {
            if (observations.Length != DesignMatrix.RowCount)
            {
                throw new ArgumentException("Wrong number of rows"); // Not L10N
            }
            var coefficients = QrFactorization.Solve(observations);
            var fittedValues = new double[observations.Length];
            var residuals    = new double[observations.Length];

            for (int iRow = 0; iRow < observations.Length; iRow++)
            {
                var designRow = Enumerable.Range(0, DesignMatrix.ColumnCount).Select(index => DesignMatrix[iRow, index]).ToArray();
                fittedValues[iRow] = DotProduct(designRow, coefficients);
                residuals[iRow]    = observations[iRow] - fittedValues[iRow];
            }
            double rss = DotProduct(residuals, residuals);

            int    degreesOfFreedom   = observations.Length - QrFactorization.NumberIndependentColumns;
            double resVar             = rss / degreesOfFreedom;
            double sigma              = Math.Sqrt(resVar);
            var    covarianceUnscaled = MatrixCrossproductInverse;
            var    scaledCovariance   = covarianceUnscaled.Multiply(sigma * sigma);
            var    indepColIndexes    = QrFactorization.IndependentColumnIndexes.ToArray();
            var    result             = new List <LinearFitResult>();

            foreach (var contrastRow in ContrastValues.EnumerateRows())
            {
                double standardError = 0;
                for (int iRow = 0; iRow < indepColIndexes.Length; iRow++)
                {
                    for (int iCol = 0; iCol < indepColIndexes.Length; iCol++)
                    {
                        standardError += contrastRow[indepColIndexes[iRow]] * scaledCovariance[iRow, iCol] * contrastRow[indepColIndexes[iCol]];
                    }
                }
                standardError = Math.Sqrt(standardError);
                double foldChange = DotProduct(coefficients, contrastRow);
                double tValue     = foldChange / standardError;
                double pValue;
                if (0 != degreesOfFreedom)
                {
                    var studentT = new StudentT(0, 1.0, degreesOfFreedom);
                    pValue = (1 - studentT.CumulativeDistribution(Math.Abs(tValue))) * 2;
                }
                else
                {
                    pValue = 1;
                }
                result.Add(new LinearFitResult(foldChange)
                           .SetDegreesOfFreedom(degreesOfFreedom)
                           .SetTValue(tValue)
                           .SetStandardError(standardError)
                           .SetPValue(pValue));
            }
            return(result);
        }
Ejemplo n.º 25
0
        public void ValidateMedian(
            [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 10.0, -5.0, 0.0)] double location,
            [Values(1.0, 0.1, 1.0, 10.0, 10.0, 10.0, 10.0, 1.0, 1.0, 100.0, Double.PositiveInfinity)] double scale,
            [Values(1.0, 1.0, 3.0, 1.0, 2.0, 2.5, Double.PositiveInfinity, 1.0, 2.5, 1.5, 1.0)] double dof)
        {
            var n = new StudentT(location, scale, dof);

            Assert.AreEqual(location, n.Median);
        }
        /// <summary>
        /// Return the confidence interval of the population mean at a given confidence level, given the point estimate sample mean are known from multiple groups / classes
        ///
        /// Note that each class should be a continuous variable.
        /// </summary>
        /// <param name="sampleMeans">point estimate sample means from different groups/classes</param>
        /// <param name="sampleStdDev">point estimate sample standard deviations from different groups / classes</param>
        /// <param name="sampleSizes">sample size from different classes</param>
        /// <param name="confidence_level">The given confidence level</param>
        /// <param name="useStudentT">whether student t should be used for test statistic</param>
        /// <returns>The confidence level of the population mean at the given confidence level</returns>
        public static double[] GetConfidenceInterval(double[] sampleMeans, double[] sampleStdDev, int[] sampleSizes, double confidence_level, bool useStudentT = false)
        {
            double[] standardErrors = new double[sampleMeans.Length];
            for (int i = 0; i < sampleMeans.Length; ++i)
            {
                standardErrors[i] = StandardError.GetStandardError(sampleStdDev[i], sampleSizes[i]);
            }

            double standardError = StandardError.GetStandardErrorForWeightAverages(sampleSizes, standardErrors);
            double sampleMean    = Mean.GetMeanForWeightedAverage(sampleMeans, sampleSizes);

            double p1 = (1 - confidence_level) / 2.0;
            double p2 = 1 - p1;

            bool shouldUseStudentT = useStudentT;

            if (!shouldUseStudentT)
            {
                for (int i = 0; i < sampleSizes.Length; ++i)
                {
                    if (sampleSizes[i] < 30)
                    {
                        shouldUseStudentT = true;
                        break;
                    }
                }
            }

            double critical_value1 = 0;
            double critical_value2 = 0;

            if (shouldUseStudentT)
            {
                int smallestSampleSize = int.MaxValue;
                for (int i = 0; i < sampleSizes.Length; ++i)
                {
                    if (sampleSizes[i] < smallestSampleSize)
                    {
                        smallestSampleSize = sampleSizes[i];
                    }
                }
                int df = smallestSampleSize - 1;
                critical_value1 = StudentT.GetQuantile(p1, df);
                critical_value2 = StudentT.GetQuantile(p2, df);
            }
            else
            {
                critical_value1 = Gaussian.GetQuantile(p1);
                critical_value2 = Gaussian.GetQuantile(p2);
            }

            double[] confidence_interval = new double[2];
            confidence_interval[0] = sampleMean + critical_value1 * standardError;
            confidence_interval[1] = sampleMean + critical_value2 * standardError;

            return(confidence_interval);
        }
Ejemplo n.º 27
0
        public void ValidateVariance(
            [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 10.0, -5.0, 0.0)] double location,
            [Values(1.0, 0.1, 1.0, 10.0, 10.0, 10.0, 10.0, 1.0, 1.0, 100.0, Double.PositiveInfinity)] double scale,
            [Values(1.0, 1.0, 3.0, 1.0, 2.0, 2.5, Double.PositiveInfinity, 1.0, 2.5, 1.5, 1.0)] double dof,
            [Values(Double.NaN, Double.NaN, 3.0, Double.NaN, Double.PositiveInfinity, 500.0, 100.0, Double.NaN, 5.0, Double.PositiveInfinity, Double.NaN)] double var)
        {
            var n = new StudentT(location, scale, dof);

            Assert.AreEqual(var, n.Variance);
        }
Ejemplo n.º 28
0
        public void ValidateStdDev(
            [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 10.0, -5.0, 0.0)] double location,
            [Values(1.0, 0.1, 1.0, 10.0, 10.0, 10.0, 10.0, 1.0, 1.0, 100.0, Double.PositiveInfinity)] double scale,
            [Values(1.0, 1.0, 3.0, 1.0, 2.0, 2.5, Double.PositiveInfinity, 1.0, 2.5, 1.5, 1.0)] double dof,
            [Values(Double.NaN, Double.NaN, 1.7320508075688772935274463415059, Double.NaN, Double.PositiveInfinity, 22.360679774997896964091736687313, 10.0, Double.NaN, 2.2360679774997896964091736687313, Double.PositiveInfinity, Double.NaN)] double sdev)
        {
            var n = new StudentT(location, scale, dof);

            Assert.AreEqual(sdev, n.StdDev);
        }
Ejemplo n.º 29
0
        public void ValidateCumulativeDistribution(
            [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location,
            [Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale,
            [Values(1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof,
            [Values(0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, 2.0)] double x,
            [Values(0.5, 0.75, 0.25, 0.852416382349567, 0.147583617650433, 0.5, 0.788675134594813, 0.211324865405187, 0.908248290463863, 0.091751709536137, 0.5, 0.841344746068543, 0.977249868051821)] double c)
        {
            var n = new StudentT(location, scale, dof);

            AssertHelpers.AlmostEqual(c, n.CumulativeDistribution(x), 13);
        }
Ejemplo n.º 30
0
        public double GetMeanErrorAt(double confidence)
        {
            if (GetN() <= 2)
            {
                return(Double.NaN);
            }
            var    distribution = new StudentT(0, 1, GetN() - 1);
            double a            = distribution.InverseCumulativeDistribution(1 - (1 - confidence) / 2);

            return(a * GetStandardDeviation() / Math.Sqrt(GetN()));
        }
Ejemplo n.º 31
0
        public void ValidateDensityLn(
            [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location,
            [Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale,
            [Values(1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof,
            [Values(0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, 2.0)] double x,
            [Values(-1.144729885849399, -1.837877066409348, -1.837877066409348, -2.754167798283503, -2.754167798283503, -1.039720770839917, -1.647918433002166, -1.647918433002166, -2.687639203842085, -2.687639203842085, -0.918938533204672, -1.418938533204674, -2.918938533204674)] double p)
        {
            var n = new StudentT(location, scale, dof);

            AssertHelpers.AlmostEqual(p, n.DensityLn(x), 13);
        }
Ejemplo n.º 32
0
        public void ValidateDensity(
            [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location,
            [Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale,
            [Values(1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof,
            [Values(0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, 2.0)] double x,
            [Values(0.318309886183791, 0.159154943091895, 0.159154943091895, 0.063661977236758, 0.063661977236758, 0.353553390593274, 0.192450089729875, 0.192450089729875, 0.068041381743977, 0.068041381743977, 0.398942280401433, 0.241970724519143, 0.053990966513188)] double p)
        {
            var n = new StudentT(location, scale, dof);

            AssertHelpers.AlmostEqual(p, n.Density(x), 13);
        }
Ejemplo n.º 33
0
 //[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
 public static double TDist(double x, int degreesFreedom, int tails)
 {
     switch (tails)
     {
         case 1:
             return 1d - StudentT.CDF(0d, 1d, degreesFreedom, x);
         case 2:
             return 1d - StudentT.CDF(0d, 1d, degreesFreedom, x) + StudentT.CDF(0d, 1d, degreesFreedom, -x);
         default:
             throw new ArgumentOutOfRangeException("tails");
     }
 }
Ejemplo n.º 34
0
 public void ValidateMinimum()
 {
     var n = new StudentT();
     Assert.AreEqual(Double.NegativeInfinity, n.Minimum);
 }
Ejemplo n.º 35
0
 public void ValidateMode(
     [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 10.0, -5.0, 0.0)] double location, 
     [Values(1.0, 0.1, 1.0, 10.0, 10.0, 10.0, 10.0, 1.0, 1.0, 100.0, Double.PositiveInfinity)] double scale, 
     [Values(1.0, 1.0, 3.0, 1.0, 2.0, 2.5, Double.PositiveInfinity, 1.0, 2.5, 1.5, 1.0)] double dof)
 {
     var n = new StudentT(location, scale, dof);
     Assert.AreEqual(location, n.Mode);
 }
 public void SetScaleFailsWithNonPositiveScale(double scale)
 {
     {
         var n = new StudentT();
         n.Scale = scale;
     }
 }
 public void CanSampleSequence()
 {
     var n = new StudentT();
     var ied = n.Samples();
     var e = ied.Take(5).ToArray();
 }
Ejemplo n.º 38
0
 public void ValidateDensityLn(
     [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location, 
     [Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale, 
     [Values(1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof, 
     [Values(0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, 2.0)] double x, 
     [Values(-1.144729885849399, -1.837877066409348, -1.837877066409348, -2.754167798283503, -2.754167798283503, -1.039720770839917, -1.647918433002166, -1.647918433002166, -2.687639203842085, -2.687639203842085, -0.918938533204672, -1.418938533204674, -2.918938533204674)] double p)
 {
     var n = new StudentT(location, scale, dof);
     AssertHelpers.AlmostEqual(p, n.DensityLn(x), 13);
 }
 public void ValidateCumulativeDistribution(double location, double scale, double dof, double x, double c)
 {
     var n = new StudentT(location, scale, dof);
     AssertHelpers.AlmostEqual(c, n.CumulativeDistribution(x), 13);
 }
 public void ValidateToString()
 {
     var n = new StudentT(1.0, 2.0, 1.0);
     AssertEx.AreEqual<string>("StudentT(Location = 1, Scale = 2, DoF = 1)", n.ToString());
 }
 public void ValidateVariance(double location, double scale, double dof, double var)
 {
     var n = new StudentT(location, scale, dof);
     AssertEx.AreEqual<double>(var, n.Variance);
 }
 public void ValidateMode(double location, double scale, double dof)
 {
     var n = new StudentT(location, scale, dof);
     AssertEx.AreEqual<double>(location, n.Mode);
 }
 public void ValidateStdDev(double location, double scale, double dof, double sdev)
 {
     var n = new StudentT(location, scale, dof);
     AssertEx.AreEqual<double>(sdev, n.StdDev);
 }
 public void ValidateMinimum()
 {
     var n = new StudentT();
     AssertEx.AreEqual<double>(System.Double.NegativeInfinity, n.Minimum);
 }
 public void ValidateMean(double location, double scale, double dof, double mean)
 {
     var n = new StudentT(location, scale, dof);
     AssertEx.AreEqual<double>(mean, n.Mean);
 }
 public void ValidateDensityLn(double location, double scale, double dof, double x, double p)
 {
     var n = new StudentT(location, scale, dof);
     AssertHelpers.AlmostEqual(p, n.DensityLn(x), 13);
 }
Ejemplo n.º 47
0
 public void ValidateMean(
     [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, -5.0, 0.0)] double location, 
     [Values(1.0, 0.1, 1.0, 10.0, 10.0, 10.0, 1.0, 100.0, Double.PositiveInfinity)] double scale, 
     [Values(1.0, 1.0, 3.0, 1.0, 2.0, Double.PositiveInfinity, 1.0, 1.5, 1.0)] double dof, 
     [Values(Double.NaN, Double.NaN, 0.0, Double.NaN, 0.0, 0.0, Double.NaN, -5.0, Double.NaN)] double mean)
 {
     var n = new StudentT(location, scale, dof);
     Assert.AreEqual(mean, n.Mean);
 }
Ejemplo n.º 48
0
 public void ValidateCumulativeDistribution(
     [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location, 
     [Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale, 
     [Values(1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof, 
     [Values(0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, 2.0)] double x, 
     [Values(0.5, 0.75, 0.25, 0.852416382349567, 0.147583617650433, 0.5, 0.788675134594813, 0.211324865405187, 0.908248290463863, 0.091751709536137, 0.5, 0.841344746068543, 0.977249868051821)] double c)
 {
     var n = new StudentT(location, scale, dof);
     AssertHelpers.AlmostEqual(c, n.CumulativeDistribution(x), 13);
 }
Ejemplo n.º 49
0
 public void ValidateMaximum()
 {
     var n = new StudentT();
     Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
 }
Ejemplo n.º 50
0
 public void SetDofFailsWithNonPositiveDoF([Values(-1.0, -0.0, 0.0)] double dof)
 {
     var n = new StudentT();
     Assert.Throws<ArgumentOutOfRangeException>(() => n.DegreesOfFreedom = dof);
 }
Ejemplo n.º 51
0
 public void ValidateDensity(
     [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location, 
     [Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale, 
     [Values(1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof, 
     [Values(0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, 2.0)] double x, 
     [Values(0.318309886183791, 0.159154943091895, 0.159154943091895, 0.063661977236758, 0.063661977236758, 0.353553390593274, 0.192450089729875, 0.192450089729875, 0.068041381743977, 0.068041381743977, 0.398942280401433, 0.241970724519143, 0.053990966513188)] double p)
 {
     var n = new StudentT(location, scale, dof);
     AssertHelpers.AlmostEqual(p, n.Density(x), 13);
 }
 public void StudentTCreateFailsWithBadParameters(double location, double scale, double dof)
 {
     var n = new StudentT(location, scale, dof);
 }
Ejemplo n.º 53
0
 public void SetScaleFailsWithNonPositiveScale([Values(-1.0, -0.0, 0.0)] double scale)
 {
     var n = new StudentT();
     Assert.Throws<ArgumentOutOfRangeException>(() => n.Scale = scale);
 }
 public void CanSetLocation(double loc)
 {
     var n = new StudentT();
     n.Location = loc;
 }
Ejemplo n.º 55
0
 public void ValidateVariance(
     [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 10.0, -5.0, 0.0)] double location, 
     [Values(1.0, 0.1, 1.0, 10.0, 10.0, 10.0, 10.0, 1.0, 1.0, 100.0, Double.PositiveInfinity)] double scale, 
     [Values(1.0, 1.0, 3.0, 1.0, 2.0, 2.5, Double.PositiveInfinity, 1.0, 2.5, 1.5, 1.0)] double dof, 
     [Values(Double.NaN, Double.NaN, 3.0, Double.NaN, Double.PositiveInfinity, 500.0, 100.0, Double.NaN, 5.0, Double.PositiveInfinity, Double.NaN)] double var)
 {
     var n = new StudentT(location, scale, dof);
     Assert.AreEqual(var, n.Variance);
 }
 public void CanSetScale(double scale)
 {
     var n = new StudentT();
     n.Scale = scale;
 }
Ejemplo n.º 57
0
 public void ValidateStdDev(
     [Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 10.0, -5.0, 0.0)] double location, 
     [Values(1.0, 0.1, 1.0, 10.0, 10.0, 10.0, 10.0, 1.0, 1.0, 100.0, Double.PositiveInfinity)] double scale, 
     [Values(1.0, 1.0, 3.0, 1.0, 2.0, 2.5, Double.PositiveInfinity, 1.0, 2.5, 1.5, 1.0)] double dof, 
     [Values(Double.NaN, Double.NaN, 1.7320508075688772935274463415059, Double.NaN, Double.PositiveInfinity, 22.360679774997896964091736687313, 10.0, Double.NaN, 2.2360679774997896964091736687313, Double.PositiveInfinity, Double.NaN)] double sdev)
 {
     var n = new StudentT(location, scale, dof);
     Assert.AreEqual(sdev, n.StdDev);
 }
 public void CanSample()
 {
     var n = new StudentT();
     var d = n.Sample();
 }
 public void SetDofFailsWithNonPositiveDoF(double dof)
 {
     {
         var n = new StudentT();
         n.DegreesOfFreedom = dof;
     }
 }
 public void CanSetDoF(double dof)
 {
     var n = new StudentT();
     n.DegreesOfFreedom = dof;
 }