示例#1
0
        protected override string CreateReportLine(
            ModelScorer modelScorer,
            PhyloTree phyloTree,
            RowData rowAndTargetData,
            UniversalWorkList workList,
            int rowIndex, int workListCount, int workIndex)
        {
            Dictionary <string, string> row = rowAndTargetData.Row;
            string predictorVariable        = row[PhyloTree.PredictorVariableColumnName]; // e.g. hla
            string targetVariable           = row[PhyloTree.TargetVariableColumnName];    // e.g. A@182 (amino acid "A" at position 182)
            int    nullIndex = int.Parse(row[PhyloTree.NullIndexColumnName]);

            //Dictionary<string, bool> caseIdToNonMissingPredictorValue = workList.NullIndexToPredictorToCaseIdToNonMissingValue[nullIndex][predictorVariable];
            Dictionary <string, SufficientStatistics> caseIdToNonMissingPredictorValue = rowAndTargetData.PredictorData; //workList.GetCaseIdToNonMissingValueForNullIndexAndPredictorVariable(nullIndex, predictorVariable);
            Dictionary <string, SufficientStatistics> caseIdToNonMissingTargetValue    = rowAndTargetData.TargetData;

            TwoByTwo fishers2by2 = TwoByTwo.GetInstance(
                SufficientStatisticsMapToIntMap(caseIdToNonMissingPredictorValue),
                SufficientStatisticsMapToIntMap(caseIdToNonMissingTargetValue));

            double pValue = fishers2by2.FisherExactTest;

            string reportLine = SpecialFunctions.CreateTabString(this, rowIndex, workListCount, workIndex, nullIndex,
                                                                 predictorVariable,
                                                                 targetVariable,
                                                                 fishers2by2.CountsString(),
                                                                 fishers2by2.FisherExactTest);

            return(reportLine);
        }
示例#2
0
        public override EvaluationResults EvaluateModelOnDataGivenParams(Converter <Leaf, SufficientStatistics> v1, Converter <Leaf, SufficientStatistics> v2, EvaluationResults previousResults)
        {
            TwoByTwo fishers2by2 = TwoByTwo.GetInstance(
                SufficientStatisticsMapToIntDictionaryMap(v1, _fullLeafCollection),
                SufficientStatisticsMapToIntDictionaryMap(v2, _fullLeafCollection));

            int[] fisherCounts = fishers2by2.ToOneDArray();

            List <Score> nullScores;
            Score        altScore;

            ComputeIidScoresGivenParams(fisherCounts,
                                        previousResults.NullScores[0].OptimizationParameters, previousResults.NullScores[1].OptimizationParameters,
                                        previousResults.AltScore.OptimizationParameters,
                                        out nullScores, out altScore);

            //int tt = fisherCounts[(int)TwoByTwo.ParameterIndex.TT];
            //int tf = fisherCounts[(int)TwoByTwo.ParameterIndex.TF];
            //int ft = fisherCounts[(int)TwoByTwo.ParameterIndex.FT];
            //int ff = fisherCounts[(int)TwoByTwo.ParameterIndex.FF];
            //int sum = SpecialFunctions.Sum(fisherCounts);

            //double pi0 = (double)(tt + tf) / sum;
            //double pi1 = (double)(tt + ft) / sum;
            //double ptt = (double)tt / sum;
            //double ptf = (double)tf / sum;
            //double pft = (double)ft / sum;
            //double pff = 1 - ptt - ptf - pft;

            //double predicted_pi0 = previousResults.NullScores[0].OptimizationParameters[0].Value;
            //double predicted_pi1 = previousResults.NullScores[1].OptimizationParameters[0].Value;
            //double predicted_ptt = previousResults.AltScore.OptimizationParameters[0].Value;
            //double predicted_ptf = previousResults.AltScore.OptimizationParameters[1].Value;
            //double predicted_pft = previousResults.AltScore.OptimizationParameters[2].Value;
            //double predicted_pff = 1 - predicted_ptt - predicted_ptf - predicted_pft;


            //double nullLLLeft = pi0 * Math.Log(predicted_pi0);
            //double nullLLRight = pi1 * Math.Log(predicted_pi1);
            //double altLL = predicted_ptt * Math.Log(ptt) + predicted_ptf * Math.Log(ptf) + predicted_pft * Math.Log(pft) + predicted_pff * Math.Log(pff);

            //Score nullScoreLeft = Score.GetInstance(nullLLLeft, previousResults.NullScores[0].OptimizationParameters, null);
            //Score nullScoreRight = Score.GetInstance(nullLLRight, previousResults.NullScores[1].OptimizationParameters, null);
            //Score altScore = Score.GetInstance(altLL, previousResults.AltScore.OptimizationParameters, null);

            //List<Score> nullScores = new List<Score>(2);
            //nullScores.Add(nullScoreLeft);
            //nullScores.Add(nullScoreRight);

            EvaluationResults results = EvaluationResultsFisher.GetInstance(this, nullScores, altScore, fishers2by2);

            return(results);
        }
示例#3
0
        public override string ToHeaderString()
        {
            //EvaluationResults dummyResults = EvaluationResultsFisher.GetInstance(this, TwoByTwo.GetInstance(new int[] { 1, 1, 1, 1 }));
            List <Score> nullScores;
            Score        altScore;
            TwoByTwo     fishers2by2 = TwoByTwo.GetInstance(new int[] { 1, 1, 1, 1 });

            ComputeIidScores(fishers2by2.ToOneDArray(), out nullScores, out altScore);

            EvaluationResults dummyResults = EvaluationResultsFisher.GetInstance(this, nullScores, altScore, fishers2by2);

            return(dummyResults.ToHeaderString());
        }
示例#4
0
        public override EvaluationResults EvaluateModelOnData(Converter <Leaf, SufficientStatistics> predMap, Converter <Leaf, SufficientStatistics> targMap)
        {
            TwoByTwo fishers2by2 = TwoByTwo.GetInstance(
                SufficientStatisticsMapToIntDictionaryMap(predMap, _fullLeafCollection),
                SufficientStatisticsMapToIntDictionaryMap(targMap, _fullLeafCollection));

            int[]        fisherCounts = fishers2by2.ToOneDArray();
            List <Score> nullScores;
            Score        altScore;

            ComputeIidScores(fisherCounts, out nullScores, out altScore);

            EvaluationResultsFisher results = EvaluationResultsFisher.GetInstance(this, nullScores, altScore, fishers2by2);

#if DEBUG
            EvaluationResults results2 = EvaluateModelOnDataGivenParams(predMap, targMap, results);
            double            eps      = 1E-14;
            Debug.Assert(ComplexNumber.ApproxEqual(results.AltLL, results2.AltLL, eps));
            Debug.Assert(ComplexNumber.ApproxEqual(results.NullLL, results2.NullLL, eps));
            Debug.Assert(ComplexNumber.ApproxEqual(results.ComputePValue(), results2.ComputePValue(), eps));
#endif

            return(results);
        }