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;
        }
Exemplo n.º 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)
            {
                //
            }
        }
        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;
        }