private void Prognoz() { var transpMatrix = MatrixFunction.TransposeMatrix(dataMatrix); int parametersCount = dataMatrix[0].Length, measuresCount = dataMatrix.Length; double[] resultParameter = transpMatrix[resultParameterNumber]; List <double>[] withoutResultParameter = new List <double> [measuresCount]; for (int i = 0; i < measuresCount; i++) { withoutResultParameter[i] = new List <double>(); withoutResultParameter[i].Add(1); for (int j = 0; j < parametersCount; ++j) { if (j != resultParameterNumber) { withoutResultParameter[i].Add(dataMatrix[i][j]); } } } var xMatrix = withoutResultParameter.Select(o => o.ToArray()).ToArray(); var transpWithoutMatrix = MatrixFunction.TransposeMatrix(xMatrix); RegressionAnalysis ra = new RegressionAnalysis(dataMatrix, resultParameterNumber); var result = ra.RegressionCoefficients; double s = ra.ResidualDispersion; double t = 4.587; double[] a = new double[2]; a[0] = MatrixFunction.ScalarProductOfVectors(x0, result) - t * s * Math.Sqrt(MatrixFunction.ScalarProductOfVectors(MatrixFunction.TransposeMatrixVectorProduct(x0, MatrixFunction.InverseMatrix(MatrixFunction.MultiplicateMatrix(transpWithoutMatrix, xMatrix))), x0)); a[1] = MatrixFunction.ScalarProductOfVectors(x0, result) + t * s * Math.Sqrt(MatrixFunction.ScalarProductOfVectors(MatrixFunction.TransposeMatrixVectorProduct(x0, MatrixFunction.InverseMatrix(MatrixFunction.MultiplicateMatrix(transpWithoutMatrix, xMatrix))), x0)); Value = a; }
private void CalcRegressionCoefficients() { var transpMatrix = MatrixFunction.TransposeMatrix(dataMatrix); int parametersCount = dataMatrix[0].Length, measuresCount = dataMatrix.Length; double[] resultParameter = transpMatrix[resultParameterNumber]; List <double>[] withoutResultParameter = new List <double> [measuresCount]; for (int i = 0; i < measuresCount; i++) { withoutResultParameter[i] = new List <double>(); withoutResultParameter[i].Add(1); for (int j = 0; j < parametersCount; ++j) { if (j != resultParameterNumber) { withoutResultParameter[i].Add(dataMatrix[i][j]); } } } xMatrix = withoutResultParameter.Select(o => o.ToArray()).ToArray(); var transpWithoutMatrix = MatrixFunction.TransposeMatrix(xMatrix); RegressionCoefficients = MatrixFunction.MatrixVectorMultiplication(MatrixFunction.MultiplicateMatrix(MatrixFunction.InverseMatrix(MatrixFunction.MultiplicateMatrix(transpWithoutMatrix, xMatrix)), transpWithoutMatrix), resultParameter); RegressionCoefficients = RegressionCoefficients.Take(parametersCount).ToArray(); }
private void CalcDispersion() { var yWithWave = MatrixFunction.MatrixVectorMultiplication(xMatrix, RegressionCoefficients); var averageY = yWithWave.Average(); var devivationsYSum = yWithWave.Select(y => Math.Pow(y - averageY, 2)).Sum(); ExplicatedDispersion = devivationsYSum / parametersCount; ResidualDispersion = devivationsYSum / (measuresCount - parametersCount - 1); }
private void CalcElasticityCoefficients() { double[] result = new double[dataMatrix.Length]; var tm = MatrixFunction.TransposeMatrix(dataMatrix); double y = tm[tm.Length - 1].Average(); result[tm.Length - 1] = RegressionCoefficients[tm.Length - 1]; for (int i = 0; i < tm.Length - 1; ++i) { result[i] = RegressionCoefficients[i] * tm[i].Average() / y; } ElasticityCoefficients = result; }
private void CalcRegressionCoefficientsSignificance() { double[] sb = new double[parametersCount]; var temperory = MatrixFunction.InverseMatrix(MatrixFunction.MultiplicateMatrix(MatrixFunction.TransposeMatrix(xMatrix), xMatrix)); for (int j = 0; j < parametersCount; j++) { sb[j] = ResidualDispersion * temperory[j][j]; } RegressionCoefficientsSignificance = new double[parametersCount]; for (int i = 0; i < parametersCount; ++i) { RegressionCoefficientsSignificance[i] = RegressionCoefficients[i] / sb[i]; } }
private void CalcConfidenceIntervalsOfCoefficients() { double[] sb = new double[parametersCount]; var temperory = MatrixFunction.InverseMatrix(MatrixFunction.MultiplicateMatrix(MatrixFunction.TransposeMatrix(xMatrix), xMatrix)); for (int j = 0; j < parametersCount; j++) { sb[j] = ResidualDispersion * temperory[j][j]; } double t = 4.587; ConfidenceIntervalsOfCoefficients = new Tuple <double, double> [parametersCount]; for (int i = 0; i < parametersCount; ++i) { ConfidenceIntervalsOfCoefficients[i] = new Tuple <double, double>(RegressionCoefficients[i] - t * sb[i], RegressionCoefficients[i] + t * sb[i]); } }
private void CalcPartialCorrelationsMatrix() { int n = PairCorrelationsMatrix.Length; PartialCorrelationsMatrix = new double[n][]; for (int i = 0; i < n; i++) { PartialCorrelationsMatrix[i] = new double[n]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { PartialCorrelationsMatrix[i][j] = MatrixFunction.AlgebraicComplement(PairCorrelationsMatrix, i, j) / Math.Sqrt(MatrixFunction.AlgebraicComplement(PairCorrelationsMatrix, i, i) * MatrixFunction.AlgebraicComplement(PairCorrelationsMatrix, j, j)); } } }
private void CalcPairCorrelationsMatrix() { var squaredDevivations = CalcSquaredDevivatiosForAllCofficients(dataMatrix); var devivations = CalcDevivatiosForAllCofficients(dataMatrix); int coefCount = dataMatrix.Length; int measurementsCount = dataMatrix[0].Length; PairCorrelationsMatrix = new double[coefCount][]; for (int k = 0; k < coefCount; k++) { PairCorrelationsMatrix[k] = new double[coefCount]; } for (int i = 0; i < coefCount; ++i) { for (int j = i; j < coefCount; ++j) { if (i == j) { PairCorrelationsMatrix[i][j] = 1; } else { var xDevivations = devivations[i]; var yDevivations = devivations[j]; var xSquaredDevivation = squaredDevivations[i]; var ySquaredDevivation = squaredDevivations[j]; PairCorrelationsMatrix[i][j] = (MatrixFunction.ScalarProductOfVectors(xDevivations, yDevivations)) / (xSquaredDevivation * ySquaredDevivation * measurementsCount); PairCorrelationsMatrix[j][i] = PairCorrelationsMatrix[i][j]; } } } }
private void CalcSelectiveMultipleCoefficient(int resultParameterNumber) { SelectiveMultipleCoefficient = Math.Sqrt(1 - MatrixFunction.MatrixDeterminant(PairCorrelationsMatrix) / MatrixFunction.AlgebraicComplement(PairCorrelationsMatrix, resultParameterNumber, resultParameterNumber)); }