Beispiel #1
0
        public string CheckCorr(double alpha)
        {
            double tTheor = StatTables.GetStudInv(n - 2, alpha);
            string s      = string.Format("Уровень значимости: α = {0}<br>", alpha);

            s += string.Format("ПРОВЕРКА ЗНАЧИМОСТИ КОЭФФИЦИЕНТОВ КОРРЕЛЯЦИИ<br>Теоретическое значение критерия Стьюдента: " +
                               "t<sub>теор</sub> = t(1-α,n-2) = t({0};{1}) = {2:g3}<table border = 1 cellspacing = 0>", 1 - alpha, n - 2, tTheor);
            string[,] matr = new string[p + 1, p + 1];
            for (int i = 0; i < matrR.GetLength(0); i++)
            {
                for (int j = 0; j < matrR.GetLength(1); j++)
                {
                    double sigma = (1 - matrR[i, j]) / Math.Sqrt(n - 1);
                    double t     = matrR[i, j] / sigma;
                    if (Math.Abs(t) > tTheor)
                    {
                        matr[i, j] = string.Format("|t<sub>набл</sub>| = {0:g3} > t<sub>теор</sub> => значим", Math.Abs(t));
                    }
                    else
                    {
                        matr[i, j] = string.Format("|t<sub>набл</sub>| = {0:g3} ≤ t<sub>теор</sub> => не значим", Math.Abs(t));
                    }
                }
            }
            List <string> l = new List <string>();

            l.Add(sY.name);
            foreach (Sample smp in arrSX)
            {
                l.Add(smp.name);
            }
            s += MatrixToHtml(matr, l.ToArray());
            return(s);
        }
Beispiel #2
0
        public string CheckNorm(double alpha, out double[] arrPNorm)
        {
            NormalDistribution ndist = new NormalDistribution(av, sigmaStd);
            double             step  = arrMid[1] - arrMid[0];

            arrPNorm    = new double[arrP.Length];
            arrPNorm[0] = ndist.CumulativeDistribution(arrMid[0] + step / 2);
            for (int i = 1; i < arrPNorm.Length - 1; i++)
            {
                arrPNorm[i] = ndist.CumulativeDistribution(arrMid[i] + step / 2) - arrPNorm[i - 1];
            }
            arrPNorm[arrPNorm.Length - 1] = 1 - arrPNorm[arrPNorm.Length - 2];
            double chi2 = 0;

            for (int i = 0; i < arrP.Length; i++)
            {
                chi2 += (arrP[i] - arrPNorm[i]) * (arrP[i] - arrPNorm[i]) / arrPNorm[i];
            }
            double chi2Theor = StatTables.GetChi2Inv(arrP.Length - 1 - 2, alpha);

            return(string.Format("Проверка нормальности распределения по критерию хи-квадрат Пирсона<br>Уровень значимости: α = {0}<br>" +
                                 "Наблюдаемое значение критерия: χ<sup>2</sup><sub>набл</sub> = {1:g3}<br>" +
                                 "Теоретическое значение: χ<sup>2</sup><sub>теор</sub> = χ<sup>2</sup>(n-3,1-α) = χ<sup>2</sup>({2};{3}) = {4:g3}<br>{5}",
                                 alpha, chi2, arrP.Length - 3, 1 - alpha, chi2Theor,
                                 chi2 < chi2Theor ? "χ<sup>2</sup><sub>набл</sub><χ<sup>2</sup><sub>теор</sub> => гипотеза о нормальности принимается" :
                                 "χ<sup>2</sup><sub>набл</sub>≥<χ<sup>2</sup><sub>теор</sub> => гипотеза о нормальности отвергается"));
        }
