public void TTestConstructorTest() { // Suppose we would like to know the effect of a treatment (such // as a new drug) in improving the well-being of 9 patients. The // well-being is measured in a discrete scale, going from 0 to 10. // // To do so, we need to register the initial state of each patient // and then register their state after a given time under treatment. double[,] patients = { // before after // treatment treatment /* Patient 1.*/ { 0, 1 }, /* Patient 2.*/ { 6, 5 }, /* Patient 3.*/ { 4, 9 }, /* Patient 4.*/ { 8, 6 }, /* Patient 5.*/ { 1, 6 }, /* Patient 6.*/ { 6, 7 }, /* Patient 7.*/ { 3, 4 }, /* Patient 8.*/ { 8, 7 }, /* Patient 9.*/ { 6, 5 }, }; // Extract the before and after columns double[] before = patients.GetColumn(0); double[] after = patients.GetColumn(1); // Create the paired-sample T-test. Our research hypothesis is // that the treatment does improve the patient's well-being. So // we will be testing the hypothesis that the well-being of the // "before" sample, the first sample, is "smaller" in comparison // to the "after" treatment group. PairedTTest test = new PairedTTest(before, after, TwoSampleHypothesis.FirstValueIsSmallerThanSecond); bool significant = test.Significant; // false double pvalue = test.PValue; // ~ 0.165 Assert.IsFalse(significant); Assert.AreEqual(0.16500, pvalue, 1e-5); Assert.AreEqual(-1.03712, test.Statistic, 1e-5); Assert.AreEqual(-0.8888889, test.ObservedDifference, 1e-6); }
protected override void EndProcessing() { var hypo = TestingHelper.GetTwoSampleHypothesis(Alternate); PairedTTest test; if (ParameterSetName == "Pipeline") { test = new PairedTTest(_data[Sample1Name].ToDoubleArray(), _data[Sample2Name].ToDoubleArray(), hypo); } else { test = new PairedTTest(Sample1, Sample2, hypo); } test.Size = Size; WriteObject(test); }
private void Button_Click(object sender, RoutedEventArgs e) { List <double> vpop1 = new List <double>(); List <double> vpop2 = new List <double>(); try { //Try comma separated instead var TextScores = pop1.Text.Replace(" ", string.Empty).Split(',').ToList(); foreach (var S in TextScores) { vpop1.Add(double.Parse(S)); } TextScores = pop2.Text.Replace(" ", string.Empty).Split(',').ToList(); foreach (var S in TextScores) { vpop2.Add(double.Parse(S)); } } catch { return; } var Hypo = TwoSampleHypothesis.FirstValueIsGreaterThanSecond; switch (((Button)sender).Content.ToString()) { case "Dif": Hypo = TwoSampleHypothesis.ValuesAreDifferent; break; case "Less": Hypo = TwoSampleHypothesis.FirstValueIsSmallerThanSecond; break; case "More": Hypo = TwoSampleHypothesis.FirstValueIsGreaterThanSecond; break; default: break; } dynamic test, testWilcoxon; if (vpop1.Count == vpop2.Count) { test = new PairedTTest(vpop1.ToArray(), vpop2.ToArray(), Hypo); testWilcoxon = new TwoSampleWilcoxonSignedRankTest(vpop1.ToArray(), vpop2.ToArray(), Hypo); } else { test = new TTest( vpop1.ToArray(), vpop2[0], OneSampleHypothesis.ValueIsSmallerThanHypothesis); testWilcoxon = new WilcoxonSignedRankTest( vpop1.ToArray(), vpop2[0], OneSampleHypothesis.ValueIsSmallerThanHypothesis); } results.Text = "T-Test:\n Significant: " + test.Significant + "\n p-value: " + test.PValue + "\nMannWhitneyWilcoxon Test:\n Significant: " + testWilcoxon.Significant + "\n p-value: " + testWilcoxon.PValue; }
public void TTestConstructorTest() { // Suppose we would like to know the effect of a treatment (such // as a new drug) in improving the well-being of 9 patients. The // well-being is measured in a discrete scale, going from 0 to 10. // // To do so, we need to register the initial state of each patient // and then register their state after a given time under treatment. double[,] patients = { // before after // treatment treatment /* Patient 1.*/ { 0, 1 }, /* Patient 2.*/ { 6, 5 }, /* Patient 3.*/ { 4, 9 }, /* Patient 4.*/ { 8, 6 }, /* Patient 5.*/ { 1, 6 }, /* Patient 6.*/ { 6, 7 }, /* Patient 7.*/ { 3, 4 }, /* Patient 8.*/ { 8, 7 }, /* Patient 9.*/ { 6, 5 }, }; // Extract the before and after columns double[] before = patients.GetColumn(0); double[] after = patients.GetColumn(1); // Create the paired-sample T-test. Our research hypothesis is // that the treatment does improve the patient's well-being. So // we will be testing the hypothesis that the well-being of the // "before" sample, the first sample, is "smaller" in comparison // to the "after" treatment group. PairedTTest test = new PairedTTest(before, after, TwoSampleHypothesis.FirstValueIsSmallerThanSecond); bool significant = test.Significant; // false double pvalue = test.PValue; // ~ 0.165 Assert.IsFalse(significant); Assert.AreEqual(0.16500, pvalue, 1e-5); Assert.AreEqual(-1.03712, test.Statistic, 1e-5); Assert.AreEqual(-0.8888889, test.ObservedDifference,1e-6); }