public double GetSignificance()
        {
            if (this.n < 3L)
            {
                return(Double.NaN);
            }
            TDistribution distribution = new TDistribution(this.n - 2L);

            return(2.0D * (1.0D - distribution.cumulativeProbability(Math.Abs(GetSlope()) / GetSlopeStdErr())));
        }
        private LeastSquaresRegressionResult getResultWithStatistics(double[][] x, double[] y, double[] betas, double[] yModel, DoubleMatrix transpose, DoubleMatrix matrix, bool useIntercept)
        {
            double yMean = 0.0;

            foreach (double y1 in y)
            {
                yMean += y1;
            }
            yMean /= y.Length;
            double totalSumOfSquares = 0.0;
            double errorSumOfSquares = 0.0;
            int    n = x.Length;
            int    k = betas.Length;

            double[] residuals     = new double[n];
            double[] stdErrorBetas = new double[k];
            double[] tStats        = new double[k];
            double[] pValues       = new double[k];
            for (int i = 0; i < n; i++)
            {
                totalSumOfSquares += (y[i] - yMean) * (y[i] - yMean);
                residuals[i]       = y[i] - yModel[i];
                errorSumOfSquares += residuals[i] * residuals[i];
            }
            double regressionSumOfSquares = totalSumOfSquares - errorSumOfSquares;

            double[][]    covarianceBetas  = convertArray(_algebra.getInverse(_algebra.multiply(transpose, matrix)).toArray());
            double        rSquared         = regressionSumOfSquares / totalSumOfSquares;
            double        adjustedRSquared = 1.0 - (1 - rSquared) * (n - 1.0) / (n - k);
            double        meanSquareError  = errorSumOfSquares / (n - k);
            TDistribution studentT         = new TDistribution(n - k);

            for (int i = 0; i < k; i++)
            {
                stdErrorBetas[i] = Math.Sqrt(meanSquareError * covarianceBetas[i][i]);
                tStats[i]        = betas[i] / stdErrorBetas[i];
                pValues[i]       = 1 - studentT.cumulativeProbability(Math.Abs(tStats[i]));
            }
            return(new LeastSquaresRegressionResult(betas, residuals, meanSquareError, stdErrorBetas, rSquared, adjustedRSquared, tStats, pValues, useIntercept));
        }
        public RealMatrix GetCorrelationPValues()
        {
            TDistribution tDistribution = new TDistribution(this.nObs - 2);
            int           nVars         = this.correlationMatrix.getColumnDimension();

            double[][] outVar = new double[nVars][];
            for (int i = 0; i < nVars; i++)
            {
                for (int j = 0; j < nVars; j++)
                {
                    if (i == j)
                    {
                        outVar[i][j] = 0.0D;
                    }
                    else
                    {
                        double r = this.correlationMatrix.getEntry(i, j);
                        double t = Math.Abs(r * Math.Sqrt((this.nObs - 2) / (1.0D - r * r)));
                        outVar[i][j] = (2.0D * tDistribution.cumulativeProbability(-t));
                    }
                }
            }
            return(new BlockRealMatrix(outVar));
        }