コード例 #1
0
        void CalculateValues()
        {
            #region Values Assigning
            Xi_squared                = new double[lines - 1];
            XiYi                      = new double[lines - 1];
            Xi_m_Xavg_x_Yi_m_YAvg     = new double[lines - 1];
            Xi_m_X_Avg_Squared        = new double[lines - 1];
            Yi_m_Y_Avg_Squared        = new double[lines - 1];
            Y_lineal                  = new double[lines - 1];
            Yi_m_Lineal_Yi_Squared    = new double[lines - 1];
            Lineal_Yi_m_Y_Avg_Squared = new double[lines - 1];
            #endregion

            for (int i = 0; i < lines - 1; i++)
            {
                Xi_squared[i] = Pow(Xi[i], 2);
                XiYi[i]       = Xi[i] * Yi[i];

                SUM_X          += Xi[i];
                SUM_Y          += Yi[i];
                SUM_Xi_squared += Xi_squared[i];
                SUM_XiYi       += XiYi[i];
            }
            Avg_X = SUM_X / (lines - 1);
            Avg_Y = SUM_Y / (lines - 1);

            B1 = ((lines - 1) * SUM_XiYi - SUM_X * SUM_Y) / ((lines - 1) * SUM_Xi_squared - Pow(SUM_X, 2));
            B0 = SUM_Y / (lines - 1) - B1 * SUM_X / (lines - 1);

            for (int i = 0; i < lines - 1; i++)
            {
                Xi_m_Xavg_x_Yi_m_YAvg[i] = (Xi[i] - Avg_X) * (Yi[i] - Avg_Y);
                Xi_m_X_Avg_Squared[i]    = Pow(Xi[i] - Avg_X, 2);
                Yi_m_Y_Avg_Squared[i]    = Pow(Yi[i] - Avg_Y, 2);
                Y_lineal[i] = B0 + B1 * Xi[i];
                Yi_m_Lineal_Yi_Squared[i]    = Pow(Yi[i] - Y_lineal[i], 2);
                Lineal_Yi_m_Y_Avg_Squared[i] = Pow(Y_lineal[i] - Avg_Y, 2);

                SUM_Xi_m_Xavg_x_Yi_m_YAvg += Xi_m_Xavg_x_Yi_m_YAvg[i];
                SUM_Xi_m_X_Avg_Squared    += Xi_m_X_Avg_Squared[i];
                SUM_Yi_m_Y_Avg_Squared    += Yi_m_Y_Avg_Squared[i];
                SUM_Y_lineal += Y_lineal[i];
                SUM_Yi_m_Lineal_Yi_Squared    += Yi_m_Lineal_Yi_Squared[i];
                SUM_Lineal_Yi_m_Y_Avg_Squared += Lineal_Yi_m_Y_Avg_Squared[i];
            }

            Determ_Coef   = SUM_Lineal_Yi_m_Y_Avg_Squared / SUM_Yi_m_Y_Avg_Squared;
            Indeterm_Coef = 1 - Determ_Coef;
            Corelation_P  = Sqrt(Determ_Coef);
            Corelation_B  = SUM_Xi_m_Xavg_x_Yi_m_YAvg / Sqrt(SUM_Xi_m_X_Avg_Squared * SUM_Yi_m_Y_Avg_Squared);
            Standard_dev  = Sqrt(SUM_Yi_m_Lineal_Yi_Squared / (lines - 3));
            Dispersion_1  = SUM_Lineal_Yi_m_Y_Avg_Squared;
            Dispersion_2  = SUM_Yi_m_Lineal_Yi_Squared / (lines - 3);
            F_em          = Dispersion_1 / Dispersion_2;
            F_t           = new double[2];
            F_t[0]        = FisherSnedecor.InvCDF(1, lines - 3, 0.95);
            F_t[1]        = (lines == 4) ? 4052 : FisherSnedecor.InvCDF(1, lines - 3, 0.99);

            SendToData();
        }
コード例 #2
0
        public void ValidateInverseCumulativeDistribution(double d1, double d2, double x)
        {
            var    n = new FisherSnedecor(d1, d2);
            double p = SpecialFunctions.BetaRegularized(d1 / 2.0, d2 / 2.0, d1 * x / (d2 + (x * d1)));

            Assert.That(n.InverseCumulativeDistribution(p), Is.EqualTo(x).Within(1e-8));
            Assert.That(FisherSnedecor.InvCDF(d1, d2, p), Is.EqualTo(x).Within(1e-8));
        }
