Session Ready
Exercise

Code a simple one-variable regression

For the first coding exercise, you'll create a formula to define a one-variable modeling task, and then fit a linear model to the data. You are given the rates of male and female unemployment in the United States over several years (Source).

The task is to predict the rate of female unemployment from the observed rate of male unemployment. The outcome is female_unemployment, and the input is male_unemployment.

The sign of the variable coefficient tells you whether the outcome increases (+) or decreases (-) as the variable increases.

Recall the calling interface for lm() is:

lm(formula, data = ___)

Instructions
100 XP

The data frame unemployment is in your workspace.

  • Define a formula that expresses female_unemployment as a function of male_unemployment. Assign the formula to the variable fmla and print it.
  • Then use lm() and fmla to fit a linear model to predict female unemployment from male unemployment using the data set unemployment.
  • Print the model. Is the coefficent for male unemployment consistent with what you would expect? Does female unemployment increase as male unemployment does?