//Menghitung estimator spatial regresi dengan OLS
        public LeastSquareEstimator(Matrix X, Matrix W, Vector Y)
        {
            //this.x = X;
               this.w = W;
               this.y = Y;
               int n = X.Rows;
               // this.p = X.Cols;

               Matrix vector1 = new Matrix(n, 1);
               vector1.InitializeAllValue(1);

               x = new Matrix(X.Rows, vector1.Cols + X.Cols);
               x = x.GroupingCols(vector1, X);
               //this.p = x.Cols;

               wStandard = new Matrix(w.Rows, w.Cols);
               Matrix wTemp = new Matrix(w.Rows, w.Cols);
               wStandard = wTemp.Standardized(w);

               xstar = wStandard * X;

               //Penggabungan matriks x dan x* sebagai matrik x observasi
               xObs = new Matrix(x.Rows, x.Cols + xstar.Cols);
               xObs = xObs.GroupingCols(x, xstar);
               this.p = xObs.Cols;

               xObsTx = xObs.GetTranspose() * xObs;

               xObsTy = xObs.GetTranspose() * y;

               xObsTxInverse = xObsTx.GetInverse();

               estimator = xObsTxInverse * xObsTy;

               ycap = xObs * estimator;
               e = y - ycap;
               eSquare = e.GetDataSquare();

               eVariance = Vector.DoubleMultiply(e.GetTranspose(), e) / (n - p);
               double seReg = Math.Sqrt(eVariance);
               covEstimator = eVariance * xObsTxInverse;

               Matrix J = new Matrix(n, n);
               J.InitializeAllValue(1.0);

               double yty = Vector.DoubleMultiply(Y.GetTranspose(), Y);
               Vector jy = J * y;
               ssto = yty - Vector.DoubleMultiply(Y.GetTranspose(), jy) / n;
               //sse = yty - Vector.DoubleMultiply(estimator.GetTranspose(), xty);
               sse = Vector.DoubleMultiply(e.GetTranspose(), e);
               ssr = ssto - sse;

               msr = ssr / (p - 1);
               mse = sse / (n - p);
               rSquare = ssr / ssto;
               r = Math.Sqrt(rSquare);

               // Mendapatkan Nilai F pada uji Simultan
               fValue = msr / mse;

               // Mendapatkan Nilai PValue pada uji F Simultan
               Distribution.F fDist = new Distribution.F();
               fProb = fDist.PValue(fValue, p - 1, n - p);

               // Mendapatkan Nilai t untuk uji Parsial
               tTest = new Vector(estimator.Tuples);
               tTest = ParsialTest(estimator, covEstimator);

               //Mendapatkan Nilai pValue pada uji t Parsial
               tProb = new Vector(tTest.Tuples);
               tProb = PValueParsialTest(tTest, p);
        }
Пример #2
0
        // Mengecek apakah dua buah vektor perpendicular.
        // Dua buah vektor perpendicular jika hasil perkalian doublenya 0
        public static bool IsPerpendicular(Vector a, Vector b)
        {
            bool result;

            if (a.Type == VectorType.ColumnVector && b.Type == VectorType.ColumnVector)
            {
                Vector aT = a.GetTranspose();
                result = Vector.DoubleMultiply(aT, b) == 0.0;
            }
            else
            {
                throw new WrongVectorTypeException("Only Column Vector valid");
            }

            return result;
        }
Пример #3
0
        // Mendapatkan vektor proyeksi antara Vektor X dan Vektor Y
        public static Vector ProjectionXonY(Vector X, Vector Y)
        {
            Vector result;

            if (X.Type == VectorType.ColumnVector && Y.Type == VectorType.ColumnVector)
            {
                Vector XT = X.GetTranspose();
                double proj = Vector.DoubleMultiply(XT, Y) / (Math.Pow(Y.Length, 2));

                result = proj * Y;
            }
            else
            {
                throw new WrongVectorTypeException("Only Column Vector valid");
            }

            return result;
        }
Пример #4
0
        // Mendapatkan sudut (dalam radian) antara dua vektor
        public static double Angle(Vector a, Vector b)
        {
            double result;

            if (a.Type == VectorType.ColumnVector && b.Type == VectorType.ColumnVector)
            {
                Vector aT = a.GetTranspose();
                result = Vector.DoubleMultiply(aT, b);
                result /= a.Length * b.Length;
                result = Math.Acos(result);
            }
            else
            {
                throw new WrongVectorTypeException("Only Column Vector valid");
            }

            return result;
        }