コード例 #1
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="proportion">The proportion of observations in the second group
        /// when compared to the first group. A proportion of 2:1 results in twice more
        /// samples in the second group than in the first. Default is 1.</param>
        /// <param name="hypothesis">The alternative hypothesis (research hypothesis) to be tested.</param>
        ///
        /// <returns>The required number of samples.</returns>
        ///
        public static TwoSampleTTestPowerAnalysis GetSampleSize(double delta,
                                                                double standardDeviation       = 1, double proportion = 1.0, double power = 0.8, double alpha = 0.05,
                                                                TwoSampleHypothesis hypothesis = TwoSampleHypothesis.ValuesAreDifferent)
        {
            var analysis = new TwoSampleTTestPowerAnalysis(hypothesis)
            {
                Effect = delta / standardDeviation,
                Size   = alpha,
                Power  = power,
            };

            analysis.ComputeSamples(proportion);

            return(analysis);
        }
コード例 #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="variance1">The first sample variance.</param>
        /// <param name="variance2">The second sample variance.</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="proportion">The proportion of observations in the second group
        /// when compared to the first group. A proportion of 2:1 results in twice more
        /// samples in the second group than in the first. Default is 1.</param>
        /// <param name="hypothesis">The alternative hypothesis (research hypothesis) to be tested.</param>
        ///
        /// <returns>The required number of samples.</returns>
        ///
        public static TwoSampleTTestPowerAnalysis GetSampleSize(
            double delta,
            double variance1,
            double variance2,
            double proportion,        //= 1.0,
            double power,             // = 0.8,
            double alpha,             // = 0.05,
            TwoSampleHypothesis hypothesis = TwoSampleHypothesis.ValuesAreDifferent
            )
        {
            double standardDeviation = Math.Sqrt((variance1 + variance2) / 2.0);

            var analysis = new TwoSampleTTestPowerAnalysis(hypothesis)
            {
                Effect = delta / standardDeviation,
                Size   = alpha,
                Power  = power,
            };

            analysis.ComputeSamples(proportion);

            return(analysis);
        }
コード例 #3
0
        public void TTestPowerAnalysisConstructorTest3()
        {
            // Examples from R's graphical manual
            // http://rgm2.lab.nig.ac.jp/RGM2/func.php?rd_id=pwr:pwr.t.test

            double actual, expected;

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

                target.ComputePower();

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

            {
                var target = new TwoSampleTTestPowerAnalysis(TwoSampleHypothesis.ValuesAreDifferent)
                {
                    Effect = 2 / 2.8,
                    Samples1 = 30,
                    Samples2 = 30,
                };

                target.ComputePower();

                expected = 0.7764889;
                actual = target.Power;
                Assert.AreEqual(expected, actual, 1e-6);
            }

            {
                var target = new TwoSampleTTestPowerAnalysis(TwoSampleHypothesis.FirstValueIsGreaterThanSecond)
                {
                    Effect = 0.3,
                    Power = 0.75,
                };

                target.ComputeSamples();

                expected = 120.2232016;
                actual = target.Samples1;
                Assert.AreEqual(expected, actual, 1e-6);
                Assert.AreEqual(target.Samples1, target.Samples2);
            }
        }
コード例 #4
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="variance1">The first sample variance.</param>
        /// <param name="variance2">The second sample variance.</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="proportion">The proportion of observations in the second group
        /// when compared to the first group. A proportion of 2:1 results in twice more
        /// samples in the second group than in the first. Default is 1.</param>
        /// <param name="hypothesis">The alternative hypothesis (research hypothesis) to be tested.</param>
        /// 
        /// <returns>The required number of samples.</returns>
        /// 
        public static TwoSampleTTestPowerAnalysis GetSampleSize(double delta,
            double variance1, double variance2, double proportion = 1.0, double power = 0.8,
            double alpha = 0.05, TwoSampleHypothesis hypothesis = TwoSampleHypothesis.ValuesAreDifferent)
        {
            double standardDeviation = Math.Sqrt((variance1 + variance2) / 2.0);

            var analysis = new TwoSampleTTestPowerAnalysis(hypothesis)
            {
                Effect = delta / standardDeviation,
                Size = alpha,
                Power = power,
            };

            analysis.ComputeSamples(proportion);

            return analysis;
        }