Regression with Triathlon Data

The file ironman_florida_2017.csv contains results from the 2017 Ironman Florida race. Each row is one athlete. Swim, bike, run, and overall times are measured in minutes.

Explore the Relationship

  1. Read the data and save it as ironman. Use glimpse() to inspect the variables.
ironman <- read_csv("data/ironman_florida_2017.csv")
glimpse(ironman)
  1. Plot bike time on the horizontal axis and run time on the vertical axis. Use transparent points so that dense parts of the plot remain visible. Give both axes clear labels with units.

  2. Calculate the correlation between bike and run times. Describe the direction and strength of the linear relationship using the scatterplot and the correlation together.

Fit and Interpret a Model

  1. Fit a linear model with run time as the response and bike time as the predictor. Save it as bike_model and display its coefficients.

  2. Interpret the slope in minutes. The intercept corresponds to a bike time of zero minutes. Explain why that intercept is not meaningful for these data.

  3. Add the model’s fitted values and residuals to ironman. Save them as bike_fitted and bike_residual.

  4. Recreate the scatterplot from Question 2 and add the fitted line with geom_line(). Remember to arrange the rows by bike time before drawing the line.

  5. Plot the residuals against the fitted values. Add a horizontal line at zero. Does the residual plot reveal a clear curve, a changing spread, or unusual observations?

Measure Fit and Predict New Rows

  1. Calculate the model’s R2R^2 and training RMSE. Interpret each value. RMSE is measured in minutes because run time is measured in minutes.

  2. Create a tibble called new_bike_times containing bike times of 300, 360, and 420 minutes. Use predict() with newdata to add each fitted run time.

Compare Two Predictors

  1. Fit a second model with run time as the response and swim time as the predictor. Add its fitted values and residuals to ironman.

  2. Create a table containing the R2R^2 and training RMSE for both models. Which predictor has the stronger linear relationship with run time? Support your answer with both measures.

  3. Reshape model_comparison into a long table with one row for each model and measure. Plot the values in two side-by-side panels. Since R2R^2 and RMSE have different scales and units, give each panel its own vertical scale.

After this problem set, you should be able to fit and interpret a simple linear regression, calculate fitted values and residuals, assess fit with R2R^2 and RMSE, use newdata, and compare two models.