private void compute(double[][] samples, LeveneTestMethod method, double percent) { this.Method = method; int N = 0, k = samples.Length; // Compute group means var means = new double[samples.Length]; switch (method) { case LeveneTestMethod.Mean: for (int i = 0; i < means.Length; i++) { means[i] = samples[i].Mean(); } break; case LeveneTestMethod.Median: for (int i = 0; i < means.Length; i++) { means[i] = samples[i].Median(); } break; case LeveneTestMethod.TruncatedMean: for (int i = 0; i < means.Length; i++) { means[i] = samples[i].TruncatedMean(percent); } break; } // Compute absolute centered samples var z = new double[samples.Length][]; for (int i = 0; i < z.Length; i++) { z[i] = new double[samples[i].Length]; for (int j = 0; j < z[i].Length; j++) { z[i][j] = Math.Abs(samples[i][j] - means[i]); } } // Compute means for the centered samples var newMeans = new double[samples.Length]; for (int i = 0; i < newMeans.Length; i++) { newMeans[i] = z[i].Mean(); } // Compute total mean double totalMean = 0; for (int i = 0; i < samples.Length; i++) { for (int j = 0; j < samples[i].Length; j++) { totalMean += z[i][j]; } N += samples[i].Length; } totalMean /= N; double sum1 = 0; // Numerator sum for (int i = 0; i < samples.Length; i++) { int n = samples[i].Length; double u = (newMeans[i] - totalMean); sum1 += n * u * u; } double sum2 = 0; // Denominator sum for (int i = 0; i < samples.Length; i++) { for (int j = 0; j < samples[i].Length; j++) { double u = z[i][j] - newMeans[i]; sum2 += u * u; } } double num = (N - k) * sum1; double den = (k - 1) * sum2; double W = num / den; int degree1 = k - 1; int degree2 = N - k; Compute(W, degree1, degree2, TwoSampleHypothesis.FirstValueIsGreaterThanSecond); }
private void compute(double[][] samples, LeveneTestMethod method, double percent) { this.Method = method; int N = 0, k = samples.Length; // Compute group means var means = new double[samples.Length]; switch (method) { case LeveneTestMethod.Mean: for (int i = 0; i < means.Length; i++) means[i] = Accord.Statistics.Tools.Mean(samples[i]); break; case LeveneTestMethod.Median: for (int i = 0; i < means.Length; i++) means[i] = Accord.Statistics.Tools.Median(samples[i]); break; case LeveneTestMethod.TruncatedMean: for (int i = 0; i < means.Length; i++) means[i] = Accord.Statistics.Tools.TruncatedMean(samples[i], percent); break; } // Compute absolute centered samples var z = new double[samples.Length][]; for (int i = 0; i < z.Length; i++) { z[i] = new double[samples[i].Length]; for (int j = 0; j < z[i].Length; j++) z[i][j] = Math.Abs(samples[i][j] - means[i]); } // Compute means for the centered samples var newMeans = new double[samples.Length]; for (int i = 0; i < newMeans.Length; i++) newMeans[i] = Accord.Statistics.Tools.Mean(z[i]); // Compute total mean double totalMean = 0; for (int i = 0; i < samples.Length; i++) { for (int j = 0; j < samples[i].Length; j++) totalMean += z[i][j]; N += samples[i].Length; } totalMean /= N; double sum1 = 0; // Numerator sum for (int i = 0; i < samples.Length; i++) { int n = samples[i].Length; double u = (newMeans[i] - totalMean); sum1 += n * u * u; } double sum2 = 0; // Denominator sum for (int i = 0; i < samples.Length; i++) { for (int j = 0; j < samples[i].Length; j++) { double u = z[i][j] - newMeans[i]; sum2 += u * u; } } double num = (N - k) * sum1; double den = (k - 1) * sum2; double W = num / den; int degree1 = k - 1; int degree2 = N - k; Compute(W, degree1, degree2, TwoSampleHypothesis.FirstValueIsGreaterThanSecond); }