2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Showing us precisely what your models are, either in R or mathematically, would doubtless help here. $\endgroup$ – Scortchi - Reinstate Monica Feb 22 '17 at 17:39
  • 1
    $\begingroup$ 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. $\endgroup$ – whuber Feb 22 '17 at 22:47
6
$\begingroup$

The intercept is a correction to the model, whereas, your number of independent variables in the model have not changed across the two cases you've presented.

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$.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ How does this account for degrees of freedom? It seems you are arguing that the "30" and "31" shown in the two models must be the same value! $\endgroup$ – whuber Feb 22 '17 at 22:47
  • $\begingroup$ @whuber The edited response should help. $\endgroup$ – dangiankit Feb 22 '17 at 23:31
  • $\begingroup$ @Whuber: In Model II (The model without intercept), The degrees of freedom for TSS is coming exactly 32. Why we don't loose any degree, it should be (n-1), in case we have n observations in response variable, but we get exactly n degrees of freedom $\endgroup$ – Bilal Para Feb 23 '17 at 4:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.