Accord.Statistics.Testing.Power.BaseTwoSamplePowerAnalysis.ComputeSamples C# (CSharp) Method

ComputeSamples() public method

Computes the recommended sample size for the test to attain the power indicated in Power considering values of Effect and Size.
public ComputeSamples ( double proportion = 1 ) : void
proportion double
return void
        public virtual void ComputeSamples(double proportion = 1)
        {
            double requiredPower = Power;

            // Attempt to locate the optimal sample size
            // to attain the required power by locating
            // a zero in the difference function:

            double sol = BrentSearch.FindRoot(n =>
            {
                Samples1 = n;
                Samples2 = n * proportion;

                ComputePower();

                return requiredPower - Power;
            },

            lowerBound: 2,
            upperBound: 1e+4);


            // Check it
            Samples1 = sol;
            Samples2 = sol * proportion;
            ComputePower();

            double newPower = Power;
            Power = requiredPower;

            if (Math.Abs(requiredPower - newPower) > 1e-5)
                Samples1 = Samples2 = Double.NaN;
        }