Beispiel #3
0
        public string CheckReg(double alpha)
        {
            string s = string.Format("Уровень значимости: α = {0}<br>", alpha);
            // знач. регр.
            double fishRegrTheor = StatTables.GetFishInv(n - 1, n - p - 1, alpha);
            double fishRegr      = sY.devStd / devRem;

            s += "ПРОВЕРКА ЗНАЧИМОСТИ УРАВНЕНИЯ РЕГРЕССИИ<br>";
            s += string.Format("Наблюдаемое значение критерия Фишера: F<sub>набл</sub> = {0:g3}<br>" +
                               "Теоретическое значение критерия Фишера: F<sub>теор</sub> = F(1-α,n-1,n-p-1) = F({1};{2};{3}) = {4:g3}<br>{5}<br>",
                               fishRegr, 1 - alpha, n - 1, n - p - 1, fishRegrTheor,
                               fishRegr > fishRegrTheor ? "F<sub>набл</sub> > F<sub>теор</sub> => уравнение регрессии значимо" :
                               "F<sub>набл</sub> ≤ F<sub>теор</sub> => уравнение регрессии не значимо");

            // знач. коэф. ур. регр.
            s += "ПРОВЕРКА ЗНАЧИМОСТИ КОЭФФИЦИЕНТОВ УРАВНЕНИЯ РЕГРЕССИИ<br>";
            double studBTheor = StatTables.GetStudInv(n - p - 1, alpha);

            double[] arrSigmaB = new double[p + 1], arrStudB = new double[p + 1], arrBMin = new double[p + 1], arrBMax = new double[p + 1];
            s += string.Format("Теоретическое значение критерия Стьюдента: t<sub>теор</sub> = {0:g3}<br>", studBTheor);
            for (int i = 0; i < arrSigmaB.Length; i++)
            {
                arrSigmaB[i] = Math.Sqrt(devRem * matrCInv[i, i]);
                arrStudB[i]  = arrB[i] / arrSigmaB[i];
                arrBMin[i]   = arrB[i] - studBTheor * arrSigmaB[i];
                arrBMax[i]   = arrB[i] + studBTheor * arrSigmaB[i];
                s           += string.Format("Коэффициент b<sub>{0}</sub> ({1}): наблюдаемое значение критерия Стьюдента t<sub>набл</sub> = " +
                                             "{2:g3}; {3}; доверительный интервал: [{4:g3}, {5:g3}]<br>",
                                             i, i > 0 ? arrSX[i - 1].name : "свободный член", arrStudB[i],
                                             Math.Abs(arrStudB[i]) > studBTheor ? "|t<sub>набл</sub>| > t<sub>теор</sub> => коэффициент значим" :
                                             "|t<sub>набл</sub>| ≤ t<sub>теор</sub> => коэффициент не значим", arrBMin[i], arrBMax[i]);
            }

            // знач. множ. коэф. кор.
            s += "ПРОВЕРКА ЗНАЧИМОСТИ МНОЖЕСТВЕННОГО КОЭФФИЦИЕНТА КОРРЕЛЯЦИИ<br>";
            double sigmaR = (1 - R * R) / Math.Sqrt(n - p - 1), fishR = R * R * (n - p - 1) / (1 - R * R) * p, studR = R / sigmaR;
            double studRTheor = StatTables.GetStudInv(n - p - 1, alpha);
            double fishRTheor = StatTables.GetFishInv(n - p - 1, p, alpha);

            s += string.Format("Множественный коэффициент корреляции: R = {0:g3}<br>Наблюдаемое значение критерия Стьюдента: " +
                               "t<sub>набл</sub> = {1:g3}<br>Теоретическое значение критерия Стьюдента: " +
                               "t<sub>теор</sub> = t(1-α;n-p-1) = t({2};{3}) = {4:g3}<br>{5}<br>" +
                               "Наблюдаемое значение критерия Фишера: F<sub>набл</sub> = {6:g3}<br>" +
                               "Теоретическое значение критерия Фишера: F<sub>теор</sub> = F(1-α;n-p-1;p) = F({7};{8};{9}) = {10:g3}<br>{11}<br>",
                               R, studR, 1 - alpha, n - p - 1, studRTheor, Math.Abs(studR) > studRTheor ? "|t<sub>набл</sub>| > t<sub>теор</sub> => коэффициент значим" :
                               "|t<sub>набл</sub>| ≤ t<sub>теор</sub> => коэффициент не значим", fishR, 1 - alpha, n - p - 1, p, fishRTheor,
                               fishR > fishRTheor ? "F<sub>набл</sub> > F<sub>теор</sub> => коэффициент значим" :
                               "F<sub>набл</sub> ≤ F<sub>теор</sub> => коэффициент не значим");
            return(s);
        }
