# Degrees of freedom for linear model without intercept and one independent variable

When I run a linear model having one independent variable with intercept in R, the degrees of freedom for model we get 1. When I run a model without intercept still the degrees of freedom remains 1. How is this possible? What is the split of degrees of freedom in with and without intercept model? For example see below:

################# Model 1 -With intercept #########
data(mtcars)
attach(mtcars)
Model1=lm(mpg~hp)
anova(Model1) #### degrees of freedom for regression 1

Analysis of Variance Table

Response: mpg
Df Sum Sq Mean Sq F value    Pr(>F)
hp         1 678.37  678.37   45.46 1.788e-07 ***
Residuals 30 447.67   14.92

################# Model 1 -Without intercept #########

data(mtcars)
attach(mtcars)
Model1=lm(mpg~hp-1) ### model without intercept
anova(Model1) #### degrees of freedom for regression again 1

Analysis of Variance Table

Response: mpg
Df Sum Sq Mean Sq F value    Pr(>F)
hp         1 8530.8  8530.8  47.982 9.062e-08 ***
Residuals 31 5511.5   177.8


My concern is, how come degrees of freedom for hp remain same in both models.

• Showing us precisely what your models are, either in R or mathematically, would doubtless help here. – Scortchi - Reinstate Monica Feb 22 '17 at 17:39
• The degrees of freedom are 30 and 31, respectively, not 1. The "1"s in the output merely count the number of parameters associated with the listed variables. – whuber Feb 22 '17 at 22:47

EDIT: The $df$ is associated with the sources of variance. The $mtcars$ dataset has $N=32$ obs. Generally, if you have $N$ obs, $p$ predictors, and the intercept, then, the $df$ for the residuals are $(N−p−1)$ because there are $(p+1)$ parameters to be estimated.
In the above models, $hp$ is the only predictor, $p=1$. The degrees of freedom, in (a) the model with intercept is $(32-1-1=30)$, and in (b) the model without the intercept is $(32-1=31)$.
In R, the $df$ for a continuous predictor is $1$. For any categorical predictor, say $C$, with $k$ categories, if you used $factor(C)$ in your model, then the $df$ for $C$ would be $k-1$.