Exemplo n.º 1
0
        private MySingleTableResults ConvertSingleTableResultToLocal(StatisticsRepository.cTable.SingleTableResults stResults)
        {
            MySingleTableResults mystResults = new MySingleTableResults();

            mystResults.ChiSquareMantel2P       = stResults.ChiSquareMantel2P;
            mystResults.ChiSquareMantel2P       = stResults.ChiSquareMantel2P;
            mystResults.ChiSquareMantelVal      = stResults.ChiSquareMantelVal;
            mystResults.ChiSquareUncorrected2P  = stResults.ChiSquareUncorrected2P;
            mystResults.ChiSquareUncorrectedVal = stResults.ChiSquareUncorrectedVal;
            mystResults.ChiSquareYates2P        = stResults.ChiSquareYates2P;
            mystResults.ChiSquareYatesVal       = stResults.ChiSquareYatesVal;
            mystResults.ErrorMessage            = stResults.ErrorMessage;
            mystResults.FisherExact2P           = stResults.FisherExact2P;
            mystResults.FisherExactP            = stResults.FisherExactP;
            mystResults.MidP = stResults.MidP;
            mystResults.OddsRatioEstimate       = stResults.OddsRatioEstimate;
            mystResults.OddsRatioLower          = stResults.OddsRatioLower;
            mystResults.OddsRatioMLEEstimate    = stResults.OddsRatioMLEEstimate;
            mystResults.OddsRatioMLEFisherLower = stResults.OddsRatioMLEFisherLower;
            mystResults.OddsRatioMLEFisherUpper = stResults.OddsRatioMLEFisherUpper;
            mystResults.OddsRatioMLEMidPLower   = stResults.OddsRatioMLEMidPLower;
            mystResults.OddsRatioMLEMidPUpper   = stResults.OddsRatioMLEMidPUpper;
            mystResults.OddsRatioUpper          = stResults.OddsRatioUpper;
            mystResults.RiskDifferenceEstimate  = stResults.RiskDifferenceEstimate;
            mystResults.RiskDifferenceLower     = stResults.RiskDifferenceLower;
            mystResults.RiskDifferenceUpper     = stResults.RiskDifferenceUpper;
            mystResults.RiskRatioEstimate       = stResults.RiskRatioEstimate;
            mystResults.RiskRatioLower          = stResults.RiskRatioLower;
            mystResults.RiskRatioUpper          = stResults.RiskRatioUpper;

            return(mystResults);
        }
Exemplo n.º 2
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       = "";
                }
            }
        }
Exemplo n.º 3
0
        public void TwoByTwoTest()
        {
            int iterations = 100;

            StatisticsRepository.cTable cTable = new StatisticsRepository.cTable();

            var reader      = new StreamReader(File.OpenRead(@"..\..\Data\TwoBy2Stats.csv"));
            int linesinfile = iterations;

            double[] chisqs       = new double[linesinfile];
            double[] chisqps      = new double[linesinfile];
            double[] mhchisqs     = new double[linesinfile];
            double[] mhchisqps    = new double[linesinfile];
            double[] yateschisqs  = new double[linesinfile];
            double[] yateschisqps = new double[linesinfile];
            double[] ors          = new double[linesinfile];
            double[] orlowers     = new double[linesinfile];
            double[] oruppers     = new double[linesinfile];
            double[] rrs          = new double[linesinfile];
            double[] rrlowers     = new double[linesinfile];
            double[] rruppers     = new double[linesinfile];
            double[] fisherlowers = new double[linesinfile];
            double[] fisheruppers = new double[linesinfile];
            double[] fisher1s     = new double[linesinfile];
            double[] fisher2s     = new double[linesinfile];
            int      i            = 0;

            while (!reader.EndOfStream)
            {
                var  line   = reader.ReadLine();
                var  values = line.Split(',');
                bool rv     = Double.TryParse(values[1], out chisqs[i]);
                rv = Double.TryParse(values[2], out chisqps[i]);
                rv = Double.TryParse(values[3], out mhchisqs[i]);
                rv = Double.TryParse(values[4], out mhchisqps[i]);
                rv = Double.TryParse(values[5], out yateschisqs[i]);
                rv = Double.TryParse(values[6], out yateschisqps[i]);
                rv = Double.TryParse(values[7], out ors[i]);
                rv = Double.TryParse(values[8], out orlowers[i]);
                rv = Double.TryParse(values[9], out oruppers[i]);
                rv = Double.TryParse(values[10], out rrs[i]);
                rv = Double.TryParse(values[11], out rrlowers[i]);
                rv = Double.TryParse(values[12], out rruppers[i]);
                rv = Double.TryParse(values[13], out fisherlowers[i]);
                rv = Double.TryParse(values[14], out fisheruppers[i]);
                rv = Double.TryParse(values[15], out fisher1s[i]);
                rv = Double.TryParse(values[16], out fisher2s[i]);
                i++;
                if (i == linesinfile)
                {
                    break;
                }
            }

            for (int j = 0; j < iterations; j++)
            {
                getData("LogisticTestData", "iteration = " + j);
                int yy = mainTable.Select("depvar = 1 and indepvar1 = 1").Length;
                int yn = mainTable.Select("depvar = 1 and indepvar1 = 0").Length;
                int ny = mainTable.Select("depvar = 0 and indepvar1 = 1").Length;
                int nn = mainTable.Select("depvar = 0 and indepvar1 = 0").Length;
                StatisticsRepository.cTable.SingleTableResults singleTableResults = cTable.SigTable((double)yy, (double)yn, (double)ny, (double)nn, 0.95);
                Assert.AreEqual(singleTableResults.ChiSquareUncorrectedVal, chisqs[j], 0.0001);
                Assert.AreEqual(singleTableResults.ChiSquareUncorrected2P, chisqps[j], 0.0001);
                Assert.AreEqual(singleTableResults.ChiSquareMantelVal, mhchisqs[j], 0.0001);
                Assert.AreEqual(singleTableResults.ChiSquareMantel2P, mhchisqps[j], 0.0001);
                Assert.AreEqual(singleTableResults.ChiSquareYatesVal, yateschisqs[j], 0.0001);
                Assert.AreEqual(singleTableResults.ChiSquareYates2P, yateschisqps[j], 0.0001);
                Assert.AreEqual(singleTableResults.OddsRatioEstimate.Value, ors[j], 0.0001);
                Assert.AreEqual(singleTableResults.OddsRatioLower.Value, orlowers[j], 0.0001);
                Assert.AreEqual(singleTableResults.OddsRatioUpper.Value, oruppers[j], 0.001);
                Assert.AreEqual(singleTableResults.RiskRatioEstimate.Value, rrs[j], 0.0001);
                Assert.AreEqual(singleTableResults.RiskRatioLower.Value, rrlowers[j], 0.0001);
                Assert.AreEqual(singleTableResults.RiskRatioUpper.Value, rruppers[j], 0.0001);
                Assert.AreEqual(singleTableResults.OddsRatioMLEFisherLower, fisherlowers[j], 0.0001);
                Assert.AreEqual(singleTableResults.OddsRatioMLEFisherUpper, fisheruppers[j], 0.0001);
                Assert.AreEqual(singleTableResults.FisherExactP, fisher1s[j], 0.0001);
                Assert.AreEqual(singleTableResults.FisherExact2P, fisher2s[j], 0.0001);
            }
        }
        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");
            }
        }