Exemple #1
0
        new public double[] computeNew(object category)
        {
            int lblIndex = Labels.IndexOf(category.ToString());
            int gN       = cateDic[category.ToString()];

            Accord.Statistics.Distributions.Univariate.TDistribution tDist = new Accord.Statistics.Distributions.Univariate.TDistribution(gN - 1);
            double[] s      = sumX[lblIndex];
            double[] s2     = sumX2[lblIndex];
            double[] mns    = (from double d in s select d / gN).ToArray();
            double[] ses    = getSe(s, s2, gN);
            double[] outArr = new double[mns.Length];
            for (int i = 0; i < outArr.Length; i++)
            {
                double tStat  = mns[i] / ses[i];
                double cdf    = tDist.DistributionFunction(tStat);
                double pValue = 0;
                if (tStat > 0)
                {
                    pValue = (1 - cdf) * 2;
                }
                else
                {
                    pValue = (cdf * 2);
                }
                outArr[i] = pValue;
            }
            return(outArr);
        }
Exemple #2
0
        public static void PairedTTestPValues(double[] popMeans, double[,] popVarCov, double[] sampMeans, double[,] sampVarCov, out double meanPvalue, out double varPvalue)
        {
            double n = popMeans.Length;

            meanPvalue = 0;
            varPvalue  = 0;
            double sumM  = 0;
            double sumV  = 0;
            double sumM2 = 0;
            double sumV2 = 0;

            for (int i = 0; i < n; i++)
            {
                double m1 = popMeans[i];
                double m2 = sampMeans[i];
                double dm = m1 - m2;
                double v1 = popVarCov[i, i];
                double v2 = sampVarCov[i, i];
                double dv = v1 - v2;
                sumM  += dm;
                sumV  += dv;
                sumM2 += dm * dm;
                sumV2 += dv * dv;
            }
            double mM     = sumM / n;
            double mV     = sumV / n;
            double seM    = Math.Sqrt((sumM2 - ((sumM * sumM) / n)) / n) / Math.Sqrt(n);
            double seV    = Math.Sqrt((sumV2 - ((sumV * sumV) / n)) / n) / Math.Sqrt(n);
            double mTstat = mM / seM;
            double vTstat = mV / seV;

            Accord.Statistics.Distributions.Univariate.TDistribution tDist = new Accord.Statistics.Distributions.Univariate.TDistribution(n - 1);
            double mCdf = tDist.DistributionFunction(mTstat);
            double vCdf = tDist.DistributionFunction(vTstat);

            if (mTstat > 0)
            {
                meanPvalue = (1 - mCdf) * 2;
            }
            else
            {
                meanPvalue = mCdf * 2;
            }
            if (vTstat > 0)
            {
                varPvalue = (1 - vCdf) * 2;
            }
            else
            {
                varPvalue = vCdf * 2;
            }
        }