Beispiel #4
0
        public void CheckHypothesises(double alpha)
        {
            // знач. регр.
            fishRegrTheor = StatTables.GetFishDistrInv(n - 1, n - p - 1, alpha);
            if (fishRegr > fishRegrTheor)
            {
                isRegrRepr = true;
            }
            else
            {
                isRegrRepr = false;
            }

            // знач. коэф. регр.
            studBTheor = StatTables.GetStudDistrInv(n - p - 1, alpha);
            arrIsBRepr = new bool[p + 1];
            for (int i = 0; i < arrIsBRepr.Length; i++)
            {
                if (arrStudB[i] > studBTheor)
                {
                    arrIsBRepr[i] = true;
                }
                else
                {
                    arrIsBRepr[i] = false;
                }
            }

            // знач. коэф. кор.
            studRxyTheor = StatTables.GetStudDistrInv(n - 2, alpha);
            arrIsRxyRepr = new bool[p];
            for (int i = 0; i < arrIsRxyRepr.Length; i++)
            {
                if (arrStudRxy[i] > studRxyTheor)
                {
                    arrIsRxyRepr[i] = true;
                }
                else
                {
                    arrIsRxyRepr[i] = false;
                }
            }

            // знач. множ. коэф. кор.
            studRTheor = StatTables.GetStudDistrInv(n - p - 1, alpha);
            if (studR > studRTheor)
            {
                isRReprStud = true;
            }
            else
            {
                isRReprStud = false;
            }

            fishRTheor = StatTables.GetFishDistrInv(n - p - 1, p, alpha);
            if (fishR > fishRTheor)
            {
                isRReprFish = true;
            }
            else
            {
                isRReprFish = false;
            }
        }
Beispiel #5
0
        public int[] DropoutErrorsStud(double alphaMin, double alphaMax)
        {
            if (alphaMin == -1)
            {
                alphaMin = 0.001f;
            }
            if (alphaMax == -1)
            {
                alphaMax = 0.05f;
            }
            ArrayList listX           = new ArrayList(arrX);
            ArrayList listIndexIgnore = new ArrayList();

            while (true)
            {
                double min = double.MaxValue, max = double.MinValue;
                double sum = 0, sumXPow2 = 0;
                int    indexMin = -1, indexMax = -1;
                for (int i = 0; i < listX.Count; i++)
                {
                    if (listIndexIgnore.BinarySearch(i) >= 0)
                    {
                        continue;
                    }
                    double x = (double)listX[i];
                    if (x < min)
                    {
                        min      = x;
                        indexMin = i;
                    }
                    if (x > max)
                    {
                        max      = x;
                        indexMax = i;
                    }
                    sum      += x;
                    sumXPow2 += x * x;
                }
                int    n = listX.Count - listIndexIgnore.Count;
                double average = sum / n;
                double devStd = sumXPow2 / (n - 1) - (sum / (n - 1)) * (sum / (n - 1));
                double sigmaStd = (double)Math.Sqrt(devStd);
                double tauXMin, tauXMax;
                tauXMin = (double)Math.Abs(min - average) / sigmaStd;
                tauXMax = (double)Math.Abs(max - average) / sigmaStd;
                int    index;
                double tauMax;
                if (tauXMin >= tauXMax)
                {
                    index  = indexMin;
                    tauMax = tauXMin;
                }
                else
                {
                    index  = indexMax;
                    tauMax = tauXMax;
                }

                double tMin    = StatTables.GetStudDistrInv(listX.Count - 2, alphaMin);
                double tMax    = StatTables.GetStudDistrInv(listX.Count - 2, alphaMax);
                double critMin = tMin * (double)Math.Sqrt(listX.Count - 1) /
                                 (double)Math.Sqrt(listX.Count - 2 + tMin * tMin);
                double critMax = tMax * (double)Math.Sqrt(listX.Count - 1) /
                                 (double)Math.Sqrt(listX.Count - 2 + tMin * tMin);
                if (tauMax > critMin)
                {
                    listIndexIgnore.Add(index);
                    listIndexIgnore.Sort();
                }
                else
                {
                    break;
                }
            }
            return((int[])listIndexIgnore.ToArray(typeof(int)));
        }
