Exercise

# Rules for counting

In this exercise, you'll work with the "rules" for counting degrees of freedom. You don't need to memorize these, but they will help you out from time to time.

- A dataset with \(n\) cases has \(n\) degrees of freedom.
- The explanatory side of a model formula has a number of degrees of freedom that depends on the terms in the formula. Start counting at 1; every model has at least 1 degree of freedom even if there are no explanatory variables.
- A single variable has 1 degree of freedom if it is quantitative. If it is categorical with \(k\) different levels, it has \(k-1\) degrees of freedom.
- If variables are connected with
`+`

, add together their individual degrees of freedom. - If variables are connected with
`*`

, add together their individual degrees of freedom and then add in the product of their individual degrees of freedom. - There are special rules that apply in some special circumstances, but you don't need to worry about those here.

- The difference between the degrees of freedom of the dataset and the degrees of freedom of the model formula is called the
*residual degrees of freedom*. Models with zero residual degrees of freedom are not generally at all useful. Models with a handful of residual degrees of freedom have statistical properties that are not reliable.

How many degrees of freedom are in the formula for this model?

```
lm(wage ~ age + sector + sex + married * exper,
data = CPS85)
```

Tip: You can use `table()`

or `length(unique(___))`

to figure out the degrees of freedom in the `sex`

and `married`

variables.

Instructions

**50 XP**

##### Possible Answers

- 6 degrees of freedom because there are five explanatory variables and you add one to that.
- 17 degrees of freedom. 1 degree of freedom (as has every model) plus 1 for
`age`

which is quantitative, then 2 for`sex`

and 8 for`sector`

and then, for`married * experience`

, 2 plus 1 plus (2 times 1), since`married`

has two levels and`experience`

(which is quantitative) counts for 1. Altogether, 1 + 1 + 2 + 8 + 2 + 1 + 2 gives 17 degrees of freedom. - 13 degrees of freedom. 1 degree of freedom (as has every model) plus 1 for
`age`

plus 7 for`sector`

plus 1 for`sex`

plus 1 for`married`

plus 1 for`exper`

plus 1 * 1 for the interaction between`married`

and`exper`

. Altogether 1 + 1 + 7 + 1 + 1 + 1 + 1 gives 13 degrees of freedom.