# linear regression degrees of freedom [duplicate]

Via trial and error where I guess the number of statistical degrees of freedom, I have determined that the single variable linear regression "automatically" performed by Excel provides a p-value for the Y-axis-intercept that is identical to the one that can be calculated by "explicit" Excel functions as follows:

2*T.DIST(0-t,n-2,TRUE)

(The p-value is for the null hypothesis that the Y-axis-intercept is zero.)

Here T.DIST is the function name and it is left tailed, hence the need to flip the sign on the t-statistic. This flip operation is visible as the 0-, or "zero minus".

Here t is the t-statistic.

Here n is the number of observations.

Here TRUE means the function operates in cumulative mode.

The second argument to the function is the statistical degrees of freedom. I guessed that the value would be n-1 which was wrong and then I guessed it would be n-2. Why should the statistical degrees of freedom be 2 less than the number of observations?

In general, this should be $n-p$ degrees of freedom, where $p$ is number of parameters in linear regression equation.