CsCheck/Check.cs
/// <summary>Assert actual is in line with expected using a chi-squared test to 6 sigma.</summary>
/// <param name="actual">The actual bin counts.</param>
/// <param name="expected">The expected bin counts.</param>
Assert actual is in line with expected using a chi-squared test to 6 sigma.
Assert actual is in line with expected using a chi - squared test to 6 sigma .
public static void ChiSquared(int[] expected, int[] actual)
        {
            if (expected.Length != actual.Length) throw new CsCheckException("Expected and actual lengths need to be the same.");
            if (Array.Exists(expected, e => e <= 5)) throw new CsCheckException("Expected frequency for all buckets needs to be above 5.");
            double chi = 0.0;
            for (int i = 0; i < expected.Length; i++)
            {
                double e = expected[i];
                double d = actual[i] - e;
                chi += d * d / e;
            }
            int k = expected.Length - 1;
            double sigmaSquared = (chi - k) * (chi - k) / k / 2.0;
            if (sigmaSquared > 36.0) throw new CsCheckException(
                "Chi-squared standard deviation = " + Math.Sqrt(sigmaSquared).ToString("0.0"));
        }
public static void ChiSquared ( int [ ] expected , int [ ] actual ) { if ( expected . Length != actual . Length ) throw new CsCheckException ( " " ) ; if ( Array . Exists ( expected , e => e <= 5 ) ) throw new CsCheckException ( " " ) ; double chi = 0.0 ; for ( int i = 0 ; i < expected . Length ; i ++ ) { double e = expected [ i ] ; double d = actual [ i ] - e ; chi += d * d / e ; } int k = expected . Length - 1 ; double sigmaSquared = ( chi - k ) * ( chi - k ) / k / 2.0 ; if ( sigmaSquared > 36.0 ) throw new CsCheckException ( " " + Math . Sqrt ( sigmaSquared ) . ToString ( " " ) ) ; }
Assert actual is in line with expected using a chi-squared test to 6 sigma.
Assert actual is in line with expected using a chi - squared test to 6 sigma .
// chi-squared distribution has Mean = k and Variance = 2 k where k is the number of degrees of freedom.
expected
int[]
The expected bin counts.
The expected bin counts .
actual
int[]
The actual bin counts.
The actual bin counts .