Exemple #3
0
        public double[] computeNew(object category)
        {
            string cat      = category.ToString();
            int    catIndex = lbl.IndexOf(cat);
            int    np       = ((VariableFieldNames.Length * VariableFieldNames.Length) - VariableFieldNames.Length) / 2;

            double[] pValues = new double[np];
            if (catIndex == -1)
            {
                return(pValues);
            }
            KMeansClusterCollection gCol   = kmeans.Clusters;
            KMeansCluster           gClust = gCol[catIndex];

            double[] mns      = gClust.Mean;
            double[] var      = new double[mns.Length];
            double   nSample  = gClust.Proportion * N;
            double   seAdjust = Math.Sqrt(2 * 1 / nSample);

            for (int j = 0; j < mns.Length; j++)
            {
                var[j] = gClust.Covariance[j, j];
            }
            int cnt  = 1;
            int pCnt = 0;

            for (int j = 0; j < mns.Length - 1; j++)
            {
                for (int k = cnt; k < mns.Length; k++)
                {
                    double mD    = mns[j] - mns[k];
                    double pSD   = Math.Sqrt((var[j] + var[k]) / 2);
                    double se    = pSD * seAdjust;
                    double tStat = mD / se;
                    Accord.Statistics.Distributions.Univariate.TDistribution tDist = new Accord.Statistics.Distributions.Univariate.TDistribution(2 * nSample - 2);
                    double cdf    = tDist.DistributionFunction(tStat);
                    double pValue = 0;
                    if (tStat > 0)
                    {
                        pValue = (1 - cdf) * 2;
                    }
                    else
                    {
                        pValue = (cdf * 2);
                    }
                    pValues[pCnt] = pValue;
                    pCnt++;
                }
                cnt += 1;
            }
            return(pValues);
        }
 public new void getReport()
 {
     if (cateDic.Count<1) buildModel();
     rd = new Forms.RunningProcess.frmRunningProcessDialog(false);
     rd.Text = "Paired T-Test Results";
     rd.TopLevel = true;
     rd.pgbProcess.Visible = false;
     rd.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
     rd.addMessage("Input path = " + InPath);
     rd.addMessage("Total Sample size = " + n.ToString());
     rd.addMessage("\nLabel   |Compare V1-V2            |N       |Dif     |T-Stat  |P-Value ");
     rd.addMessage("-".PadRight(83, '-'));
     for (int i = 0; i < lbl.Count; i++)
     {
         string labelVl = Labels[i];
         string l = getValue(labelVl, 8);
         int gN = cateDic[labelVl];
         if (gN == 1) continue;
         double[] s = sumX[i];
         double[] s2 = sumX2[i];
         double[] mns = (from double d in s select d/gN).ToArray();
         //Console.WriteLine("Means = " + mns.Length.ToString());
         double[] ses = getSe(s, s2, gN);
         //Console.WriteLine("Se = " + ses.Length.ToString());
         double nSample = gN;
         int cnt = 1;
         int sCnt = 0;
         for (int j = 0; j < VariableFieldNames.Length-1; j++)
         {
             for (int k = cnt; k < VariableFieldNames.Length; k++)
             {
                 string fN1 = getValue(VariableFieldNames[j], 12);
                 string fN2 = getValue(VariableFieldNames[k], 12);
                 double mD = mns[sCnt];
                 double se = ses[sCnt];
                 double tStat = mD / se;
                 //Console.WriteLine(tStat.ToString());
                 Accord.Statistics.Distributions.Univariate.TDistribution tDist = new Accord.Statistics.Distributions.Univariate.TDistribution(nSample - 1);
                 double cdf = tDist.DistributionFunction(tStat);
                 double pValue = 0;
                 if (tStat > 0)
                 {
                     pValue = (1 - cdf) * 2;
                 }
                 else
                 {
                     pValue = (cdf * 2);
                 }
                 string pValueS = pValue.ToString();
                 if (pValue < 0.0001) pValueS = pValueS = "p < 0.0001";
                 string ln = l + "|" + fN1 + "-" + fN2 + "| " + getValue(nSample.ToString(), 6) + " | " + getValue(mD.ToString(), 6) + " | " + getValue(tStat.ToString(), 6) + " | " + getValue(pValueS,10);
                 rd.addMessage(ln);
                 sCnt += 1;
             }
             cnt += 1;
         }
     }
     rd.addMessage("-".PadRight(83, '-'));
     rd.enableClose();
     rd.Show();
 }
 public new double[] computeNew(object category)
 {
     int lblIndex = Labels.IndexOf(category.ToString());
     int gN = cateDic[category.ToString()];
     Accord.Statistics.Distributions.Univariate.TDistribution tDist = new Accord.Statistics.Distributions.Univariate.TDistribution(gN - 1);
     double[] s = sumX[lblIndex];
     double[] s2 = sumX2[lblIndex];
     double[] mns = (from double d in s select d / gN).ToArray();
     double[] ses = getSe(s, s2, gN);
     double[] outArr = new double[mns.Length];
     for (int i = 0; i < outArr.Length; i++)
     {
         double tStat = mns[i] / ses[i];
         double cdf = tDist.DistributionFunction(tStat);
         double pValue = 0;
         if (tStat > 0)
         {
             pValue = (1 - cdf) * 2;
         }
         else
         {
             pValue = (cdf * 2);
         }
         outArr[i] = pValue;
     }
     return outArr;
 }
 public void getReport()
 {
     if (kmeans == null) buildModel();
     rd = new Forms.RunningProcess.frmRunningProcessDialog(false);
     rd.Text = "Independent T-Test Results";
     rd.TopLevel = true;
     rd.pgbProcess.Visible = false;
     rd.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
     rd.addMessage("Input path = " + InPath);
     rd.addMessage("Total Sample size = " + n.ToString());
     rd.addMessage("\nLabel   |Compare V1-V2            |N       |Dif     |T-Stat  |P-Value ");
     rd.addMessage("-".PadRight(83,'-'));
     KMeansClusterCollection gCol = kmeans.Clusters;
     for (int i = 0; i < gCol.Count; i++)
     {
         string l = getValue(Labels[i],8);
         KMeansCluster gClust = gCol[i];
         double[] mns = gClust.Mean;
         double[] var = new double[mns.Length];
         double nSample = gClust.Proportion * N;
         if (nSample <= 1) continue;
         double seAdjust = Math.Sqrt(2*1/nSample);
         for (int j = 0; j < mns.Length; j++)
         {
             var[j] = gClust.Covariance[j, j];
         }
         int cnt = 1;
         for (int j = 0; j < mns.Length-1; j++)
         {
             for (int k = cnt; k < mns.Length; k++)
             {
                 string fN1 = getValue(VariableFieldNames[j],12);
                 string fN2 = getValue(VariableFieldNames[k],12);
                 double mD = mns[j] - mns[k];
                 double pSD = Math.Sqrt((var[j] + var[k]) / 2);
                 double se = pSD * seAdjust;
                 double tStat = mD / se;
                 Accord.Statistics.Distributions.Univariate.TDistribution tDist = new Accord.Statistics.Distributions.Univariate.TDistribution(2*nSample-2);
                 double cdf = tDist.DistributionFunction(tStat);
                 double pValue = 0;
                 if (tStat>0)
                 {
                     pValue = (1 - cdf) * 2;
                 }
                 else
                 {
                     pValue = (cdf * 2);
                 }
                 string pValueS = pValue.ToString();
                 if (pValue < 0.0001) pValueS = "p < 0.0001";
                 string ln = l + "|" + fN1 + "-" + fN2 + "| " + getValue(nSample.ToString(), 6) + " | " + getValue(mD.ToString(), 6) + " | " + getValue(tStat.ToString(), 6) + " | " + getValue(pValueS,10);
                 rd.addMessage(ln);
             }
             cnt += 1;
         }
     }
     rd.addMessage("-".PadRight(83, '-'));
     rd.enableClose();
     rd.Show();
 }
 public double[] computeNew(object category)
 {
     string cat = category.ToString();
     int catIndex = lbl.IndexOf(cat);
     int np = ((VariableFieldNames.Length * VariableFieldNames.Length) - VariableFieldNames.Length) / 2;
     double[] pValues = new double[np];
     if (catIndex == -1) return pValues;
     KMeansClusterCollection gCol = kmeans.Clusters;
     KMeansCluster gClust = gCol[catIndex];
     double[] mns = gClust.Mean;
     double[] var = new double[mns.Length];
     double nSample = gClust.Proportion * N;
     double seAdjust = Math.Sqrt(2 * 1 / nSample);
     for (int j = 0; j < mns.Length; j++)
     {
         var[j] = gClust.Covariance[j, j];
     }
     int cnt = 1;
     int pCnt = 0;
     for (int j = 0; j < mns.Length-1; j++)
     {
         for (int k = cnt; k < mns.Length; k++)
         {
             double mD = mns[j] - mns[k];
             double pSD = Math.Sqrt((var[j] + var[k]) / 2);
             double se = pSD * seAdjust;
             double tStat = mD / se;
             Accord.Statistics.Distributions.Univariate.TDistribution tDist = new Accord.Statistics.Distributions.Univariate.TDistribution(2*nSample-2);
             double cdf = tDist.DistributionFunction(tStat);
             double pValue = 0;
             if (tStat>0)
             {
                 pValue = (1 - cdf) * 2;
             }
             else
             {
                 pValue = (cdf * 2);
             }
             pValues[pCnt] = pValue;
             pCnt++;
         }
         cnt += 1;
     }
     return pValues;
 }
