예제 #1
0
        public static string printCount(List <RowMatchPool> rowMatchPools, DataMatcher dataMatcher)
        {
            StringBuilder result = new StringBuilder();

            result.AppendLine("\tFemale\t\tMale\t\tTotal\t\t");
            result.AppendLine("AgeGrp\tPrimary\tMatch\tPrimary\tMatch\tPrimary\tMatch");


            for (int i = 0; i < rowMatchPools.Count / 2; i++)
            {
                string line = (i + 1).ToString();
                int    primaryFemaleCount = rowMatchPools[i * 2].primaryRows.Count;
                int    matchFemaleCount   = rowMatchPools[i * 2].matchedRows.Count;
                int    primaryMaleCount   = rowMatchPools[i * 2 + 1].primaryRows.Count;
                int    matchMaleCount     = rowMatchPools[i * 2 + 1].matchedRows.Count;
                int    primaryTotalCount  = primaryFemaleCount + primaryMaleCount;
                int    matchTotalCount    = matchFemaleCount + matchMaleCount;

                line += "\t" + primaryFemaleCount;
                line += "\t" + matchFemaleCount;
                line += "\t" + primaryMaleCount;
                line += "\t" + matchMaleCount;
                line += "\t" + primaryTotalCount;
                line += "\t" + matchTotalCount;
                result.AppendLine(line);
            }
            return(result.ToString());
        }
예제 #2
0
 static void initializeGroupContent(DataMatcher dataMatcher)
 {
     for (int i = 1; i <= 11; i++)
     {
         for (int j = 0; j <= 1; j++)
         {
             dataMatcher.addGroupContentList(new string[] { i.ToString(), j.ToString() });
         }
     }
 }
예제 #3
0
        static string MatchAndCalculateChiSquare(string name, int repeat, DataSet Primary, DataSet Match, int matchCount,
                                                 List <FieldNameToTest> CalculateField)
        {
            StringBuilder result = new StringBuilder();
            int           primaryMore = 0, matchMore = 0;
            int           succussefulMatch = 0;

            for (int i = 0; i < repeat; i++)
            {
                DataMatcher dataMatcher = new DataMatcher();
                dataMatcher.addMatchKey("AGEGROUP");
                dataMatcher.addMatchKey("CASESEX");
                initializeGroupContent(dataMatcher);
                dataMatcher.setPrimaryData(Primary);
                dataMatcher.setMatchData(Match);
                List <RowMatchPool> matchPools = dataMatcher.matchIntoPools();
                SampleRandomizely.sampleTheMatchList(matchPools, matchCount);
                ChiSquareCalculator chiSquare = new ChiSquareCalculator(CalculateField, matchPools);
                chiSquare.countPosAndNegInBothGroup();
                result.AppendLine($"Test #{i + 1}");
                result.AppendLine(ChiSquareCalculator.printTitle());
                result.Append(chiSquare.printResult(ref primaryMore, ref matchMore, name));
                result.AppendLine("");
                if (Primary.dataRow.Count * repeat >= Match.dataRow.Count)
                {
                    succussefulMatch++;
                }
                if (i == repeat - 1)
                {
                    result.AppendLine("Match Detail");
                    result.Append(SummarizeMatchPools.printCount(matchPools, dataMatcher));
                    result.AppendLine("");
                }
            }
            Console.WriteLine($"calculate Chi square table {name} for {repeat} times");
            string summary  = $"Significant result: Primary > Matched:{primaryMore},  Matched > Primary:{matchMore}, Non-Significant:{repeat - primaryMore - matchMore}";
            string summary2 = ($"[match raito] 1:{matchCount}, success matching = {Math.Round(((double)succussefulMatch * 100 / repeat), 1)}%");

            return(name + "\r\n" + summary + "\r\n" + summary2 + "\r\n" + result.ToString());
        }