Problem Set 6
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
- Read the data and save it as
ironman. Useglimpse()to inspect the variables.
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.
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
Fit a linear model with run time as the response and bike time as the predictor. Save it as
bike_modeland display its coefficients.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.
Add the model’s fitted values and residuals to
ironman. Save them asbike_fittedandbike_residual.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.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
Calculate the model’s and training RMSE. Interpret each value. RMSE is measured in minutes because run time is measured in minutes.
Create a tibble called
new_bike_timescontaining bike times of 300, 360, and 420 minutes. Usepredict()withnewdatato add each fitted run time.
Compare Two Predictors
Fit a second model with run time as the response and swim time as the predictor. Add its fitted values and residuals to
ironman.Create a table containing the and training RMSE for both models. Which predictor has the stronger linear relationship with run time? Support your answer with both measures.
Reshape
model_comparisoninto a long table with one row for each model and measure. Plot the values in two side-by-side panels. Since 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 and RMSE, use
newdata, and compare two models.