Exemple #8
0
 new public void getReport()
 {
     if (cateDic.Count < 1)
     {
         buildModel();
     }
     rd                    = new Forms.RunningProcess.frmRunningProcessDialog(false);
     rd.Text               = "Paired T-Test Results";
     rd.TopLevel           = true;
     rd.pgbProcess.Visible = false;
     rd.FormBorderStyle    = System.Windows.Forms.FormBorderStyle.Sizable;
     rd.addMessage("Input path = " + InPath);
     rd.addMessage("Total Sample size = " + n.ToString());
     rd.addMessage("\nLabel   |Compare V1-V2            |N       |Dif     |T-Stat  |P-Value ");
     rd.addMessage("-".PadRight(83, '-'));
     for (int i = 0; i < lbl.Count; i++)
     {
         string labelVl = Labels[i];
         string l       = getValue(labelVl, 8);
         int    gN      = cateDic[labelVl];
         if (gN == 1)
         {
             continue;
         }
         double[] s   = sumX[i];
         double[] s2  = sumX2[i];
         double[] mns = (from double d in s select d / gN).ToArray();
         //Console.WriteLine("Means = " + mns.Length.ToString());
         double[] ses = getSe(s, s2, gN);
         //Console.WriteLine("Se = " + ses.Length.ToString());
         double nSample = gN;
         int    cnt     = 1;
         int    sCnt    = 0;
         for (int j = 0; j < VariableFieldNames.Length - 1; j++)
         {
             for (int k = cnt; k < VariableFieldNames.Length; k++)
             {
                 string fN1   = getValue(VariableFieldNames[j], 12);
                 string fN2   = getValue(VariableFieldNames[k], 12);
                 double mD    = mns[sCnt];
                 double se    = ses[sCnt];
                 double tStat = mD / se;
                 //Console.WriteLine(tStat.ToString());
                 Accord.Statistics.Distributions.Univariate.TDistribution tDist = new Accord.Statistics.Distributions.Univariate.TDistribution(nSample - 1);
                 double cdf    = tDist.DistributionFunction(tStat);
                 double pValue = 0;
                 if (tStat > 0)
                 {
                     pValue = (1 - cdf) * 2;
                 }
                 else
                 {
                     pValue = (cdf * 2);
                 }
                 string pValueS = pValue.ToString();
                 if (pValue < 0.0001)
                 {
                     pValueS = pValueS = "p < 0.0001";
                 }
                 string ln = l + "|" + fN1 + "-" + fN2 + "| " + getValue(nSample.ToString(), 6) + " | " + getValue(mD.ToString(), 6) + " | " + getValue(tStat.ToString(), 6) + " | " + getValue(pValueS, 10);
                 rd.addMessage(ln);
                 sCnt += 1;
             }
             cnt += 1;
         }
     }
     rd.addMessage("-".PadRight(83, '-'));
     rd.enableClose();
     rd.Show();
 }
 public static void PairedTTestPValues(double[] popMeans, double[,] popVarCov, double[] sampMeans, double[,] sampVarCov, out double meanPvalue, out double varPvalue)
 {
     double n = popMeans.Length;
     meanPvalue = 0;
     varPvalue = 0;
     double sumM = 0;
     double sumV = 0;
     double sumM2 = 0;
     double sumV2 = 0;
     for (int i = 0; i < n; i++)
     {
         double m1 = popMeans[i];
         double m2 = sampMeans[i];
         double dm = m1 - m2;
         double v1 = popVarCov[i, i];
         double v2 = sampVarCov[i, i];
         double dv = v1 - v2;
         sumM += dm;
         sumV += dv;
         sumM2 += dm * dm;
         sumV2 += dv * dv;
     }
     double mM = sumM / n;
     double mV = sumV / n;
     double seM = Math.Sqrt((sumM2 - ((sumM * sumM) / n)) / n) / Math.Sqrt(n);
     double seV = Math.Sqrt((sumV2 - ((sumV * sumV) / n)) / n) / Math.Sqrt(n);
     double mTstat = mM / seM;
     double vTstat = mV / seV;
     Accord.Statistics.Distributions.Univariate.TDistribution tDist = new Accord.Statistics.Distributions.Univariate.TDistribution(n - 1);
     double mCdf = tDist.DistributionFunction(mTstat);
     double vCdf = tDist.DistributionFunction(vTstat);
     if (mTstat > 0)
     {
         meanPvalue = (1 - mCdf) * 2;
     }
     else
     {
         meanPvalue = mCdf * 2;
     }
     if (vTstat > 0)
     {
         varPvalue = (1 - vCdf) * 2;
     }
     else
     {
         varPvalue = vCdf * 2;
     }
 }
