Inheritance: BaseOneSamplePowerAnalysis
Exemplo n.º 1
0
        /// <summary>
        ///   Estimates the number of samples necessary to attain the
        ///   required power level for the given effect size.
        /// </summary>
        ///
        /// <param name="sampleSize">The number of observations in the sample.</param>
        /// <param name="power">The desired power level. Default is 0.8.</param>
        /// <param name="alpha">The desired significance level. Default is 0.05.</param>
        /// <param name="hypothesis">The alternative hypothesis (research hypothesis) to be tested.</param>
        ///
        /// <returns>The required number of samples.</returns>
        ///
        public static ZTestPowerAnalysis GetEffectSize(int sampleSize, double power   = 0.8, double alpha = 0.05,
                                                       OneSampleHypothesis hypothesis = OneSampleHypothesis.ValueIsDifferentFromHypothesis)
        {
            var analysis = new ZTestPowerAnalysis(hypothesis)
            {
                Samples = sampleSize,
                Size    = alpha,
                Power   = power,
            };

            analysis.ComputeEffect();

            return(analysis);
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Estimates the number of samples necessary to attain the
        ///   required power level for the given effect size.
        /// </summary>
        ///
        /// <param name="delta">The minimum detectable difference.</param>
        /// <param name="standardDeviation">The difference standard deviation.</param>
        /// <param name="power">The desired power level. Default is 0.8.</param>
        /// <param name="alpha">The desired significance level. Default is 0.05.</param>
        /// <param name="hypothesis">The alternative hypothesis (research hypothesis) to be tested.</param>
        ///
        /// <returns>The required number of samples.</returns>
        ///
        public static ZTestPowerAnalysis GetSampleSize(double delta,
                                                       double standardDeviation       = 1, double power = 0.8, double alpha = 0.05,
                                                       OneSampleHypothesis hypothesis = OneSampleHypothesis.ValueIsDifferentFromHypothesis)
        {
            ZTestPowerAnalysis analysis = new ZTestPowerAnalysis(hypothesis)
            {
                Effect = (delta) / standardDeviation,
                Size   = alpha,
                Power  = power,
            };

            analysis.ComputeSamples();

            return(analysis);
        }
        public void ZTestPowerAnalysisConstructorTest1()
        {
            ZTestPowerAnalysis target;
            double actual, expected;

            target = new ZTestPowerAnalysis(OneSampleHypothesis.ValueIsDifferentFromHypothesis)
            {
                Effect = 0.2,
                Samples = 60,
                Size = 0.10,
            };

            target.ComputePower();

            expected = 0.4618951;
            actual = target.Power;
            Assert.AreEqual(expected, actual, 1e-5);


            target = new ZTestPowerAnalysis(OneSampleHypothesis.ValueIsSmallerThanHypothesis)
            {
                Effect = 0.2,
                Samples = 60,
                Size = 0.10,
            };

            target.ComputePower();

            expected = 0.00232198;
            actual = target.Power;
            Assert.AreEqual(expected, actual, 1e-5);


            target = new ZTestPowerAnalysis(OneSampleHypothesis.ValueIsGreaterThanHypothesis)
            {
                Effect = 0.2,
                Samples = 60,
                Size = 0.10,
            };

            target.ComputePower();

            expected = 0.6055124;
            actual = target.Power;
            Assert.AreEqual(expected, actual, 1e-5);
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Estimates the number of samples necessary to attain the
        ///   required power level for the given effect size.
        /// </summary>
        /// 
        /// <param name="sampleSize">The number of observations in the sample.</param>
        /// <param name="power">The desired power level. Default is 0.8.</param>
        /// <param name="alpha">The desired significance level. Default is 0.05.</param>
        /// <param name="hypothesis">The alternative hypothesis (research hypothesis) to be tested.</param>
        /// 
        /// <returns>The required number of samples.</returns>
        /// 
        public static ZTestPowerAnalysis GetEffectSize(int sampleSize, double power = 0.8, double alpha = 0.05,
            OneSampleHypothesis hypothesis = OneSampleHypothesis.ValueIsDifferentFromHypothesis)
        {
            var analysis = new ZTestPowerAnalysis(hypothesis)
            {
                Samples = sampleSize,
                Size = alpha,
                Power = power,
            };

            analysis.ComputeEffect();

            return analysis;
        }
Exemplo n.º 5
0
        /// <summary>
        ///   Estimates the number of samples necessary to attain the
        ///   required power level for the given effect size.
        /// </summary>
        /// 
        /// <param name="delta">The minimum detectable difference.</param>
        /// <param name="standardDeviation">The difference standard deviation.</param>
        /// <param name="power">The desired power level. Default is 0.8.</param>
        /// <param name="alpha">The desired significance level. Default is 0.05.</param>
        /// <param name="hypothesis">The alternative hypothesis (research hypothesis) to be tested.</param>
        /// 
        /// <returns>The required number of samples.</returns>
        /// 
        public static ZTestPowerAnalysis GetSampleSize(double delta,
            double standardDeviation = 1, double power = 0.8, double alpha = 0.05,
           OneSampleHypothesis hypothesis = OneSampleHypothesis.ValueIsDifferentFromHypothesis)
        {
            ZTestPowerAnalysis analysis = new ZTestPowerAnalysis(hypothesis)
            {
                Effect = (delta) / standardDeviation,
                Size = alpha,
                Power = power,
            };

            analysis.ComputeSamples();

            return analysis;
        }
        public void ZTestPowerAnalysisConstructorTest2()
        {
            // When creating a power analysis, we have three things we can
            // change. We can always freely configure two of those things
            // and then ask the analysis to give us the third.

            var analysis = new ZTestPowerAnalysis(OneSampleHypothesis.ValueIsDifferentFromHypothesis);

            // Those are:
            double e = analysis.Effect;   // the test's minimum detectable effect size
            double n = analysis.Samples;  // the number of samples in the test
            double p = analysis.Power;    // the probability of committing a type-2 error

            // Let's set the desired effect size and the 
            // number of samples so we can get the power

            analysis.Effect = 0.2; // we would like to detect at least 0.2 std. dev. apart
            analysis.Samples = 60; // we would like to use at most 60 samples
            analysis.ComputePower(); // what will be the power of this test?

            double power = analysis.Power; // The power is going to be 0.34 (or 34%)

            // Let's set the desired power and the number 
            // of samples so we can get the effect size

            analysis.Power = 0.8;  // we would like to create a test with 80% power
            analysis.Samples = 60; // we would like to use at most 60 samples
            analysis.ComputeEffect(); // what would be the minimum effect size we can detect?

            double effect = analysis.Effect; // The effect will be 0.36 standard deviations.

            // Let's set the desired power and the effect
            // size so we can get the number of samples

            analysis.Power = 0.8;  // we would like to create a test with 80% power
            analysis.Effect = 0.2; // we would like to detect at least 0.2 std. dev. apart
            analysis.ComputeSamples();

            double samples = analysis.Samples; // We would need around 197 samples.

            Assert.AreEqual(196.22199335872716, samples); // 196.22199335872716
            Assert.AreEqual(0.36168309642441332, effect);
            Assert.AreEqual(0.34062035960875625, power);
        }