public void Compute()
        {
            if (YesYesValue.HasValue && YesNoValue.HasValue && NoYesValue.HasValue && NoNoValue.HasValue)
            {
                StatisticsRepository.cTable cTable = new StatisticsRepository.cTable();
                StatisticsRepository.cTable.SingleTableResults singleTableResults = cTable.SigTable((double)yyVal.Value, (double)ynVal.Value, (double)nyVal.Value, (double)nnVal.Value, 0.95);
                cTable = null;

                string fisherExact = Epi.SharedStrings.UNDEFINED;
                string fisherExact2P = Epi.SharedStrings.UNDEFINED;
                string fisherLower = Epi.SharedStrings.UNDEFINED;
                string fisherUpper = Epi.SharedStrings.UNDEFINED;

                string oddsRatioEstimate = Epi.SharedStrings.UNDEFINED;
                string oddsRatioLower = Epi.SharedStrings.UNDEFINED;
                string oddsRatioUpper = Epi.SharedStrings.UNDEFINED;

                string oddsRatioMLEEstimate = Epi.SharedStrings.UNDEFINED;
                string oddsRatioMLEMidPLower = Epi.SharedStrings.UNDEFINED;
                string oddsRatioMLEMidPUpper = Epi.SharedStrings.UNDEFINED;

                string riskRatioEstimate = Epi.SharedStrings.UNDEFINED;
                string riskRatioLower = Epi.SharedStrings.UNDEFINED;
                string riskRatioUpper = Epi.SharedStrings.UNDEFINED;

                if (singleTableResults.FisherExactP != -1)
                {
                    fisherExact = ((double)singleTableResults.FisherExactP).ToString("F10");
                }

                if (singleTableResults.FisherExact2P != -1)
                {
                    fisherExact2P = ((double)singleTableResults.FisherExact2P).ToString("F10");
                }

                if (singleTableResults.OddsRatioMLEFisherLower != -1)
                {
                    fisherLower = ((double)singleTableResults.OddsRatioMLEFisherLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEFisherUpper != -1)
                {
                    fisherUpper = ((double)singleTableResults.OddsRatioMLEFisherUpper).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEEstimate != -1)
                {
                    oddsRatioMLEEstimate = ((double)singleTableResults.OddsRatioMLEEstimate).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEMidPLower != -1)
                {
                    oddsRatioMLEMidPLower = ((double)singleTableResults.OddsRatioMLEMidPLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEMidPUpper != -1)
                {
                    oddsRatioMLEMidPUpper = ((double)singleTableResults.OddsRatioMLEMidPUpper).ToString("F4");
                }

                if (singleTableResults.OddsRatioEstimate != null)
                {
                    oddsRatioEstimate = ((double)singleTableResults.OddsRatioEstimate).ToString("F4");
                }

                if (singleTableResults.OddsRatioLower != null)
                {
                    oddsRatioLower = ((double)singleTableResults.OddsRatioLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioUpper != null)
                {
                    oddsRatioUpper = ((double)singleTableResults.OddsRatioUpper).ToString("F4");
                }

                if (singleTableResults.RiskRatioEstimate != null)
                {
                    riskRatioEstimate = ((double)singleTableResults.RiskRatioEstimate).ToString("F4");
                }

                if (singleTableResults.RiskRatioLower != null)
                {
                    riskRatioLower = ((double)singleTableResults.RiskRatioLower).ToString("F4");
                }

                if (singleTableResults.RiskRatioUpper != null)
                {
                    riskRatioUpper = ((double)singleTableResults.RiskRatioUpper).ToString("F4");
                }

                txtChiSqCorP.Text = singleTableResults.ChiSquareYates2P.ToString("F10");
                txtChiSqCorVal.Text = singleTableResults.ChiSquareYatesVal.ToString("F4");
                txtChiSqManP.Text = singleTableResults.ChiSquareMantel2P.ToString("F10");
                txtChiSqManVal.Text = singleTableResults.ChiSquareMantelVal.ToString("F4");
                txtChiSqUncP.Text = singleTableResults.ChiSquareUncorrected2P.ToString("F10");
                txtChiSqUncVal.Text = singleTableResults.ChiSquareUncorrectedVal.ToString("F4");
                txtOddsRatioEstimate.Text = oddsRatioEstimate;
                txtOddsRatioLower.Text = oddsRatioLower;
                txtOddsRatioUpper.Text = oddsRatioUpper;
                txtMidPEstimate.Text = oddsRatioMLEEstimate;
                txtMidPLower.Text = oddsRatioMLEMidPLower;
                txtMidPUpper.Text = oddsRatioMLEMidPUpper;
                txtRiskDifferenceEstimate.Text = singleTableResults.RiskDifferenceEstimate.ToString("F4");
                txtRiskDifferenceLower.Text = singleTableResults.RiskDifferenceLower.ToString("F4");
                txtRiskDifferenceUpper.Text = singleTableResults.RiskDifferenceUpper.ToString("F4");
                txtRiskRatioEstimate.Text = riskRatioEstimate;
                txtRiskRatioLower.Text = riskRatioLower;
                txtRiskRatioUpper.Text = riskRatioUpper;
                txtFisherLower.Text = fisherLower;
                txtFisherUpper.Text = fisherUpper;
                txtFisherExact.Text = fisherExact;
                txtFisherExact2P.Text = fisherExact2P;
                txtMidPExact.Text = singleTableResults.MidP.ToString("F10");
                if (singleTableResults.LowestExpectedCellCount < 5)
                {
                    txtDisclaimer.Visibility = Visibility.Visible;
                    txtDisclaimer.FontWeight = FontWeights.DemiBold;
                    txtDisclaimer.Text = "An expected cell count is < 5. X" + '\u00B2' + " may not be valid.";
                }
                else
                {
                    txtDisclaimer.Visibility = Visibility.Collapsed;
                    txtDisclaimer.Text = "";
                }
                if (singleTableResults.LowNPQ < 5)
                {
                    txtDisclaimerOR.Visibility = Visibility.Visible;
                    txtDisclaimerOR.FontWeight = FontWeights.DemiBold;
                    txtDisclaimerOR.Text = "Sparse data. Use exact confidence limits.";
                }
                else
                {
                    txtDisclaimerOR.Visibility = Visibility.Collapsed;
                    txtDisclaimerOR.Text = "";
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Helper methods that calculates the results.
        /// </summary>
        void CalculateSummary()
        {
            try
            {
                List <double> yyList = new List <double>();
                List <double> ynList = new List <double>();
                List <double> nyList = new List <double>();
                List <double> nnList = new List <double>();
                for (int x = 1; x <= 9; x++)
                {
                    if (!strataActive[x].Contains(false))
                    {
                        yyList.Add(strataVals[x][0]);
                        ynList.Add(strataVals[x][1]);
                        nyList.Add(strataVals[x][2]);
                        nnList.Add(strataVals[x][3]);
                    }
                }
                double[] yyArr = yyList.ToArray();
                double[] ynArr = ynList.ToArray();
                double[] nyArr = nyList.ToArray();
                double[] nnArr = nnList.ToArray();

                double yySum = yyList.Sum();
                double ynSum = ynList.Sum();
                double nySum = nyList.Sum();
                double nnSum = nnList.Sum();

                if (yyList.Count > 1)
                {
                    StatisticsRepository.Strat2x2 strat2x2 = new StatisticsRepository.Strat2x2();
                    StatisticsRepository.cTable.SingleTableResults singleTableResults = new StatisticsRepository.cTable().SigTable(yySum, ynSum, nySum, nnSum, 0.95);

                    double computedOddsRatio     = (double)strat2x2.ComputeOddsRatio(yyArr, ynArr, nyArr, nnArr);
                    double computedOddsRatioMHLL = computedOddsRatio * Math.Exp(-(double)strat2x2.ZSElnOR(yyArr, ynArr, nyArr, nnArr));
                    double computedOddsRatioMHUL = computedOddsRatio * Math.Exp((double)strat2x2.ZSElnOR(yyArr, ynArr, nyArr, nnArr));
                    double computedRR            = (double)strat2x2.ComputedRR(yyArr, ynArr, nyArr, nnArr);
                    double computedRRMHLL        = computedRR * Math.Exp(-(double)strat2x2.ZSElnRR(yyArr, ynArr, nyArr, nnArr));
                    double computedRRMHUL        = computedRR * Math.Exp((double)strat2x2.ZSElnRR(yyArr, ynArr, nyArr, nnArr));
                    //                double mleOR = (double)strat2x2.ucestimaten(yyArr, ynArr, nyArr, nnArr);
                    //                double ExactORLL = (double)strat2x2.exactorln(yyArr, ynArr, nyArr, nnArr);
                    //                double ExactORUL = (double)strat2x2.exactorun(yyArr, ynArr, nyArr, nnArr);
                    double mleOR     = double.NaN;
                    double ExactORLL = double.NaN;
                    double ExactORUL = double.NaN;
                    if (ynSum == 0.0 || nySum == 0.0)
                    {
                        mleOR     = double.PositiveInfinity;
                        ExactORLL = (double)strat2x2.exactorln(yyArr, ynArr, nyArr, nnArr);
                        ExactORUL = double.PositiveInfinity;
                    }
                    else if (yySum == 0.0 || nnSum == 0.0)
                    {
                        mleOR     = 0.0;
                        ExactORLL = 0.0;
                        ExactORUL = (double)strat2x2.exactorun(yyArr, ynArr, nyArr, nnArr);
                    }
                    else
                    {
                        mleOR     = (double)strat2x2.ucestimaten(yyArr, ynArr, nyArr, nnArr);
                        ExactORLL = (double)strat2x2.exactorln(yyArr, ynArr, nyArr, nnArr);
                        ExactORUL = (double)strat2x2.exactorun(yyArr, ynArr, nyArr, nnArr);
                    }
                    double   uncorrectedChiSquare  = strat2x2.ComputeUnChisq(yyArr, ynArr, nyArr, nnArr);
                    double   corrChisq             = strat2x2.ComputeCorrChisq(yyArr, ynArr, nyArr, nnArr);
                    double   uncorrectedChiSquareP = (double)strat2x2.pForChisq(uncorrectedChiSquare);
                    double   corrChisqP            = (double)strat2x2.pForChisq(corrChisq);
                    string[] results = new string[24];

                    //results[0] = mleOR.ToString("F4");
                    //results[1] = ExactORLL.ToString("F4");
                    //results[2] = ExactORUL.ToString("F4");

                    //results[3] = computedRR.ToString("F4");
                    //results[4] = computedRRMHLL.ToString("F4");
                    //results[5] = computedRRMHUL.ToString("F4");
                    resultsList.Add(new MyString(mleOR.ToString("F4")));
                    resultsList.Add(new MyString(ExactORLL.ToString("F4")));
                    resultsList.Add(new MyString(ExactORUL.ToString("F4")));
                    resultsList.Add(new MyString(computedRR.ToString("F4")));
                    resultsList.Add(new MyString(computedRRMHLL.ToString("F4")));
                    resultsList.Add(new MyString(computedRRMHUL.ToString("F4")));

                    try
                    {
                        resultsList.Add(new MyString(singleTableResults.OddsRatioEstimate.Value.ToString("F4")));
                    }
                    catch (Exception ex)
                    {
                        //
                    }
                    try
                    {
                        resultsList.Add(new MyString(singleTableResults.OddsRatioLower.Value.ToString("F4")));
                    }
                    catch (Exception ex)
                    {
                        //
                    }
                    try
                    {
                        resultsList.Add(new MyString(singleTableResults.OddsRatioUpper.Value.ToString("F4")));
                    }
                    catch (Exception ex)
                    {
                        //
                    }

                    resultsList.Add(new MyString(singleTableResults.OddsRatioMLEEstimate.ToString("F4")));
                    resultsList.Add(new MyString(singleTableResults.OddsRatioMLEMidPLower.ToString("F4")));
                    resultsList.Add(new MyString(singleTableResults.OddsRatioMLEMidPUpper.ToString("F4")));

                    resultsList.Add(new MyString(singleTableResults.OddsRatioMLEFisherLower.ToString("F4")));
                    resultsList.Add(new MyString(singleTableResults.OddsRatioMLEFisherUpper.ToString("F4")));
                    resultsList.Add(new MyString(singleTableResults.RiskRatioEstimate.ToString("F4")));
                    resultsList.Add(new MyString(singleTableResults.RiskRatioLower.Value.ToString("F4")));
                    resultsList.Add(new MyString(singleTableResults.RiskRatioUpper.Value.ToString("F4")));
                    resultsList.Add(new MyString(computedOddsRatio.ToString("F4")));
                    resultsList.Add(new MyString(computedOddsRatioMHLL.ToString("F4")));
                    resultsList.Add(new MyString(computedOddsRatioMHUL.ToString("F4")));
                    resultsList.Add(new MyString(uncorrectedChiSquare.ToString("F4")));
                    resultsList.Add(new MyString(uncorrectedChiSquareP.ToString("F10")));
                    resultsList.Add(new MyString(corrChisq.ToString("F4")));
                    resultsList.Add(new MyString(corrChisqP.ToString("F10")));

                    //e.Result = results;
                }
            }
            catch (Exception ex)
            {
                //
            }
        }
예제 #3
0
        public void Compute()
        {
            if (YesYesValue.HasValue && YesNoValue.HasValue && NoYesValue.HasValue && NoNoValue.HasValue)
            {
                StatisticsRepository.cTable cTable = new StatisticsRepository.cTable();
                StatisticsRepository.cTable.SingleTableResults singleTableResults = cTable.SigTable((double)yyVal.Value, (double)ynVal.Value, (double)nyVal.Value, (double)nnVal.Value, 0.95);
                cTable = null;

                string fisherExact   = Epi.SharedStrings.UNDEFINED;
                string fisherExact2P = Epi.SharedStrings.UNDEFINED;
                string fisherLower   = Epi.SharedStrings.UNDEFINED;
                string fisherUpper   = Epi.SharedStrings.UNDEFINED;

                string oddsRatioEstimate = Epi.SharedStrings.UNDEFINED;
                string oddsRatioLower    = Epi.SharedStrings.UNDEFINED;
                string oddsRatioUpper    = Epi.SharedStrings.UNDEFINED;

                string oddsRatioMLEEstimate  = Epi.SharedStrings.UNDEFINED;
                string oddsRatioMLEMidPLower = Epi.SharedStrings.UNDEFINED;
                string oddsRatioMLEMidPUpper = Epi.SharedStrings.UNDEFINED;

                string riskRatioEstimate = Epi.SharedStrings.UNDEFINED;
                string riskRatioLower    = Epi.SharedStrings.UNDEFINED;
                string riskRatioUpper    = Epi.SharedStrings.UNDEFINED;

                if (singleTableResults.FisherExactP != -1)
                {
                    fisherExact = ((double)singleTableResults.FisherExactP).ToString("F10");
                }

                if (singleTableResults.FisherExact2P != -1)
                {
                    fisherExact2P = ((double)singleTableResults.FisherExact2P).ToString("F10");
                }

                if (singleTableResults.OddsRatioMLEFisherLower != -1)
                {
                    fisherLower = ((double)singleTableResults.OddsRatioMLEFisherLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEFisherUpper != -1)
                {
                    fisherUpper = ((double)singleTableResults.OddsRatioMLEFisherUpper).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEEstimate != -1)
                {
                    oddsRatioMLEEstimate = ((double)singleTableResults.OddsRatioMLEEstimate).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEMidPLower != -1)
                {
                    oddsRatioMLEMidPLower = ((double)singleTableResults.OddsRatioMLEMidPLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEMidPUpper != -1)
                {
                    oddsRatioMLEMidPUpper = ((double)singleTableResults.OddsRatioMLEMidPUpper).ToString("F4");
                }

                if (singleTableResults.OddsRatioEstimate != null)
                {
                    oddsRatioEstimate = ((double)singleTableResults.OddsRatioEstimate).ToString("F4");
                }

                if (singleTableResults.OddsRatioLower != null)
                {
                    oddsRatioLower = ((double)singleTableResults.OddsRatioLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioUpper != null)
                {
                    oddsRatioUpper = ((double)singleTableResults.OddsRatioUpper).ToString("F4");
                }

                if (singleTableResults.RiskRatioEstimate != null)
                {
                    riskRatioEstimate = ((double)singleTableResults.RiskRatioEstimate).ToString("F4");
                }

                if (singleTableResults.RiskRatioLower != null)
                {
                    riskRatioLower = ((double)singleTableResults.RiskRatioLower).ToString("F4");
                }

                if (singleTableResults.RiskRatioUpper != null)
                {
                    riskRatioUpper = ((double)singleTableResults.RiskRatioUpper).ToString("F4");
                }

                txtChiSqCorP.Text              = singleTableResults.ChiSquareYates2P.ToString("F10");
                txtChiSqCorVal.Text            = singleTableResults.ChiSquareYatesVal.ToString("F4");
                txtChiSqManP.Text              = singleTableResults.ChiSquareMantel2P.ToString("F10");
                txtChiSqManVal.Text            = singleTableResults.ChiSquareMantelVal.ToString("F4");
                txtChiSqUncP.Text              = singleTableResults.ChiSquareUncorrected2P.ToString("F10");
                txtChiSqUncVal.Text            = singleTableResults.ChiSquareUncorrectedVal.ToString("F4");
                txtOddsRatioEstimate.Text      = oddsRatioEstimate;
                txtOddsRatioLower.Text         = oddsRatioLower;
                txtOddsRatioUpper.Text         = oddsRatioUpper;
                txtMidPEstimate.Text           = oddsRatioMLEEstimate;
                txtMidPLower.Text              = oddsRatioMLEMidPLower;
                txtMidPUpper.Text              = oddsRatioMLEMidPUpper;
                txtRiskDifferenceEstimate.Text = singleTableResults.RiskDifferenceEstimate.ToString("F4");
                txtRiskDifferenceLower.Text    = singleTableResults.RiskDifferenceLower.ToString("F4");
                txtRiskDifferenceUpper.Text    = singleTableResults.RiskDifferenceUpper.ToString("F4");
                txtRiskRatioEstimate.Text      = riskRatioEstimate;
                txtRiskRatioLower.Text         = riskRatioLower;
                txtRiskRatioUpper.Text         = riskRatioUpper;
                txtFisherLower.Text            = fisherLower;
                txtFisherUpper.Text            = fisherUpper;
                txtFisherExact.Text            = fisherExact;
                txtFisherExact2P.Text          = fisherExact2P;
                txtMidPExact.Text              = singleTableResults.MidP.ToString("F10");
                if (singleTableResults.LowestExpectedCellCount < 5)
                {
                    txtDisclaimer.Visibility = Visibility.Visible;
                    txtDisclaimer.FontWeight = FontWeights.DemiBold;
                    txtDisclaimer.Text       = "An expected cell count is < 5. X" + '\u00B2' + " may not be valid.";
                }
                else
                {
                    txtDisclaimer.Visibility = Visibility.Collapsed;
                    txtDisclaimer.Text       = "";
                }
                if (singleTableResults.LowNPQ < 5)
                {
                    txtDisclaimerOR.Visibility = Visibility.Visible;
                    txtDisclaimerOR.FontWeight = FontWeights.DemiBold;
                    txtDisclaimerOR.Text       = "Sparse data. Use exact confidence limits.";
                }
                else
                {
                    txtDisclaimerOR.Visibility = Visibility.Collapsed;
                    txtDisclaimerOR.Text       = "";
                }
            }
        }
        public void Compute()
        {
            if (YesYesValue.HasValue && YesNoValue.HasValue && NoYesValue.HasValue && NoNoValue.HasValue)
            {
                StatisticsRepository.cTable cTable = new StatisticsRepository.cTable();
                StatisticsRepository.cTable.SingleTableResults singleTableResults = cTable.SigTable((double)yyVal.Value, (double)ynVal.Value, (double)nyVal.Value, (double)nnVal.Value, 0.95);
                cTable = null;

                string fisherExact   = Epi.SharedStrings.UNDEFINED;
                string fisherExact2P = Epi.SharedStrings.UNDEFINED;
                string fisherLower   = Epi.SharedStrings.UNDEFINED;
                string fisherUpper   = Epi.SharedStrings.UNDEFINED;

                string oddsRatioEstimate = Epi.SharedStrings.UNDEFINED;
                string oddsRatioLower    = Epi.SharedStrings.UNDEFINED;
                string oddsRatioUpper    = Epi.SharedStrings.UNDEFINED;

                string oddsRatioMLEEstimate  = Epi.SharedStrings.UNDEFINED;
                string oddsRatioMLEMidPLower = Epi.SharedStrings.UNDEFINED;
                string oddsRatioMLEMidPUpper = Epi.SharedStrings.UNDEFINED;

                string riskRatioEstimate = Epi.SharedStrings.UNDEFINED;
                string riskRatioLower    = Epi.SharedStrings.UNDEFINED;
                string riskRatioUpper    = Epi.SharedStrings.UNDEFINED;

                if (singleTableResults.FisherExactP != -1)
                {
                    fisherExact = ((double)singleTableResults.FisherExactP).ToString("F10");
                }

                if (singleTableResults.FisherExact2P != -1)
                {
                    fisherExact2P = ((double)singleTableResults.FisherExact2P).ToString("F10");
                }

                if (singleTableResults.OddsRatioMLEFisherLower != -1)
                {
                    fisherLower = ((double)singleTableResults.OddsRatioMLEFisherLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEFisherUpper != -1)
                {
                    fisherUpper = ((double)singleTableResults.OddsRatioMLEFisherUpper).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEEstimate != -1)
                {
                    oddsRatioMLEEstimate = ((double)singleTableResults.OddsRatioMLEEstimate).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEMidPLower != -1)
                {
                    oddsRatioMLEMidPLower = ((double)singleTableResults.OddsRatioMLEMidPLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEMidPUpper != -1)
                {
                    oddsRatioMLEMidPUpper = ((double)singleTableResults.OddsRatioMLEMidPUpper).ToString("F4");
                }

                if (singleTableResults.OddsRatioEstimate != null)
                {
                    oddsRatioEstimate = ((double)singleTableResults.OddsRatioEstimate).ToString("F4");
                }

                if (singleTableResults.OddsRatioLower != null)
                {
                    oddsRatioLower = ((double)singleTableResults.OddsRatioLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioUpper != null)
                {
                    oddsRatioUpper = ((double)singleTableResults.OddsRatioUpper).ToString("F4");
                }

                if (singleTableResults.RiskRatioEstimate != null)
                {
                    riskRatioEstimate = ((double)singleTableResults.RiskRatioEstimate).ToString("F4");
                }

                if (singleTableResults.RiskRatioLower != null)
                {
                    riskRatioLower = ((double)singleTableResults.RiskRatioLower).ToString("F4");
                }

                if (singleTableResults.RiskRatioUpper != null)
                {
                    riskRatioUpper = ((double)singleTableResults.RiskRatioUpper).ToString("F4");
                }

                txtChiSqCorP.Text              = singleTableResults.ChiSquareYates2P.ToString("F10");
                txtChiSqCorVal.Text            = singleTableResults.ChiSquareYatesVal.ToString("F4");
                txtChiSqManP.Text              = singleTableResults.ChiSquareMantel2P.ToString("F10");
                txtChiSqManVal.Text            = singleTableResults.ChiSquareMantelVal.ToString("F4");
                txtChiSqUncP.Text              = singleTableResults.ChiSquareUncorrected2P.ToString("F10");
                txtChiSqUncVal.Text            = singleTableResults.ChiSquareUncorrectedVal.ToString("F4");
                txtOddsRatioEstimate.Text      = oddsRatioEstimate;
                txtOddsRatioLower.Text         = oddsRatioLower;
                txtOddsRatioUpper.Text         = oddsRatioUpper;
                txtMidPEstimate.Text           = oddsRatioMLEEstimate;
                txtMidPLower.Text              = oddsRatioMLEMidPLower;
                txtMidPUpper.Text              = oddsRatioMLEMidPUpper;
                txtRiskDifferenceEstimate.Text = singleTableResults.RiskDifferenceEstimate.ToString("F4");
                txtRiskDifferenceLower.Text    = singleTableResults.RiskDifferenceLower.ToString("F4");
                txtRiskDifferenceUpper.Text    = singleTableResults.RiskDifferenceUpper.ToString("F4");
                txtRiskRatioEstimate.Text      = riskRatioEstimate;// singleTableResults.RiskRatioEstimate.ToString("F4");
                txtRiskRatioLower.Text         = riskRatioLower;
                txtRiskRatioUpper.Text         = riskRatioUpper;
                txtFisherLower.Text            = fisherLower;
                txtFisherUpper.Text            = fisherUpper;
                txtFisherExact.Text            = fisherExact;
                txtFisherExact2P.Text          = fisherExact2P;
                txtMidPExact.Text              = singleTableResults.MidP.ToString("F10");
            }
        }
예제 #5
0
        /// <summary>
        /// This GetFactory Generates the results and sends it back to client in STATCalcDTO format.
        /// </summary>
        /// <param name="ytVal"></param>
        /// <param name="ntVal"></param>
        /// <param name="tyVal"></param>
        /// <param name="tnVal"></param>
        /// <param name="yyVal"></param>
        /// <param name="ynVal"></param>
        /// <param name="nyVal"></param>
        /// <param name="nnVal"></param>
        /// <param name="strataActive"></param>
        /// <param name="strataVals"></param>
        /// <returns></returns>
        public StatCalcDTO GenerateSigTable(int ytVal, int ntVal, int tyVal, int tnVal, int yyVal, int ynVal, int nyVal, int nnVal, List <DictionaryDTO> strataActive,
                                            List <DictionaryDTO> strataVals)
        {
            InitializeStatCalc();
            ConvertToDictionaryWithBoolKey(strataActive);
            ConvertToDictionaryWithDoubleKey(strataVals);


            if ((ytVal > 0) && (ntVal > 0) && (tyVal > 0) && (tnVal > 0))
            {
                StatisticsRepository.cTable.SingleTableResults singleTableResults = new StatisticsRepository.cTable().SigTable((double)yyVal, (double)ynVal, (double)nyVal, (double)nnVal, 0.95);
                currentSingleTableResults.ChiSquareMantel2P       = singleTableResults.ChiSquareMantel2P;
                currentSingleTableResults.ChiSquareMantelVal      = singleTableResults.ChiSquareMantelVal;
                currentSingleTableResults.ChiSquareUncorrected2P  = singleTableResults.ChiSquareUncorrected2P;
                currentSingleTableResults.ChiSquareUncorrectedVal = singleTableResults.ChiSquareUncorrectedVal;
                currentSingleTableResults.ChiSquareYates2P        = singleTableResults.ChiSquareYates2P;
                currentSingleTableResults.ChiSquareYatesVal       = singleTableResults.ChiSquareYatesVal;
                currentSingleTableResults.ErrorMessage            = singleTableResults.ErrorMessage;
                currentSingleTableResults.FisherExact2P           = singleTableResults.FisherExact2P;
                currentSingleTableResults.FisherExactP            = singleTableResults.FisherExactP;
                currentSingleTableResults.MidP = singleTableResults.MidP;
                currentSingleTableResults.OddsRatioEstimate       = singleTableResults.OddsRatioEstimate;
                currentSingleTableResults.OddsRatioLower          = singleTableResults.OddsRatioLower;
                currentSingleTableResults.OddsRatioMLEEstimate    = singleTableResults.OddsRatioMLEEstimate;
                currentSingleTableResults.OddsRatioMLEFisherLower = singleTableResults.OddsRatioMLEFisherLower;
                currentSingleTableResults.OddsRatioMLEFisherUpper = singleTableResults.OddsRatioMLEFisherUpper;
                currentSingleTableResults.OddsRatioMLEMidPLower   = singleTableResults.OddsRatioMLEMidPLower;
                currentSingleTableResults.OddsRatioMLEMidPUpper   = singleTableResults.OddsRatioMLEMidPUpper;
                currentSingleTableResults.OddsRatioUpper          = singleTableResults.OddsRatioUpper;
                currentSingleTableResults.RiskDifferenceEstimate  = singleTableResults.RiskDifferenceEstimate;
                currentSingleTableResults.RiskDifferenceLower     = singleTableResults.RiskDifferenceLower;
                currentSingleTableResults.RiskDifferenceUpper     = singleTableResults.RiskDifferenceUpper;
                currentSingleTableResults.RiskRatioEstimate       = singleTableResults.RiskRatioEstimate;
                currentSingleTableResults.RiskRatioLower          = singleTableResults.RiskRatioLower;
                currentSingleTableResults.RiskRatioUpper          = singleTableResults.RiskRatioUpper;


                string oddsRatioEstimate = Epi.SharedStrings.UNDEFINED;
                string oddsRatioLower    = Epi.SharedStrings.UNDEFINED;
                string oddsRatioUpper    = Epi.SharedStrings.UNDEFINED;
                string riskRatioLower    = Epi.SharedStrings.UNDEFINED;
                string riskRatioUpper    = Epi.SharedStrings.UNDEFINED;
                string fisherExact2P     = Epi.SharedStrings.UNDEFINED;

                if (singleTableResults.FisherExact2P != -1)
                {
                    fisherExact2P = ((double)singleTableResults.FisherExact2P).ToString("F10");
                }

                if (singleTableResults.OddsRatioEstimate != null)
                {
                    oddsRatioEstimate = ((double)singleTableResults.OddsRatioEstimate).ToString("F4");
                }

                if (singleTableResults.OddsRatioLower != null)
                {
                    oddsRatioLower = ((double)singleTableResults.OddsRatioLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioUpper != null)
                {
                    oddsRatioUpper = ((double)singleTableResults.OddsRatioUpper).ToString("F4");
                }

                if (singleTableResults.RiskRatioLower != null)
                {
                    riskRatioLower = ((double)singleTableResults.RiskRatioLower).ToString("F4");
                }

                if (singleTableResults.RiskRatioUpper != null)
                {
                    riskRatioUpper = ((double)singleTableResults.RiskRatioUpper).ToString("F4");
                }

                statCalcRecord.ChiSqCorP              = singleTableResults.ChiSquareYates2P.ToString("F10");
                statCalcRecord.ChiSqCorVal            = singleTableResults.ChiSquareYatesVal.ToString("F4");
                statCalcRecord.ChiSqManP              = singleTableResults.ChiSquareMantel2P.ToString("F10");
                statCalcRecord.ChiSqManVal            = singleTableResults.ChiSquareMantelVal.ToString("F4");
                statCalcRecord.ChiSqUncP              = singleTableResults.ChiSquareUncorrected2P.ToString("F10");
                statCalcRecord.ChiSqUncVal            = singleTableResults.ChiSquareUncorrectedVal.ToString("F4");
                statCalcRecord.OddsRatioEstimate      = oddsRatioEstimate; // singleTableResults.OddsRatioEstimate.ToString("F4");
                statCalcRecord.OddsRatioLower         = oddsRatioLower;    //singleTableResults.OddsRatioLower.ToString("F4");
                statCalcRecord.OddsRatioUpper         = oddsRatioUpper;    // singleTableResults.OddsRatioUpper.ToString("F4");
                statCalcRecord.MidPEstimate           = singleTableResults.OddsRatioMLEEstimate.ToString("F4");
                statCalcRecord.MidPLower              = singleTableResults.OddsRatioMLEMidPLower.ToString("F4");
                statCalcRecord.MidPUpper              = singleTableResults.OddsRatioMLEMidPUpper.ToString("F4");
                statCalcRecord.FisherLower            = singleTableResults.OddsRatioMLEFisherLower.ToString("F4");
                statCalcRecord.FisherUpper            = singleTableResults.OddsRatioMLEFisherUpper.ToString("F4");
                statCalcRecord.RiskDifferenceEstimate = singleTableResults.RiskDifferenceEstimate.ToString("F4");
                statCalcRecord.RiskDifferenceLower    = singleTableResults.RiskDifferenceLower.ToString("F4");
                statCalcRecord.RiskDifferenceUpper    = singleTableResults.RiskDifferenceUpper.ToString("F4");
                statCalcRecord.RiskRatioEstimate      = singleTableResults.RiskRatioEstimate.ToString("F4");
                statCalcRecord.RiskRatioLower         = riskRatioLower; //singleTableResults.RiskRatioLower.ToString("F4");
                statCalcRecord.RiskRatioUpper         = riskRatioUpper; //singleTableResults.RiskRatioUpper.ToString("F4");
                statCalcRecord.FisherExact            = singleTableResults.FisherExactP.ToString("F10");
                statCalcRecord.MidPExact              = singleTableResults.MidP.ToString("F10");
                statCalcRecord.FisherExact2P          = fisherExact2P;
            }
            CalculateSummary();
            statCalcDtoObject.SingleResults = currentSingleTableResults;
            statCalcDtoObject.Results       = resultsList;
            statCalcDtoObject.TextBoxesData = statCalcRecord;
            return(statCalcDtoObject);
        }
예제 #6
0
        //void Swap2x2RowValues(DataTable table)
        //{
        //    if (table.Rows.Count > 2 || table.Columns.Count > 3)
        //    {
        //        return; // cannot do an invalid 2x2 table
        //    }

        //    object row1Col1 = table.Rows[0][1];
        //    object row1Col2 = table.Rows[0][2];

        //    object row2Col1 = table.Rows[1][1];
        //    object row2Col2 = table.Rows[1][2];

        //    table.Rows[0][1] = row2Col1;
        //    table.Rows[0][2] = row2Col2;

        //    table.Rows[1][1] = row1Col1;
        //    table.Rows[1][2] = row1Col2;

        //    object firstRowName = table.Rows[0][0];
        //    table.Rows[0][0] = table.Rows[1][0];
        //    table.Rows[1][0] = firstRowName;
        //}

        //void Swap2x2ColValues(DataTable table)
        //{
        //    if (table.Rows.Count > 2 || table.Columns.Count > 3)
        //    {
        //        return; // cannot do an invalid 2x2 table
        //    }

        //    object row1Col1 = table.Rows[0][1];
        //    object row1Col2 = table.Rows[0][2];

        //    object row2Col1 = table.Rows[1][1];
        //    object row2Col2 = table.Rows[1][2];

        //    table.Rows[0][1] = row1Col2;
        //    table.Rows[0][2] = row1Col1;

        //    table.Rows[1][1] = row2Col2;
        //    table.Rows[1][2] = row2Col1;

        //    string firstColumnName = table.Columns[1].ColumnName;
        //    string secondColumnName = table.Columns[2].ColumnName;

        //    table.Columns[1].ColumnName = "_COL1_";
        //    table.Columns[2].ColumnName = "_COL2_";

        //    table.Columns[1].ColumnName = secondColumnName;
        //    table.Columns[2].ColumnName = firstColumnName;
        //}

        private TwoxTwoAndMxNResultsSet Setup2x2(GadgetParameters gadgetOptions, TwoxTwoAndMxNResultsSet resultSet)
        {
            GridCells gridCells = new GridCells();

            TwoxTwoTableDTO table = resultSet.TwoxTwoTableDTO;

            DataTable dt = resultSet.FreqResultsDataTable;

            if (table != null)  //      && table.Rows.Length != 0)
            {
                //if (gadgetOptions.InputVariableList.ContainsKey("smarttable") && gadgetOptions.InputVariableList["smarttable"].Equals("true"))
                //{
                //    CheckLabels(table);
                //}


                gridCells.yyVal = Convert.ToInt32(dt.Rows[0][1].ToString()); //table.Yy;
                gridCells.ynVal = Convert.ToInt32(dt.Rows[0][2].ToString()); //table.Yn;
                gridCells.nyVal = Convert.ToInt32(dt.Rows[1][1].ToString()); //table.Ny;
                gridCells.nnVal = Convert.ToInt32(dt.Rows[1][2].ToString()); //table.Nn;

                gridCells.ntVal = gridCells.nnVal + gridCells.nyVal;
                gridCells.ytVal = gridCells.yyVal + gridCells.ynVal;

                gridCells.ttVal = gridCells.ytVal + gridCells.ntVal;
                gridCells.tyVal = gridCells.yyVal + gridCells.nyVal;
                gridCells.tnVal = gridCells.ynVal + gridCells.nnVal;
                if (gridCells.ytVal != 0)
                {
                    gridCells.yyRowPct = 1.0 * gridCells.yyVal / gridCells.ytVal;
                    gridCells.ynRowPct = 1.0 * gridCells.ynVal / gridCells.ytVal;
                }
                if (gridCells.ntVal != 0)
                {
                    gridCells.nyRowPct = 1.0 * gridCells.nyVal / gridCells.ntVal;
                    gridCells.nnRowPct = 1.0 * gridCells.nnVal / gridCells.ntVal;
                }
                if (gridCells.tyVal != 0)
                {
                    gridCells.yyColPct = 1.0 * gridCells.yyVal / gridCells.tyVal;
                    gridCells.nyColPct = 1.0 * gridCells.nyVal / gridCells.tyVal;
                }
                if (gridCells.tnVal != 0)
                {
                    gridCells.ynColPct = 1.0 * gridCells.ynVal / gridCells.tnVal;
                    gridCells.nnColPct = 1.0 * gridCells.nnVal / gridCells.tnVal;
                }
                if (gridCells.ttVal != 0)
                {
                    gridCells.tyRowPct = 1.0 * gridCells.tyVal / gridCells.ttVal;
                    gridCells.tnRowPct = 1.0 * gridCells.tnVal / gridCells.ttVal;
                    gridCells.ytColPct = 1.0 * gridCells.ytVal / gridCells.ttVal;
                    gridCells.ntColPct = 1.0 * gridCells.ntVal / gridCells.ttVal;
                }
                if (gridCells.tyVal > 0 && gridCells.tnVal > 0 && gridCells.ytVal > 0 && gridCells.ntVal > 0)
                {
                    //gridCells.singleTableResults = new StatisticsRepository.cTable().SigTable(
                    //    (double)gridCells.yyVal, (double)gridCells.ynVal,
                    //    (double)gridCells.nyVal, (double)gridCells.nnVal, 0.95);
                    StatisticsRepository.cTable.SingleTableResults stab = new StatisticsRepository.cTable().SigTable(
                        (double)gridCells.yyVal, (double)gridCells.ynVal,
                        (double)gridCells.nyVal, (double)gridCells.nnVal, 0.95);

                    //gridCells.singleTableResults = new MySingleTableResults()
                    //{
                    //     ChiSquareMantel2P =  stab.ChiSquareMantel2P,
                    //      ChiSquareUncorrected2P = stab.ChiSquareUncorrected2P,
                    //       ChiSquareMantelVal = stab.ChiSquareMantel2P

                    //}

                    gridCells.singleTableResults = new MySingleTableResults()
                    {
                        ChiSquareMantel2P       = stab.ChiSquareMantel2P,
                        ChiSquareMantelVal      = stab.ChiSquareMantelVal,
                        ChiSquareUncorrected2P  = stab.ChiSquareUncorrected2P,
                        ChiSquareUncorrectedVal = stab.ChiSquareUncorrectedVal,
                        ChiSquareYates2P        = stab.ChiSquareYates2P,
                        ChiSquareYatesVal       = stab.ChiSquareYatesVal,
                        ErrorMessage            = stab.ErrorMessage,
                        FisherExact2P           = stab.FisherExact2P,
                        FisherExactP            = stab.FisherExactP,
                        MidP = stab.MidP,
                        OddsRatioEstimate       = stab.OddsRatioEstimate,
                        OddsRatioLower          = stab.OddsRatioLower,
                        OddsRatioMLEEstimate    = stab.OddsRatioMLEEstimate,
                        OddsRatioMLEFisherLower = stab.OddsRatioMLEFisherLower,
                        OddsRatioMLEFisherUpper = stab.OddsRatioMLEFisherUpper,
                        OddsRatioMLEMidPLower   = stab.OddsRatioMLEMidPLower,
                        OddsRatioMLEMidPUpper   = stab.OddsRatioMLEMidPUpper,
                        OddsRatioUpper          = stab.OddsRatioUpper,
                        RiskDifferenceEstimate  = stab.RiskDifferenceEstimate,
                        RiskDifferenceLower     = stab.RiskDifferenceLower,
                        RiskDifferenceUpper     = stab.RiskDifferenceUpper,
                        RiskRatioEstimate       = stab.RiskRatioEstimate,
                        RiskRatioLower          = stab.RiskRatioLower,
                        RiskRatioUpper          = stab.RiskRatioUpper
                    };
                }
            }

            if (gridCells.singleTableResults != null && !string.IsNullOrEmpty(gridCells.singleTableResults.ErrorMessage))
            {
                //this.Dispatcher.BeginInvoke(new SimpleCallback(ClearSingleResults));
                //this.Dispatcher.BeginInvoke(new ShowErrorMessage(ShowError), gridCells.singleTableResults.ErrorMessage);
                //  this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), gridCells.singleTableResults.ErrorMessage);
                //      RenderFinishWithError(gridCells.singleTableResults.ErrorMessage);
                //   resultSet.AddError(thisStringLiterals.RenderFinishWithError, gridCells.singleTableResults.ErrorMessage);
                //stopwatch.Stop();
                //Debug.Print("2x2 table gadget took " + stopwatch.Elapsed.ToString() + " seconds to complete with " + dashboardHelper.RecordCount.ToString() + " records and the following filters:");
                //Debug.Print(dashboardHelper.DataFilters.GenerateDataFilterString());
            }
            else
            {
                //    RenderGridCells(gridCells, table);
                //    RenderFinish();
                resultSet.GridCells = gridCells;
            }

            return(resultSet);
        }
        private void strataTwoByTwoWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            //List<double>[] lists = (List<double>[])e.Argument;

            //List<double> yyList = lists[0];
            //List<double> ynList = lists[1];
            //List<double> nyList = lists[2];
            //List<double> nnList = lists[3];

            double[] yyArr = yyList.ToArray();
            double[] ynArr = ynList.ToArray();
            double[] nyArr = nyList.ToArray();
            double[] nnArr = nnList.ToArray();

            double yySum = yyList.Sum();
            double ynSum = ynList.Sum();
            double nySum = nyList.Sum();
            double nnSum = nnList.Sum();

            StatisticsRepository.Strat2x2 strat2x2 = new StatisticsRepository.Strat2x2();
            StatisticsRepository.cTable.SingleTableResults singleTableResults = new StatisticsRepository.cTable().SigTable(yySum, ynSum, nySum, nnSum, 0.95);

            double computedOddsRatio = (double)strat2x2.ComputeOddsRatio(yyArr, ynArr, nyArr, nnArr);
            double computedOddsRatioMHLL = computedOddsRatio * Math.Exp(-(double)strat2x2.ZSElnOR(yyArr, ynArr, nyArr, nnArr));
            double computedOddsRatioMHUL = computedOddsRatio * Math.Exp((double)strat2x2.ZSElnOR(yyArr, ynArr, nyArr, nnArr));
            double computedRR = (double)strat2x2.ComputedRR(yyArr, ynArr, nyArr, nnArr);
            double computedRRMHLL = computedRR * Math.Exp(-(double)strat2x2.ZSElnRR(yyArr, ynArr, nyArr, nnArr));
            double computedRRMHUL = computedRR * Math.Exp((double)strat2x2.ZSElnRR(yyArr, ynArr, nyArr, nnArr));
            //                double mleOR = (double)strat2x2.ucestimaten(yyArr, ynArr, nyArr, nnArr);
            //                double ExactORLL = (double)strat2x2.exactorln(yyArr, ynArr, nyArr, nnArr);
            //                double ExactORUL = (double)strat2x2.exactorun(yyArr, ynArr, nyArr, nnArr);
            double mleOR = double.NaN;
            double ExactORLL = double.NaN;
            double ExactORUL = double.NaN;
            if (ynSum == 0.0 || nySum == 0.0)
            {
                mleOR = double.PositiveInfinity;
                ExactORLL = (double)strat2x2.exactorln(yyArr, ynArr, nyArr, nnArr);
                ExactORUL = double.PositiveInfinity;
            }
            else if (yySum == 0.0 || nnSum == 0.0)
            {
                mleOR = 0.0;
                ExactORLL = 0.0;
                ExactORUL = (double)strat2x2.exactorun(yyArr, ynArr, nyArr, nnArr, ref mleOR);
            }
            else
            {
                mleOR = (double)strat2x2.ucestimaten(yyArr, ynArr, nyArr, nnArr);
                ExactORLL = (double)strat2x2.exactorln(yyArr, ynArr, nyArr, nnArr);
                ExactORUL = (double)strat2x2.exactorun(yyArr, ynArr, nyArr, nnArr, ref mleOR);
            }
            double uncorrectedChiSquare = strat2x2.ComputeUnChisq(yyArr, ynArr, nyArr, nnArr);
            double corrChisq = strat2x2.ComputeCorrChisq(yyArr, ynArr, nyArr, nnArr);
            double uncorrectedChiSquareP = (double)strat2x2.pForChisq(uncorrectedChiSquare);
            double corrChisqP = (double)strat2x2.pForChisq(corrChisq); string[] results = new string[24];
            results[0] = mleOR.ToString("F4");
            results[1] = ExactORLL.ToString("F4");
            results[2] = ExactORUL.ToString("F4");

            results[3] = computedRR.ToString("F4");
            results[4] = computedRRMHLL.ToString("F4");
            results[5] = computedRRMHUL.ToString("F4");

            try
            {
                results[6] = singleTableResults.OddsRatioEstimate.Value.ToString("F4");
            }
            catch (Exception ex)
            {
                //
            }
            try
            {
                results[7] = singleTableResults.OddsRatioLower.Value.ToString("F4");
            }
            catch (Exception ex)
            {
                //
            }
            try
            {
                results[8] = singleTableResults.OddsRatioUpper.Value.ToString("F4");
            }
            catch (Exception ex)
            {
                //
            }

            results[9] = singleTableResults.OddsRatioMLEEstimate.ToString("F4");
            results[10] = singleTableResults.OddsRatioMLEMidPLower.ToString("F4");
            results[11] = singleTableResults.OddsRatioMLEMidPUpper.ToString("F4");

            results[12] = singleTableResults.OddsRatioMLEFisherLower.ToString("F4");
            results[13] = singleTableResults.OddsRatioMLEFisherUpper.ToString("F4");

            results[14] = singleTableResults.RiskRatioEstimate.Value.ToString("F4");
            results[15] = singleTableResults.RiskRatioLower.Value.ToString("F4");
            results[16] = singleTableResults.RiskRatioUpper.Value.ToString("F4");

            results[17] = computedOddsRatio.ToString("F4");
            results[18] = computedOddsRatioMHLL.ToString("F4");
            results[19] = computedOddsRatioMHUL.ToString("F4");

            results[20] = uncorrectedChiSquare.ToString("F4");
            results[21] = uncorrectedChiSquareP.ToString("F10");

            results[22] = corrChisq.ToString("F4");
            results[23] = corrChisqP.ToString("F10");

            e.Result = results;
        }
예제 #8
0
        private void PrintTable(List<DataRow> pRows, StringBuilder pHTML)
        {
            Dictionary<string, long> ColHeaders = new Dictionary<string, long>(StringComparer.OrdinalIgnoreCase);
            Dictionary<string, long> RowHeaders = new Dictionary<string, long>(StringComparer.OrdinalIgnoreCase);
            Dictionary<string, Dictionary<string, long>> CellDetail = new Dictionary<string, Dictionary<string, long>>(StringComparer.OrdinalIgnoreCase);
            Dictionary<string, DataRow> RowList = new Dictionary<string, DataRow>(StringComparer.OrdinalIgnoreCase);

            //RowTotal = Foreach ColumnValue : Sum(RowValue)
            //ColumnTotal == Foreach Rowvalue : Sum(ColumnValue)

            bool twobytwo = false;

            long ColTotal = 0;

            foreach (DataRow R in pRows)
            {
                string ColKey = GetPrintValue(this.Numeric_Variable,R[this.Numeric_Variable], this.Context.SetProperties);
                string RowKey = GetPrintValue(this.Cross_Tabulation_Variable,R[this.Cross_Tabulation_Variable], this.Context.SetProperties);

                if (ColHeaders.ContainsKey(ColKey))
                {
                    ColHeaders[ColKey] += Convert.ToInt32(R["Outcome"]);
                    ColTotal += Convert.ToInt32(R["Outcome"]);
                }
                else
                {
                    ColHeaders.Add(ColKey, Convert.ToInt32(R["Outcome"]));
                    ColTotal += Convert.ToInt32(R["Outcome"]);
                }

                if (RowHeaders.ContainsKey(RowKey))
                {
                    RowHeaders[RowKey] += Convert.ToInt32(R["Outcome"]);
                }
                else
                {
                    RowHeaders.Add(RowKey, Convert.ToInt32(R["Outcome"]));
                }

                if (CellDetail.ContainsKey(ColKey))
                {
                    if (CellDetail[ColKey].ContainsKey(RowKey))
                    {
                        //System.Diagnostics.Debug.Assert(false);
                        CellDetail[ColKey][RowKey] += Convert.ToInt32(R["Outcome"]);
                    }
                    else
                    {
                        CellDetail[ColKey].Add(RowKey, Convert.ToInt32(R["Outcome"]));
                    }
                }
                else
                {
                    CellDetail.Add(ColKey, new Dictionary<string, long>(StringComparer.OrdinalIgnoreCase));
                    CellDetail[ColKey].Add(RowKey, Convert.ToInt32(R["Outcome"]));
                }
            }

            if (RowHeaders.Count == 2 && ColHeaders.Count == 2 && pRows.Count == 4)
            {
                twobytwo = true;
            }

            pHTML.Append("<table align=\"left\"><tr><th colspan='");
            pHTML.Append(RowHeaders.Count + 2);
            pHTML.Append("'>");
            pHTML.Append(this.Cross_Tabulation_Variable);
            pHTML.Append("</th></tr><tr><th>");
            pHTML.Append(this.Numeric_Variable);
            pHTML.Append("</th>");

            long yy = 0; // yes/yes cell
            long yn = 0; // yes/no cell
            long ny = 0; // no/yes cell
            long nn = 0; // no/no cell
            long rnt = 0; // right no total
            long ryt = 0; // right yes total

            long bnt = 0; // bottom no total
            long byt = 0; // bottom yes total

            long tt = 0; // total

            IEnumerable<KeyValuePair<string, long>> RHE = null;
            IEnumerable<KeyValuePair<string, long>> CHE = null;
            if (twobytwo)
            {
                CHE = ColHeaders.OrderByDescending(x => { return x.Key; });
                RHE = RowHeaders.OrderByDescending(x => { return x.Key; });
            }
            else
            {
                CHE = ColHeaders;
                RHE = RowHeaders;
            }

            foreach (KeyValuePair<string, long> RH in RHE)
            {
                pHTML.Append("<th>");
                pHTML.Append(RH.Key);
                pHTML.Append("</th>");
            }
            pHTML.Append("<th>Total</th></tr>");

            int counter = 0;

            foreach (KeyValuePair<string, long> CH in CHE)
            {
                pHTML.Append("<tr><td>");
                pHTML.Append("<strong>" + CH.Key + "</strong>");
                pHTML.Append("<br/>Row%<br/>Col%</td>");

                foreach (KeyValuePair<string, long> RH in RHE)
                {
                    pHTML.Append("<td>");
                    if (CellDetail.ContainsKey(CH.Key) && CellDetail[CH.Key].ContainsKey(RH.Key))
                    {
                        GetPrintValue(CH.Key, CellDetail[CH.Key][RH.Key], this.Context.SetProperties, pHTML);

                        if (twobytwo)
                        {
                            switch (counter)
                            {
                                case 0:
                                    yy = CellDetail[CH.Key][RH.Key];
                                    break;
                                case 1:
                                    yn = CellDetail[CH.Key][RH.Key];
                                    break;
                                case 3:
                                    ny = CellDetail[CH.Key][RH.Key];
                                    break;
                                case 4:
                                    nn = CellDetail[CH.Key][RH.Key];
                                    break;
                            }
                            counter++;
                        }

                        pHTML.Append("<br/>");
                        GetPrintValue(CH.Key, (Convert.ToDouble(CellDetail[CH.Key][RH.Key]) / Convert.ToDouble(CH.Value)) * 100.0, this.Context.SetProperties, pHTML);
                        pHTML.Append("<br/>");
                        GetPrintValue(CH.Key, (Convert.ToDouble(CellDetail[CH.Key][RH.Key]) / Convert.ToDouble(RH.Value)) * 100.0, this.Context.SetProperties, pHTML);

                    }
                    else
                    {
                        pHTML.Append("0<br/>0<br/>0");
                    }
                    pHTML.Append("</td>");
                }

                pHTML.Append("<td>");
                pHTML.Append(CH.Value.ToString());

                if (twobytwo)
                {
                    switch (counter)
                    {
                        case 2:
                            ryt = CH.Value;
                            break;
                        case 5:
                            rnt = CH.Value;
                            break;
                    }
                    counter++;
                }

                pHTML.Append("<br/>100%<br/>");
                GetPrintValue(CH.Key, Convert.ToDouble(CH.Value) / Convert.ToDouble(ColTotal) * 100.0, this.Context.SetProperties, pHTML);
                pHTML.Append("</td>");

                pHTML.Append("</tr>");
            }

            pHTML.Append("<tr><td>");
            pHTML.Append("<strong>Total</strong>");
            pHTML.Append("</td>");

            long TotalRows = 0;
            counter = 0;

            foreach (KeyValuePair<string, long> RH in RHE)
            {
                pHTML.Append("<td>");
                TotalRows += RH.Value;
                pHTML.Append(RH.Value.ToString());

                if (twobytwo)
                {
                    switch (counter)
                    {
                        case 0:
                            byt = RH.Value;
                            break;
                        case 1:
                            bnt = RH.Value;
                            break;
                    }
                    counter++;
                }

                pHTML.Append("</td>");
            }
            pHTML.Append("<td>");
            pHTML.Append(TotalRows.ToString());
            if (twobytwo)
            {
                tt = TotalRows;
            }
            pHTML.Append("</td>");
            pHTML.Append("</table>");

            if (twobytwo)
            {
                StatisticsRepository.cTable.SingleTableResults singleTableResults;
                singleTableResults = new StatisticsRepository.cTable().SigTable((double)yy, (double)yn, (double)ny, (double)nn, 0.95);

                double yyPct = ((double)yy / (double)tt) * 160;
                double ynPct = ((double)yn / (double)tt) * 160;
                double nyPct = ((double)ny / (double)tt) * 160;
                double nnPct = ((double)nn / (double)tt) * 160;

                string oddsRatioEstimate = Epi.SharedStrings.UNDEFINED;
                string oddsRatioLower = SharedStrings.UNDEFINED;
                string oddsRatioUpper = SharedStrings.UNDEFINED;
                string riskRatioEstimate = SharedStrings.UNDEFINED;
                string riskRatioLower = SharedStrings.UNDEFINED;
                string riskRatioUpper = SharedStrings.UNDEFINED;

                if (singleTableResults.OddsRatioLower != null)
                {
                    oddsRatioLower = ((double)singleTableResults.OddsRatioLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioUpper != null)
                {
                    oddsRatioUpper = ((double)singleTableResults.OddsRatioUpper).ToString("F4");
                }

                if (singleTableResults.RiskRatioEstimate != null)
                {
                    riskRatioEstimate = ((double)singleTableResults.RiskRatioEstimate).ToString("F4");
                }

                if (singleTableResults.RiskRatioLower != null)
                {
                    riskRatioLower = ((double)singleTableResults.RiskRatioLower).ToString("F4");
                }

                if (singleTableResults.RiskRatioUpper != null)
                {
                    riskRatioUpper = ((double)singleTableResults.RiskRatioUpper).ToString("F4");
                }

                pHTML.Append("<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"padding-left: 50px;\">");
                pHTML.Append("<tr>");
                pHTML.Append("<td class=\"TwoByTwo\" valign=\"bottom\" align=\"right\"><div style=\"background-color: red; width:" + yyPct.ToString("F0") + "; height:" + yyPct.ToString("F0") + ";\"><!-- --></td>");
                pHTML.Append("<td class=\"TwoByTwo\" valign=\"bottom\" align=\"left\"><div style=\"background-color: orange; width:" + ynPct.ToString("F0") + "; height:" + ynPct.ToString("F0") + ";\"><!-- --></td>");
                pHTML.Append("</tr><tr>");
                pHTML.Append("<td class=\"TwoByTwo\" valign=\"top\" align=\"right\"><div style=\"background-color: yellow; width:" + nyPct.ToString("F0") + "; height:" + nyPct.ToString("F0") + ";\"><!-- --></td>");
                pHTML.Append("<td class=\"TwoByTwo\" valign=\"top\" align=\"left\"><div style=\"background-color: green; width:" + nnPct.ToString("F0") + "; height:" + nnPct.ToString("F0") + ";\"><!-- --></td>");
                pHTML.Append("</tr></table>");
                pHTML.Append("<br clear=\"all\" />");

                pHTML.Append("<br clear=\"all\" /><h4 align=\"center\"> Single Table Analysis </h4>");
                pHTML.Append("<table align=\"center\">");
                pHTML.Append("<tr><td class=\"stats\"></td><td class=\"stats\" align=\"center\">Point</td>");
                pHTML.Append("<td class=\"stats\" colspan=\"2\" align=\"center\">95% Confidence Interval</td>");
                pHTML.Append("<tr><td class=\"stats\"></td><td class=\"stats\" align=\"center\">Estimate<td class=\"stats\" align=\"right\">Lower<td class=\"stats\" align=\"right\">Upper</td></tr>");
                pHTML.Append("<tr><td class=\"stats\">PARAMETERS: Odds-based</td><td class=\"stats\"></td><td class=\"stats\"></td><td class=\"stats\"></td></tr>");
                pHTML.Append("<tr><td class=\"stats\">Odds Ratio (cross product)</td><td class=\"stats\" align=\"right\">" + /*singleTableResults.OddsRatioEstimate.ToString("F4")*/oddsRatioEstimate + "</td><td class=\"stats\" align=\"right\">" + /*singleTableResults.OddsRatioLower.ToString("F4")*/oddsRatioLower + "</td><td class=\"stats\" align=\"right\">" + /*singleTableResults.OddsRatioUpper.ToString("F4")*/oddsRatioUpper + "<tt> (T)</tt></td></tr>");
                pHTML.Append("<tr><td class=\"stats\">Odds Ratio (MLE)</td><td class=\"stats\" align=\"right\">" + singleTableResults.OddsRatioMLEEstimate.ToString("F4") + "</td><td class=\"stats\" align=\"right\">" + singleTableResults.OddsRatioMLEMidPLower.ToString("F4") + "</td><td class=\"stats\" align=\"right\">" + singleTableResults.OddsRatioMLEMidPUpper.ToString("F4") + "<tt> (M)</tt></td></tr>");
                pHTML.Append("<tr><td class=\"stats\"></td><td class=\"stats\"></td><td class=\"stats\" align=\"right\">" + singleTableResults.OddsRatioMLEFisherLower.ToString("F4") + "</td><td class=\"stats\" align=\"right\">" + singleTableResults.OddsRatioMLEFisherUpper.ToString("F4") + "<tt> (F)</tt></td></tr>");
                pHTML.Append("<tr><td class=\"stats\">PARAMETERS: Risk-based</td><td class=\"stats\"></td><td class=\"stats\"></td><td class=\"stats\"></td></tr>");
                pHTML.Append("<tr><td class=\"stats\">Risk Ratio (RR)</td><td class=\"stats\" align=\"right\">" + /*singleTableResults.RiskRatioEstimate.ToString("F4")*/riskRatioEstimate + "</td><td class=\"stats\" align=\"right\">" + /*singleTableResults.RiskRatioLower.ToString("F4")*/riskRatioLower + "</td><td class=\"stats\" align=\"right\">" + /*singleTableResults.RiskRatioUpper.ToString("F4")*/ riskRatioUpper + "<tt> (T)</tt></td></tr>");
                pHTML.Append("<tr><td class=\"stats\">Risk Difference (RD%)</td><td class=\"stats\" align=\"right\">" + singleTableResults.RiskDifferenceEstimate.ToString("F4") + "</td><td class=\"stats\" align=\"right\">" + singleTableResults.RiskDifferenceLower.ToString("F4") + "</td><td class=\"stats\" align=\"right\">" + singleTableResults.RiskDifferenceUpper.ToString("F4") + "<tt> (T)</tt></td></tr>");
                pHTML.Append("<tr /><tr /><tr /><tr /><tr />");
                pHTML.Append("<tr> <td class=\"stats\" colspan=\"4\"><p align=\"center\"><tt> (T=Taylor series; C=Cornfield; M=Mid-P; F=Fisher Exact)</tt></p></tr>");
                pHTML.Append("<tr /><tr /><tr /><tr /><tr />");
                pHTML.Append("<tr><td class=\"stats\">STATISTICAL TESTS</td> <td class=\"stats\">Chi-square<td class=\"stats\">1-tailed p<td class=\"stats\">2-tailed p<tr><td class=\"stats\">Chi-square - uncorrected<td class=\"stats\" align=\"right\">" + singleTableResults.ChiSquareUncorrectedVal.ToString("F4") + "<td class=\"stats\"><td class=\"stats\" align=\"right\">" + singleTableResults.ChiSquareUncorrected2P.ToString("F10") + "</td></tr>");
                pHTML.Append("<tr><td class=\"stats\">Chi-square - Mantel-Haenszel</td> <td class=\"stats\" align=\"right\">" + singleTableResults.ChiSquareMantelVal.ToString("F4") + "<td class=\"stats\"><td class=\"stats\" align=\"right\">" + singleTableResults.ChiSquareMantel2P.ToString("F10") + "</td></tr>");
                pHTML.Append("<tr><td class=\"stats\">Chi-square - corrected (Yates)</td> <td class=\"stats\" align=\"right\">" + singleTableResults.ChiSquareYatesVal.ToString("F4") + "<td class=\"stats\"></td><td class=\"stats\" align=\"right\">" + singleTableResults.ChiSquareYates2P.ToString("F10") + "</td></tr>");
                pHTML.Append("<tr><td class=\"stats\">Mid-p exact</td>  <td class=\"stats\"></td> <td class=\"stats\" align=\"right\">" + singleTableResults.MidP.ToString("F10") + "</td><td class=\"stats\"></td></tr>");
                pHTML.Append("<tr><td class=\"stats\">Fisher exact</td> <td class=\"stats\"></td> <td class=\"stats\" align=\"right\">" + singleTableResults.FisherExactP.ToString("F10") + "</td><td class=\"stats\"></td></tr>");
                pHTML.Append("</table>");

            }
            pHTML.Append("<br clear=\"all\" />");
            pHTML.Append("<br clear=\"all\" />");
        }
        public void Compute()
        {
            if (YesYesValue.HasValue && YesNoValue.HasValue && NoYesValue.HasValue && NoNoValue.HasValue)
            {
                StatisticsRepository.cTable cTable = new StatisticsRepository.cTable();
                StatisticsRepository.cTable.SingleTableResults singleTableResults = cTable.SigTable((double)yyVal.Value, (double)ynVal.Value, (double)nyVal.Value, (double)nnVal.Value, 0.95);
                cTable = null;

                string fisherExact = Epi.SharedStrings.UNDEFINED;
                string fisherExact2P = Epi.SharedStrings.UNDEFINED;
                string fisherLower = Epi.SharedStrings.UNDEFINED;
                string fisherUpper = Epi.SharedStrings.UNDEFINED;

                string oddsRatioEstimate = Epi.SharedStrings.UNDEFINED;
                string oddsRatioLower = Epi.SharedStrings.UNDEFINED;
                string oddsRatioUpper = Epi.SharedStrings.UNDEFINED;

                string oddsRatioMLEEstimate = Epi.SharedStrings.UNDEFINED;
                string oddsRatioMLEMidPLower = Epi.SharedStrings.UNDEFINED;
                string oddsRatioMLEMidPUpper = Epi.SharedStrings.UNDEFINED;

                string riskRatioEstimate = Epi.SharedStrings.UNDEFINED;
                string riskRatioLower = Epi.SharedStrings.UNDEFINED;
                string riskRatioUpper = Epi.SharedStrings.UNDEFINED;

                if (singleTableResults.FisherExactP != -1)
                {
                    fisherExact = ((double)singleTableResults.FisherExactP).ToString("F10");
                }

                if (singleTableResults.FisherExact2P != -1)
                {
                    fisherExact2P = ((double)singleTableResults.FisherExact2P).ToString("F10");
                }

                if (singleTableResults.OddsRatioMLEFisherLower != -1)
                {
                    fisherLower = ((double)singleTableResults.OddsRatioMLEFisherLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEFisherUpper != -1)
                {
                    fisherUpper = ((double)singleTableResults.OddsRatioMLEFisherUpper).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEEstimate != -1)
                {
                    oddsRatioMLEEstimate = ((double)singleTableResults.OddsRatioMLEEstimate).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEMidPLower != -1)
                {
                    oddsRatioMLEMidPLower = ((double)singleTableResults.OddsRatioMLEMidPLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioMLEMidPUpper != -1)
                {
                    oddsRatioMLEMidPUpper = ((double)singleTableResults.OddsRatioMLEMidPUpper).ToString("F4");
                }

                if (singleTableResults.OddsRatioEstimate != null)
                {
                    oddsRatioEstimate = ((double)singleTableResults.OddsRatioEstimate).ToString("F4");
                }

                if (singleTableResults.OddsRatioLower != null)
                {
                    oddsRatioLower = ((double)singleTableResults.OddsRatioLower).ToString("F4");
                }

                if (singleTableResults.OddsRatioUpper != null)
                {
                    oddsRatioUpper = ((double)singleTableResults.OddsRatioUpper).ToString("F4");
                }

                if (singleTableResults.RiskRatioEstimate != null)
                {
                    riskRatioEstimate = ((double)singleTableResults.RiskRatioEstimate).ToString("F4");
                }

                if (singleTableResults.RiskRatioLower != null)
                {
                    riskRatioLower = ((double)singleTableResults.RiskRatioLower).ToString("F4");
                }

                if (singleTableResults.RiskRatioUpper != null)
                {
                    riskRatioUpper = ((double)singleTableResults.RiskRatioUpper).ToString("F4");
                }

                txtChiSqCorP.Text = singleTableResults.ChiSquareYates2P.ToString("F10");
                txtChiSqCorVal.Text = singleTableResults.ChiSquareYatesVal.ToString("F4");
                txtChiSqManP.Text = singleTableResults.ChiSquareMantel2P.ToString("F10");
                txtChiSqManVal.Text = singleTableResults.ChiSquareMantelVal.ToString("F4");
                txtChiSqUncP.Text = singleTableResults.ChiSquareUncorrected2P.ToString("F10");
                txtChiSqUncVal.Text = singleTableResults.ChiSquareUncorrectedVal.ToString("F4");
                txtOddsRatioEstimate.Text = oddsRatioEstimate;
                txtOddsRatioLower.Text = oddsRatioLower;
                txtOddsRatioUpper.Text = oddsRatioUpper;
                txtMidPEstimate.Text = oddsRatioMLEEstimate;
                txtMidPLower.Text = oddsRatioMLEMidPLower;
                txtMidPUpper.Text = oddsRatioMLEMidPUpper;
                txtRiskDifferenceEstimate.Text = singleTableResults.RiskDifferenceEstimate.ToString("F4");
                txtRiskDifferenceLower.Text = singleTableResults.RiskDifferenceLower.ToString("F4");
                txtRiskDifferenceUpper.Text = singleTableResults.RiskDifferenceUpper.ToString("F4");
                txtRiskRatioEstimate.Text = riskRatioEstimate;
                txtRiskRatioLower.Text = riskRatioLower;
                txtRiskRatioUpper.Text = riskRatioUpper;
                txtFisherLower.Text = fisherLower;
                txtFisherUpper.Text = fisherUpper;
                txtFisherExact.Text = fisherExact;
                txtFisherExact2P.Text = fisherExact2P;
                txtMidPExact.Text = singleTableResults.MidP.ToString("F10");
            }
        }
        private void strataTwoByTwoWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            //List<double>[] lists = (List<double>[])e.Argument;

            //List<double> yyList = lists[0];
            //List<double> ynList = lists[1];
            //List<double> nyList = lists[2];
            //List<double> nnList = lists[3];

            double[] yyArr = yyList.ToArray();
            double[] ynArr = ynList.ToArray();
            double[] nyArr = nyList.ToArray();
            double[] nnArr = nnList.ToArray();

            double yySum = yyList.Sum();
            double ynSum = ynList.Sum();
            double nySum = nyList.Sum();
            double nnSum = nnList.Sum();

            StatisticsRepository.Strat2x2 strat2x2 = new StatisticsRepository.Strat2x2();
            StatisticsRepository.cTable.SingleTableResults singleTableResults = new StatisticsRepository.cTable().SigTable(yySum, ynSum, nySum, nnSum, 0.95);

            double computedOddsRatio     = (double)strat2x2.ComputeOddsRatio(yyArr, ynArr, nyArr, nnArr);
            double computedOddsRatioMHLL = computedOddsRatio * Math.Exp(-(double)strat2x2.ZSElnOR(yyArr, ynArr, nyArr, nnArr));
            double computedOddsRatioMHUL = computedOddsRatio * Math.Exp((double)strat2x2.ZSElnOR(yyArr, ynArr, nyArr, nnArr));
            double computedRR            = (double)strat2x2.ComputedRR(yyArr, ynArr, nyArr, nnArr);
            double computedRRMHLL        = computedRR * Math.Exp(-(double)strat2x2.ZSElnRR(yyArr, ynArr, nyArr, nnArr));
            double computedRRMHUL        = computedRR * Math.Exp((double)strat2x2.ZSElnRR(yyArr, ynArr, nyArr, nnArr));
            //                double mleOR = (double)strat2x2.ucestimaten(yyArr, ynArr, nyArr, nnArr);
            //                double ExactORLL = (double)strat2x2.exactorln(yyArr, ynArr, nyArr, nnArr);
            //                double ExactORUL = (double)strat2x2.exactorun(yyArr, ynArr, nyArr, nnArr);
            double mleOR     = double.NaN;
            double ExactORLL = double.NaN;
            double ExactORUL = double.NaN;

            if (ynSum == 0.0 || nySum == 0.0)
            {
                mleOR     = double.PositiveInfinity;
                ExactORLL = (double)strat2x2.exactorln(yyArr, ynArr, nyArr, nnArr);
                ExactORUL = double.PositiveInfinity;
            }
            else if (yySum == 0.0 || nnSum == 0.0)
            {
                mleOR     = 0.0;
                ExactORLL = 0.0;
                ExactORUL = (double)strat2x2.exactorun(yyArr, ynArr, nyArr, nnArr, ref mleOR);
            }
            else
            {
                mleOR     = (double)strat2x2.ucestimaten(yyArr, ynArr, nyArr, nnArr);
                ExactORLL = (double)strat2x2.exactorln(yyArr, ynArr, nyArr, nnArr);
                ExactORUL = (double)strat2x2.exactorun(yyArr, ynArr, nyArr, nnArr, ref mleOR);
            }
            double uncorrectedChiSquare = strat2x2.ComputeUnChisq(yyArr, ynArr, nyArr, nnArr);
            double corrChisq = strat2x2.ComputeCorrChisq(yyArr, ynArr, nyArr, nnArr);
            double uncorrectedChiSquareP = (double)strat2x2.pForChisq(uncorrectedChiSquare);
            double corrChisqP = (double)strat2x2.pForChisq(corrChisq); string[] results = new string[24];

            results[0] = mleOR.ToString("F4");
            results[1] = ExactORLL.ToString("F4");
            results[2] = ExactORUL.ToString("F4");

            results[3] = computedRR.ToString("F4");
            results[4] = computedRRMHLL.ToString("F4");
            results[5] = computedRRMHUL.ToString("F4");

            try
            {
                results[6] = singleTableResults.OddsRatioEstimate.Value.ToString("F4");
            }
            catch (Exception ex)
            {
                //
            }
            try
            {
                results[7] = singleTableResults.OddsRatioLower.Value.ToString("F4");
            }
            catch (Exception ex)
            {
                //
            }
            try
            {
                results[8] = singleTableResults.OddsRatioUpper.Value.ToString("F4");
            }
            catch (Exception ex)
            {
                //
            }

            results[9]  = singleTableResults.OddsRatioMLEEstimate.ToString("F4");
            results[10] = singleTableResults.OddsRatioMLEMidPLower.ToString("F4");
            results[11] = singleTableResults.OddsRatioMLEMidPUpper.ToString("F4");

            results[12] = singleTableResults.OddsRatioMLEFisherLower.ToString("F4");
            results[13] = singleTableResults.OddsRatioMLEFisherUpper.ToString("F4");

            results[14] = singleTableResults.RiskRatioEstimate.Value.ToString("F4");
            results[15] = singleTableResults.RiskRatioLower.Value.ToString("F4");
            results[16] = singleTableResults.RiskRatioUpper.Value.ToString("F4");

            results[17] = computedOddsRatio.ToString("F4");
            results[18] = computedOddsRatioMHLL.ToString("F4");
            results[19] = computedOddsRatioMHUL.ToString("F4");

            results[20] = uncorrectedChiSquare.ToString("F4");
            results[21] = uncorrectedChiSquareP.ToString("F10");

            results[22] = corrChisq.ToString("F4");
            results[23] = corrChisqP.ToString("F10");

            e.Result = results;
        }