Exemple #10
0
        public void getReport()
        {
            if (kmeans == null)
            {
                buildModel();
            }
            rd                    = new Forms.RunningProcess.frmRunningProcessDialog(false);
            rd.Text               = "Independent T-Test Results";
            rd.TopLevel           = true;
            rd.pgbProcess.Visible = false;
            rd.FormBorderStyle    = System.Windows.Forms.FormBorderStyle.Sizable;
            rd.addMessage("Input path = " + InPath);
            rd.addMessage("Total Sample size = " + n.ToString());
            rd.addMessage("\nLabel   |Compare V1-V2            |N       |Dif     |T-Stat  |P-Value ");
            rd.addMessage("-".PadRight(83, '-'));
            KMeansClusterCollection gCol = kmeans.Clusters;

            for (int i = 0; i < gCol.Count; i++)
            {
                string        l       = getValue(Labels[i], 8);
                KMeansCluster gClust  = gCol[i];
                double[]      mns     = gClust.Mean;
                double[]      var     = new double[mns.Length];
                double        nSample = gClust.Proportion * N;
                if (nSample <= 1)
                {
                    continue;
                }
                double seAdjust = Math.Sqrt(2 * 1 / nSample);
                for (int j = 0; j < mns.Length; j++)
                {
                    var[j] = gClust.Covariance[j, j];
                }
                int cnt = 1;
                for (int j = 0; j < mns.Length - 1; j++)
                {
                    for (int k = cnt; k < mns.Length; k++)
                    {
                        string fN1   = getValue(VariableFieldNames[j], 12);
                        string fN2   = getValue(VariableFieldNames[k], 12);
                        double mD    = mns[j] - mns[k];
                        double pSD   = Math.Sqrt((var[j] + var[k]) / 2);
                        double se    = pSD * seAdjust;
                        double tStat = mD / se;
                        Accord.Statistics.Distributions.Univariate.TDistribution tDist = new Accord.Statistics.Distributions.Univariate.TDistribution(2 * nSample - 2);
                        double cdf    = tDist.DistributionFunction(tStat);
                        double pValue = 0;
                        if (tStat > 0)
                        {
                            pValue = (1 - cdf) * 2;
                        }
                        else
                        {
                            pValue = (cdf * 2);
                        }
                        string pValueS = pValue.ToString();
                        if (pValue < 0.0001)
                        {
                            pValueS = "p < 0.0001";
                        }
                        string ln = l + "|" + fN1 + "-" + fN2 + "| " + getValue(nSample.ToString(), 6) + " | " + getValue(mD.ToString(), 6) + " | " + getValue(tStat.ToString(), 6) + " | " + getValue(pValueS, 10);
                        rd.addMessage(ln);
                    }
                    cnt += 1;
                }
            }
            rd.addMessage("-".PadRight(83, '-'));
            rd.enableClose();
            rd.Show();
        }