コード例 #3
0
ファイル: ExcelFunctions.cs プロジェクト: AChE-p/Circulus
 public static double FInv(double probability, int degreesFreedom1, int degreesFreedom2)
 {
     return(FisherSnedecor.InvCDF(degreesFreedom1, degreesFreedom2, 1d - probability));
 }
コード例 #4
0
        public (double residualDispersion, double explainedDispersion, double fEmpirical, double fTheoretical, bool isModelAdecuate) CheckAdequacyOfModel()
        {
            //If the adjustedValues are correct continue with the analysis
            if (areAdjustedYValuesAlright == true)
            {
                double alpha = 0.05D;
                double numberOfEquationParameters = 2.0D;

                double explainedDeviation = this.GetExplainedDeviation();

                double residualDeviation = this.GetResidualDeviation();

                double explainedDisperssion = explainedDeviation / (numberOfEquationParameters - 1.0D);

                if (Double.IsNaN(explainedDisperssion) || Double.IsInfinity(explainedDisperssion))
                {
                    explainedDisperssion = 1;
                }

                double residualDisperssion = residualDeviation / (this.YValues.Count - numberOfEquationParameters);

                if (Double.IsNaN(residualDisperssion) || Double.IsInfinity(residualDisperssion))
                {
                    residualDisperssion = 1;
                }

                double FEmpirical = (explainedDisperssion >= residualDisperssion) ? (explainedDisperssion / residualDisperssion) : (residualDisperssion / explainedDisperssion);

                if (Double.IsNaN(FEmpirical) || Double.IsInfinity(FEmpirical))
                {
                    FEmpirical = 1;
                }

                double firstDegreeOfFreedom  = 0.0;
                double secondDegreeOfFreedom = 0.0;

                if (explainedDisperssion > residualDisperssion)
                {
                    firstDegreeOfFreedom  = (numberOfEquationParameters - 1);
                    secondDegreeOfFreedom = (this.Count - numberOfEquationParameters);
                }
                else if (residualDisperssion > explainedDisperssion)
                {
                    firstDegreeOfFreedom  = (this.Count - numberOfEquationParameters);
                    secondDegreeOfFreedom = (numberOfEquationParameters - 1);
                }
                else
                {
                    firstDegreeOfFreedom  = (numberOfEquationParameters - 1);
                    secondDegreeOfFreedom = (this.Count - numberOfEquationParameters);
                }

                if (firstDegreeOfFreedom <= 0)
                {
                    firstDegreeOfFreedom = 1;
                }

                if (secondDegreeOfFreedom <= 0)
                {
                    secondDegreeOfFreedom = 1;
                }


                FisherSnedecor fDistibution = new FisherSnedecor(1, 1);
                double         FTheoretical = FisherSnedecor.InvCDF(firstDegreeOfFreedom, secondDegreeOfFreedom, (1.00 - alpha));

                bool isModelAdequate = false;

                if (FEmpirical <= FTheoretical)
                {
                    isModelAdequate = false;
                }
                else if (FEmpirical > FTheoretical)
                {
                    isModelAdequate = true;
                }

                return(residualDisperssion, explainedDisperssion, FEmpirical, FTheoretical, isModelAdequate);
            }
            else
            {
                //Else return default values.
                return(0.0, 0.0, 0.0, 0.0, false);
            }
        }
コード例 #5
0
ファイル: Distribucije.cs プロジェクト: hgugic/Geodezija-2
 /// <summary>
 /// Inverzna Fisherova (F) distribucija (razdioba)
 /// </summary>
 /// <param name="alfa">Nivo signifikantnosti (znacajnosti) -> 1 > alfa > 0 </param>
 /// <param name="f1">Stupanj slobode</param>
 /// <param name="f2">Stupanj slobode (ako uvrstite veliki broj dvostruka Fisherova prelazi u Chi^2)</param>
 /// <returns>double</returns>
 public static double Fisher(double alfa, int f1, int f2)
 {
     return(FisherSnedecor.InvCDF(f1, f2, 1 - alfa));
 }