private void RemoveItem(TauUModel item) { if (item != null) { TauUHolder.Remove(item); } }
private void CheckBaseline() { List <double> phase1 = mWindow.ParseRange(baselineRangeString); TauUModel mTau = mTauMethods.BaselineTrend(phase1, phase1, false); mTau.Name = "Baseline: " + baselineRangeString; mTau.Range = baselineRangeString; mTau.IsChecked = false; mInterface.SendMessageToOutput("---------------------------------------------------"); mInterface.SendMessageToOutput("Scoring baseline range { " + baselineRangeString + " }"); mInterface.SendMessageToOutput("Baseline Tau score was " + mTau.TAU); }
private void CompareBaseline() { List <double> phase1 = mWindow.ParseRange(BaselineRangeString); List <double> phase2 = mWindow.ParseRange(InterventionRangeString); mInterface.SendMessageToOutput("---------------------------------------------------"); if (phase1.Count < 3 || phase2.Count < 3) { mInterface.SendMessageToOutput("Arrays appear short ( less than 3 items in 1 or more arrays )."); MessageBox.Show("Too few items were found. Please review the selected arrays."); return; } TauUModel mTau = mTauMethods.BaselineTrend(phase1, phase2, CorrectBaseline); mTau.Name = "Comparisons of {" + BaselineRangeString + "} and {" + InterventionRangeString + "} Corrected: " + CorrectBaseline; mTau.IsCorrected = CorrectBaseline; mTau.Range = BaselineRangeString; mTau.IsChecked = false; mInterface.SendMessageToOutput("Comparisons of {" + BaselineRangeString + "} and {" + InterventionRangeString + "} Corrected: " + CorrectBaseline); mInterface.SendMessageToOutput(string.Format("S: {0}, Pairs: {1}, Tau: {2}, TauB: {3}, P: {4}", mTau.S, mTau.Pairs, mTau.TAU, mTau.TAUB, mTau.PValue)); mInterface.SendMessageToOutput(string.Format("@ 85% CI ({0} - {1})", mTau.CI_85[0], mTau.CI_85[1])); mInterface.SendMessageToOutput(string.Format("@ 90% CI ({0} - {1})", mTau.CI_90[0], mTau.CI_90[1])); mInterface.SendMessageToOutput(string.Format("@ 95% CI ({0} - {1})", mTau.CI_95[0], mTau.CI_95[1])); TauUHolder.Add(mTau); CorrectBaseline = false; BaselineRangeString = ""; InterventionRangeString = ""; }
public TauUModel BaselineTrend(List <double> phase1, List <double> phase2, bool lessBaselineTrend) { List <double> blCopy = new List <double>(phase1); List <double> txCopy = new List <double>(phase2); var blNotTx = blCopy.Except(txCopy).ToList(); if (blNotTx.Count < 1) { /* BlNotTx is LINQ except list. If n = 0, both supplied are identical */ // Both Phases supplied have same elements! int pos = 0, neg = 0, ties = 0; var pairs = 0; var inc = 0; int trend_off = 1; for (var i = 0; i < blCopy.Count - trend_off; i++) { for (var j = trend_off + inc; j < txCopy.Count; j++) { System.Console.WriteLine(string.Format("bl counter {0}, bl length {1}, tx counter {2}, tx length {3}", i, blCopy.Count, j, txCopy.Count)); var diff = (txCopy[j] - blCopy[i]); if (diff == 0 || (txCopy[j].ToString() == blCopy[i].ToString())) { /* Hackish workaround for odd floating point comparisons */ ties++; } else if (diff > 0) { pos++; } else { neg++; } pairs++; } inc++; } var S = pos - neg; /* Variance as Defined by two-tailed Mann-Kendall test */ double Vars = blCopy.Count * (blCopy.Count - 1.0) * (2.0 * blCopy.Count + 5.0) / 18.0; return(new TauUModel { Reflective = true, S = S, Pairs = pairs, Ties = ties, TAU = (double)S / (double)pairs, TAUB = (S / (pairs * 1.0 - ties * 0.5)), VARs = Vars, SD = System.Math.Sqrt(Vars), SDtau = (System.Math.Sqrt(Vars) / pairs), Z = ((S / (double)pairs) / (System.Math.Sqrt(Vars) / (double)pairs)), PValue = GetPValueFromUDistribution(System.Math.Abs(((S / (double)pairs) / (System.Math.Sqrt(Vars) / (double)pairs))), true), CI_85 = new double[] { ((double)S / (double)pairs - 1.44 * (System.Math.Sqrt(Vars) / (double)pairs)), ((double)S / (double)pairs + 1.44 * (System.Math.Sqrt(Vars) / (double)pairs)) }, CI_90 = new double[] { ((double)S / (double)pairs - 1.645 * (System.Math.Sqrt(Vars) / (double)pairs)), ((double)S / (double)pairs + 1.645 * (System.Math.Sqrt(Vars) / (double)pairs)) }, CI_95 = new double[] { ((double)S / (double)pairs - 1.96 * (System.Math.Sqrt(Vars) / (double)pairs)), ((double)S / (double)pairs + 1.96 * (System.Math.Sqrt(Vars) / (double)pairs)) } }); } else { // Phases have differing elements var pos = 0; var neg = 0; var ties = 0; var pairs = 0; var istrend = false; var trend_off = 0; var inc = 0; var n = blCopy.Count; var m = txCopy.Count; for (var i = 0; i < n - trend_off; i++) { for (var j = trend_off + inc; j < m; j++) { var diff = (txCopy[j] - blCopy[i]); if (diff == 0 || (txCopy[j].ToString() == blCopy[i].ToString())) { ties++; } else if (diff > 0) { pos++; } else { neg++; } pairs++; } if (istrend) { inc++; } } var S = pos - neg; var Vars = 0.0; if (istrend) { /* Variance as Defined by two-tailed Mann-Kendall test */ Vars = n * (n - 1.0) * (2.0 * n + 5.0) / 18.0; } else { Vars = n * m * (n + m + 1) / 3.0; } if (lessBaselineTrend) { TauUModel mBl = BaselineTrend(phase1, phase1, false); S -= (int)mBl.S; } return(new TauUModel { Reflective = true, S = S, SD = System.Math.Sqrt(Vars), TAU = (double)S / (double)pairs, Pairs = pairs, Ties = ties, TAUB = (S / (pairs * 1.0 - ties * 0.5)), VARs = Vars, SDtau = (System.Math.Sqrt(Vars) / pairs), Z = ((S / (double)pairs) / (System.Math.Sqrt(Vars) / (double)pairs)), PValue = GetPValueFromUDistribution(System.Math.Abs(((S / (double)pairs) / (System.Math.Sqrt(Vars) / (double)pairs))), true), CI_85 = new double[] { ((double)S / (double)pairs - 1.44 * (System.Math.Sqrt(Vars) / (double)pairs)), ((double)S / (double)pairs + 1.44 * (System.Math.Sqrt(Vars) / (double)pairs)) }, CI_90 = new double[] { ((double)S / (double)pairs - 1.645 * (System.Math.Sqrt(Vars) / (double)pairs)), ((double)S / (double)pairs + 1.645 * (System.Math.Sqrt(Vars) / (double)pairs)) }, CI_95 = new double[] { ((double)S / (double)pairs - 1.96 * (System.Math.Sqrt(Vars) / (double)pairs)), ((double)S / (double)pairs + 1.96 * (System.Math.Sqrt(Vars) / (double)pairs)) } }); } }
private void CalculateOmnibus() { ObservableCollection <TauUModel> tempHolder = new ObservableCollection <TauUModel>(TauUHolder); if (tempHolder.Count < 2) { mInterface.SendMessageToOutput("At least two Tau-U objects must be selected to construct an omnibus"); MessageBox.Show("Please select at least two Tau-U objects in the list view (i.e., CTRL+click)"); return; } /* Based on Hedges' Optimal Weighting formula */ double globalTau = 0.0, globalSETau = 0.0; double inverseSd = 0.0, inverseSdSum = 0.0; foreach (TauUModel model in tempHolder) { inverseSd = 1.0 / model.SDtau; inverseSdSum += inverseSd; globalTau += model.TAU * inverseSd; globalSETau += model.SDtau * model.SDtau; } globalTau = globalTau / inverseSdSum; globalSETau = System.Math.Sqrt(globalSETau) / tempHolder.Count; var z = globalTau / globalSETau; var pval = mTauMethods.GetPValueFromUDistribution(z, true); double totalInverseVariance = 0.0, totalTauES = 0.0; double pairs = 0, ties = 0, S = 0; foreach (TauUModel model in tempHolder) { totalInverseVariance += (1.0 / (model.SDtau * model.SDtau)); totalTauES += (model.TAU * (1.0 / (model.SDtau * model.SDtau))); pairs += model.Pairs; ties += model.Ties; S += model.S; } TauUModel omniTau = new TauUModel { S = S, Pairs = pairs, TAU = totalTauES / totalInverseVariance, TAUB = (S / (pairs * 1.0 - ties * 0.5)), VARs = (1.0 / totalInverseVariance), SDtau = System.Math.Sqrt(1.0 / totalInverseVariance), Z = z, PValue = pval, CI_85 = new double[] { ((totalTauES / totalInverseVariance) - 1.44 * globalSETau), ((totalTauES / totalInverseVariance) + 1.44 * globalSETau) }, CI_90 = new double[] { ((totalTauES / totalInverseVariance) - 1.645 * globalSETau), ((totalTauES / totalInverseVariance) + 1.645 * globalSETau) }, CI_95 = new double[] { ((totalTauES / totalInverseVariance) - 1.96 * globalSETau), ((totalTauES / totalInverseVariance) + 1.96 * globalSETau) }, IsChecked = false, IsCorrected = false }; mInterface.SendMessageToOutput("---------------------------------------------------"); mInterface.SendMessageToOutput("Omnibus comparison created: "); mInterface.SendMessageToOutput(string.Format("Omnibus ES --- S: {0}, Pairs: {1}, Tau: {2}, TauB: {3}, P: {4}", omniTau.S, omniTau.Pairs, omniTau.TAU, omniTau.TAUB, omniTau.PValue)); mInterface.SendMessageToOutput(string.Format("@ 85% CI ({0} - {1})", omniTau.CI_85[0], omniTau.CI_85[1])); mInterface.SendMessageToOutput(string.Format("@ 90% CI ({0} - {1})", omniTau.CI_90[0], omniTau.CI_90[1])); mInterface.SendMessageToOutput(string.Format("@ 95% CI ({0} - {1})", omniTau.CI_95[0], omniTau.CI_95[1])); CorrectBaseline = false; BaselineRangeString = ""; InterventionRangeString = ""; }