CommencerCommencer gratuitement

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() (docs) is:

lm(formula, data = ___)

The unemployment data frame has been pre-loaded.

Cet exercice fait partie du cours

Supervised Learning in R: Regression

Afficher le cours

Instructions

  • 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 dataset unemployment.
  • Print the model. Is the coefficient for male unemployment consistent with what you would expect? Does female unemployment increase as male unemployment does?

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# unemployment is available
summary(unemployment)

# Define a formula to express female_unemployment as a function of male_unemployment
fmla <- ___

# Print it
___

# Use the formula to fit a model: unemployment_model
unemployment_model <- ___

# Print it
___
Modifier et exécuter le code