Beispiel #6
0
        public int[] DropoutErrors(double alpha, out string rep)
        {
            rep = string.Format("ОТСЕВ ПОГРЕШНОСТЕЙ ДЛЯ {0}<br>Уровень значимости: α = {1}<table border = 1 cellspacing = 0>" +
                                "<tr><td>№ наблюдения<td>Значение<td>τ<sub>набл</sub><td>τ<sub>теор</sub>", name, alpha);
            List <int> lIgnore = new List <int>(), lI = new List <int>();

            for (int i = 0; i < arr.Length; i++)
            {
                lI.Add(i);
            }
            while (true)
            {
                double min = double.MaxValue, max = double.MinValue;
                double sum = 0, sum2 = 0;
                int    iMin = -1, iMax = -1;
                foreach (int i in lI)
                {
                    if (arr[i] < min)
                    {
                        min  = arr[i];
                        iMin = i;
                    }
                    if (arr[i] > max)
                    {
                        max  = arr[i];
                        iMax = i;
                    }
                    sum  += arr[i];
                    sum2 += arr[i] * arr[i];
                }
                int    n = lI.Count;
                double average = sum / n;
                double devStd = (sum2 / n - (sum / n) * (sum / n)) * n / (n - 1);
                double sigmaStd = (double)Math.Sqrt(devStd);
                double tauXMin, tauXMax;
                tauXMin = Math.Abs(min - average) / sigmaStd;
                tauXMax = Math.Abs(max - average) / sigmaStd;
                int    index;
                double tauMax;
                if (tauXMin >= tauXMax)
                {
                    index  = iMin;
                    tauMax = tauXMin;
                }
                else
                {
                    index  = iMax;
                    tauMax = tauXMax;
                }
                double tauCrit;
                if (n <= 25)
                {
                    tauCrit = StatTables.GetTau(1 - alpha, n);
                }
                else
                {
                    double t = StatTables.GetStudInv(n - 2, alpha);
                    tauCrit = t * Math.Sqrt(n - 1) / Math.Sqrt(n - 2 + t * t);
                }
                if (tauMax > tauCrit)
                {
                    rep += string.Format("<tr><td>{0}<td>{1:g5}<td>{2:g3}<td>{3:g3}{4}", index, arr[index], tauMax, tauCrit,
                                         n <= 25 ? "" : "(исп. t(α,n-2))");
                    int pos = lIgnore.BinarySearch(index);
                    lIgnore.Insert(~pos, index);
                    pos = lI.BinarySearch(index);
                    lI.RemoveAt(pos);
                }
                else
                {
                    break;
                }
            }
            return(lIgnore.ToArray());
        }
Beispiel #7
0
        public int[] DropoutErrorsStud(double alphaMin, double alphaMax, out string[] arrReason)
        {
            if (alphaMin == -1)
            {
                alphaMin = 0.001f;
            }
            if (alphaMax == -1)
            {
                alphaMax = 0.05f;
            }
            ArrayList     listX           = new ArrayList(arrX);
            ArrayList     listIndexIgnore = new ArrayList();
            List <string> listReason      = new List <string>();

            while (true)
            {
                double min = double.MaxValue, max = double.MinValue;
                double sum = 0, sumXPow2 = 0;
                int    indexMin = -1, indexMax = -1;
                for (int i = 0; i < listX.Count; i++)
                {
                    if (listIndexIgnore.BinarySearch(i) >= 0)
                    {
                        continue;
                    }
                    double x = (double)listX[i];
                    if (x < min)
                    {
                        min      = x;
                        indexMin = i;
                    }
                    if (x > max)
                    {
                        max      = x;
                        indexMax = i;
                    }
                    sum      += x;
                    sumXPow2 += x * x;
                }
                int    n = listX.Count - listIndexIgnore.Count;
                double average = sum / n;
                double devStd = sumXPow2 / (n - 1) - (sum / (n - 1)) * (sum / (n - 1));
                double sigmaStd = (double)Math.Sqrt(devStd);
                double tauXMin, tauXMax;
                tauXMin = (double)Math.Abs(min - average) / sigmaStd;
                tauXMax = (double)Math.Abs(max - average) / sigmaStd;
                int    index;
                double tauMax;
                if (tauXMin >= tauXMax)
                {
                    index  = indexMin;
                    tauMax = tauXMin;
                }
                else
                {
                    index  = indexMax;
                    tauMax = tauXMax;
                }

                double tMin    = StatTables.GetStudDistrInv(listX.Count - 2, alphaMin);
                double tMax    = StatTables.GetStudDistrInv(listX.Count - 2, alphaMax);
                double critMin = tMin * (double)Math.Sqrt(listX.Count - 1) /
                                 (double)Math.Sqrt(listX.Count - 2 + tMin * tMin);
                double critMax = tMax * (double)Math.Sqrt(listX.Count - 1) /
                                 (double)Math.Sqrt(listX.Count - 2 + tMin * tMin);
                if (tauMax > critMin)
                {
                    int i = listIndexIgnore.BinarySearch(index);
                    listIndexIgnore.Insert(~i, index);
                    listReason.Insert(~i, string.Format("Для {0}: tau<SUB>max</SUB> = {1} > {2}",
                                                        Math.Round(arrX[index], 3), Math.Round(tauMax, 3),
                                                        Math.Round(critMin, 3)));
                }
                else
                {
                    break;
                }
            }
            arrReason = listReason.ToArray();
            return((int[])listIndexIgnore.ToArray(typeof(int)));
        }