Changeset 11696
- Timestamp:
- 12/18/14 16:12:19 (10 years ago)
- Location:
- branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/StatisticalTestsView.cs
r11695 r11696 91 91 protected override void RegisterContentEvents() { 92 92 base.RegisterContentEvents(); 93 Content. ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);94 Content. ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);93 Content.ColumnsChanged += Content_ColumnsChanged; 94 Content.RowsChanged += Content_RowsChanged; 95 95 Content.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset); 96 96 Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged; … … 99 99 protected override void DeregisterContentEvents() { 100 100 base.DeregisterContentEvents(); 101 Content. ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);102 Content. ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);101 Content.ColumnsChanged -= Content_ColumnsChanged; 102 Content.RowsChanged -= Content_RowsChanged; 103 103 Content.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset); 104 104 Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged; 105 105 } 106 106 107 void Content_RowsChanged(object sender, EventArgs e) { 108 RebuildDataTable(); 109 } 110 111 void Content_ColumnsChanged(object sender, EventArgs e) { 112 RebuildDataTable(); 113 } 114 107 115 private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 108 RebuildDataTable();109 }110 111 private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {112 RebuildDataTable();113 }114 115 private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {116 116 RebuildDataTable(); 117 117 } … … 301 301 302 302 private void CalculateValuesAsync(string groupName) { 303 TestAllGroups(); 304 CalculateNormality(); 305 CalculateNormalityDetails(); 303 CalculateAllGroupsTest(); 304 CalculateNormalityTest(); 306 305 CalculatePairwiseTest(groupName); 307 CalculatePairwiseTestDetails(groupName);308 306 309 307 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); … … 320 318 private void CalculatePairwiseAsync(string groupName) { 321 319 CalculatePairwiseTest(groupName); 322 CalculatePairwiseTestDetails(groupName);323 320 324 321 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox); 325 322 } 326 323 327 private void TestAllGroups() {324 private void CalculateAllGroupsTest() { 328 325 double pval = KruskalWallisTest.Test(data); 329 326 pValTextBox.Text = pval.ToString(); … … 341 338 } 342 339 343 private void CalculateNormality () {340 private void CalculateNormalityTest() { 344 341 double val; 345 342 List<double> res = new List<double>(); 343 DoubleMatrix pValsMatrix = new DoubleMatrix(1, stringConvertibleMatrixView.Content.Columns); 344 pValsMatrix.ColumnNames = stringConvertibleMatrixView.Content.ColumnNames; 345 pValsMatrix.RowNames = new string[] { "p-Value" }; 346 346 347 347 for (int i = 0; i < data.Length; i++) { 348 348 alglib.jarqueberatest(data[i], data[i].Length, out val); 349 349 res.Add(val); 350 } 351 352 // p-value is below significance level and thus the null hypothesis (data is normally distributed) is rejected. 350 pValsMatrix[0, i] = val; 351 } 352 353 // p-value is below significance level and thus the null hypothesis (data is normally distributed) is rejected 353 354 if (res.Any(x => x < significanceLevel)) { 354 355 this.Invoke(new Action(() => { … … 361 362 normalityTextLabel.Text = "All sample data is normally distributed"; 362 363 })); 363 }364 }365 366 private void CalculateNormalityDetails() {367 DoubleMatrix pValsMatrix = new DoubleMatrix(1, stringConvertibleMatrixView.Content.Columns);368 pValsMatrix.ColumnNames = stringConvertibleMatrixView.Content.ColumnNames;369 pValsMatrix.RowNames = new string[] { "p-Value" };370 371 double val;372 for (int i = 0; i < data.Length; i++) {373 alglib.jarqueberatest(data[i], data[i].Length, out val);374 pValsMatrix[0, i] = val;375 364 } 376 365 … … 381 370 } 382 371 383 private void CalculatePairwiseTest(string groupName) { 384 int colIndex = 0; 385 IEnumerable<string> columnNames = null; 386 this.Invoke(new Action(() => { columnNames = stringConvertibleMatrixView.Content.ColumnNames; })); 387 388 foreach (string col in columnNames) { 389 if (col == groupName) { 390 break; 391 } 392 colIndex++; 393 } 394 395 double[][] newData = FilterDataForPairwiseTest(colIndex); 396 int cnt = 0; 397 for (int i = 0; i < newData.Length; i++) { 398 double mwuBothtails = PairwiseTest.MannWhitneyUTest(data[colIndex], newData[i]); 399 if (mwuBothtails > significanceLevel) { 400 cnt++; 401 } 402 } 403 404 double ratio = ((double)cnt) / (data.Length - 1) * 100.0; 372 private void ShowPairwiseResult(int nrOfEqualDistributions) { 373 double ratio = ((double)nrOfEqualDistributions) / (data.Length - 1) * 100.0; 405 374 equalDistsTextBox.Text = ratio.ToString() + " %"; 406 375 407 if ( cnt== 0) {376 if (nrOfEqualDistributions == 0) { 408 377 this.Invoke(new Action(() => { 409 378 pairwiseLabel.Image = HeuristicLab.Analysis.Statistics.Resources.Default; … … 416 385 })); 417 386 } 387 } 388 389 private void CalculatePairwiseTest(string groupName) { 390 var columnNames = stringConvertibleMatrixView.Content.ColumnNames.ToList(); 391 int colIndex = columnNames.IndexOf(groupName); 392 columnNames = columnNames.Where(x => x != groupName).ToList(); 393 394 double[][] newData = FilterDataForPairwiseTest(colIndex); 395 396 var rowNames = new string[] { "p-Value of Mann-Whitney U", "Adjusted p-Value of Mann-Whitney U", 397 "p-Value of T-Test", "Adjusted p-Value of T-Test", "Cohen's d", "Hedges' g" }; 398 399 DoubleMatrix pValsMatrix = new DoubleMatrix(rowNames.Length, columnNames.Count()); 400 pValsMatrix.ColumnNames = columnNames; 401 pValsMatrix.RowNames = rowNames; 402 403 double mwuBothTails; 404 double tTestBothTails; 405 double[] mwuPValues = new double[newData.Length]; 406 double[] tTestPValues = new double[newData.Length]; 407 bool[] decision = null; 408 double[] adjustedMwuPValues = null; 409 double[] adjustedTtestPValues = null; 410 int cnt = 0; 411 412 for (int i = 0; i < newData.Length; i++) { 413 mwuBothTails = PairwiseTest.MannWhitneyUTest(data[colIndex], newData[i]); 414 tTestBothTails = PairwiseTest.TTest(data[colIndex], newData[i]); 415 mwuPValues[i] = mwuBothTails; 416 tTestPValues[i] = tTestBothTails; 417 418 if (mwuBothTails > significanceLevel) { 419 cnt++; 420 } 421 } 422 423 adjustedMwuPValues = BonferroniHolm.Calculate(significanceLevel, mwuPValues, out decision); 424 adjustedTtestPValues = BonferroniHolm.Calculate(significanceLevel, tTestPValues, out decision); 425 426 for (int i = 0; i < newData.Length; i++) { 427 pValsMatrix[0, i] = mwuPValues[i]; 428 pValsMatrix[1, i] = adjustedMwuPValues[i]; 429 pValsMatrix[2, i] = tTestPValues[i]; 430 pValsMatrix[3, i] = adjustedTtestPValues[i]; 431 pValsMatrix[4, i] = SampleSizeDetermination.CalculateCohensD(data[colIndex], newData[i]); 432 pValsMatrix[5, i] = SampleSizeDetermination.CalculateHedgesG(data[colIndex], newData[i]); 433 } 434 435 this.Invoke(new Action(() => { 436 pairwiseStringConvertibleMatrixView.Content = pValsMatrix; 437 pairwiseStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); 438 })); 439 440 ShowPairwiseResult(cnt); 418 441 } 419 442 … … 447 470 } 448 471 449 private void CalculatePairwiseTestDetails(string groupName) {450 int colIndex = 0;451 IEnumerable<string> columnNames = null;452 this.Invoke(new Action(() => { columnNames = stringConvertibleMatrixView.Content.ColumnNames; }));453 454 foreach (string col in columnNames) {455 if (col == groupName) {456 break;457 }458 colIndex++;459 }460 461 double[][] newData = FilterDataForPairwiseTest(colIndex);462 463 columnNames = columnNames.Where(x => x != groupName).ToList();464 465 var rowNames = new string[] { "p-Value of Mann-Whitney U", "Adjusted p-Value of Mann-Whitney U",466 "p-Value of T-Test", "Adjusted p-Value of T-Test", "Cohen's d", "Hedges' g" };467 468 DoubleMatrix pValsMatrix = new DoubleMatrix(rowNames.Length, columnNames.Count());469 pValsMatrix.ColumnNames = columnNames;470 pValsMatrix.RowNames = rowNames;471 472 double mwuBothtails;473 double tTestBothTails;474 double[] mwuPValues = new double[newData.Length];475 double[] tTestPValues = new double[newData.Length];476 bool[] decision = null;477 double[] adjustedMwuPValues = null;478 double[] adjustedTtestPValues = null;479 480 for (int i = 0; i < newData.Length; i++) {481 mwuBothtails = PairwiseTest.MannWhitneyUTest(data[colIndex], newData[i]);482 tTestBothTails = PairwiseTest.TTest(data[colIndex], newData[i]);483 mwuPValues[i] = mwuBothtails;484 tTestPValues[i] = tTestBothTails;485 }486 487 adjustedMwuPValues = BonferroniHolm.Calculate(significanceLevel, mwuPValues, out decision);488 adjustedTtestPValues = BonferroniHolm.Calculate(significanceLevel, tTestPValues, out decision);489 490 for (int i = 0; i < newData.Length; i++) {491 pValsMatrix[0, i] = mwuPValues[i];492 pValsMatrix[1, i] = adjustedMwuPValues[i];493 pValsMatrix[2, i] = tTestPValues[i];494 pValsMatrix[3, i] = adjustedTtestPValues[i];495 pValsMatrix[4, i] = SampleSizeDetermination.CalculateCohensD(data[colIndex], newData[i]);496 pValsMatrix[5, i] = SampleSizeDetermination.CalculateHedgesG(data[colIndex], newData[i]);497 }498 499 this.Invoke(new Action(() => {500 pairwiseStringConvertibleMatrixView.Content = pValsMatrix;501 pairwiseStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);502 }));503 }504 505 472 private void openBoxPlotToolStripMenuItem_Click(object sender, EventArgs e) { 506 473 RunCollectionBoxPlotView boxplotView = new RunCollectionBoxPlotView();
Note: See TracChangeset
for help on using the changeset viewer.