1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2009 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Drawing;
|
---|
26 | using System.Data;
|
---|
27 | using System.Linq;
|
---|
28 | using System.Text;
|
---|
29 | using System.Windows.Forms;
|
---|
30 | using HeuristicLab.Core;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.StatisticalAnalysis {
|
---|
33 | public partial class MannWhitneyWilcoxonTestControl : EditorBase {
|
---|
34 | public MannWhitneyWilcoxonTestControl()
|
---|
35 | : base() {
|
---|
36 | InitializeComponent();
|
---|
37 | alphaTextBox.Text = ((double)0.05).ToString();
|
---|
38 | }
|
---|
39 |
|
---|
40 | private void ArrayToString<T>(T[] array, TextBox p) {
|
---|
41 | StringBuilder s = new StringBuilder();
|
---|
42 | foreach (T element in array)
|
---|
43 | s.Append(element + "; ");
|
---|
44 | s.Remove(s.Length - 2, 2);
|
---|
45 | p.Text = s.ToString();
|
---|
46 | }
|
---|
47 |
|
---|
48 | private double[] ConvertStringToArray(TextBox p) {
|
---|
49 | string t = p.Text;
|
---|
50 | string[] s = t.Split(new char[] { ';', ' ', '\t' });
|
---|
51 | List<double> tmp = new List<double>();
|
---|
52 | for (int i = 0; i < s.Length; i++) {
|
---|
53 | try {
|
---|
54 | double val = double.Parse(s[i]);
|
---|
55 | tmp.Add(val);
|
---|
56 | }
|
---|
57 | catch (FormatException) { }
|
---|
58 | }
|
---|
59 | if (tmp.Count > 0) return tmp.ToArray();
|
---|
60 | else return null;
|
---|
61 | }
|
---|
62 |
|
---|
63 | private void testApproximateButton_Click(object sender, EventArgs e) {
|
---|
64 | double[] p1 = ConvertStringToArray(p1TextBox);
|
---|
65 | double[] p2 = ConvertStringToArray(p2TextBox);
|
---|
66 | if (p1.Length < 10 || p2.Length < 10) {
|
---|
67 | MessageBox.Show("Caution: Sample size is too small for good approximation, treat the results carefully. Provide at least 10 samples in each population.");
|
---|
68 | }
|
---|
69 | double alpha = Double.Parse(alphaTextBox.Text);
|
---|
70 | double pVal = MannWhitneyWilcoxonTest.TwoTailedTest(p1, p2);
|
---|
71 | if (pVal <= alpha) {
|
---|
72 | resultLabel.Text = "The hypothesis H0 can be rejected at " + alpha.ToString() + ", the approximated p-Value is " + pVal.ToString() + "\nThe samples are not likely to stem from the same distribution.";
|
---|
73 | } else {
|
---|
74 | resultLabel.Text = "The hypothesis H0 cannot be rejected at " + alpha.ToString();
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | private void testExactButton_Click(object sender, EventArgs e) {
|
---|
79 | double[] p1 = ConvertStringToArray(p1TextBox);
|
---|
80 | double[] p2 = ConvertStringToArray(p2TextBox);
|
---|
81 | if (p1.Length > 20 || p2.Length > 20) {
|
---|
82 | double[] tmp = new double[Math.Min(20, p1.Length)];
|
---|
83 | for (int i = 0; i < Math.Min(20, p1.Length); i++) tmp[i] = p1[i];
|
---|
84 | p1 = tmp;
|
---|
85 | tmp = new double[Math.Min(20, p2.Length)];
|
---|
86 | for (int i = 0; i < Math.Min(20, p2.Length); i++) tmp[i] = p2[i];
|
---|
87 | p2 = tmp;
|
---|
88 | MessageBox.Show("Caution: Sample size is too large for exact calculation. Only the first 20 samples are used for the test!");
|
---|
89 | }
|
---|
90 | double alpha = Double.Parse(alphaTextBox.Text);
|
---|
91 | if (MannWhitneyWilcoxonTest.TwoTailedTest(p1, p2, alpha)) {
|
---|
92 | resultLabel.Text = "The hypothesis H0 can be rejected at " + alpha.ToString() + "\nThe samples are likely not to stem from the same distribution.";
|
---|
93 | } else {
|
---|
94 | resultLabel.Text = "The hypothesis H0 cannot be rejected at " + alpha.ToString();
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|