STAT 1080 - Fall 2026
  • Course Info
    • Overview
    • Syllabus
    • Support
    • Schedule
    • Useful links
  • Weekly Materials
    • W1. Introduction
    • W2. RStudio
    • W3. Correlation
    • W4. Programming
    • W5. Tidyverse
    • W6. Dates/Times and Distributions
    • W7. Data Visualization
    • W8. Statistics & Probability
    • W9. Data & Probability
    • W10. Random Variables
    • W11. Parameters & Estimates
    • W12. Statistical Inference
    • W13. Regression
    • W14. Regression
    • W15. Project Meetings

On this page

  • 1 Problem
  • 2 Problem
  • 3 Problem
  • 4 Problem
  • 5 Problem
  • 6 Problem
  • 7 Problem
  • Report an issue

3.9.a - Class Activity

Be sure to run the following code chunk before continuing with the assignment.

library(tidyverse)
library(stat1080r)

We are going to use the toluca dataset from the stat1080r package for this assignment. Run the following code to make that dataset available in your global environment. Moving the dataset to your global environment is not required; it just makes it easier to view.

toluca <- stat1080r::toluca

The dataset explores the average time (hours) required to manufacture a certain piece of refrigeration equipment at 25 different production plants. Each production plant has a different lot size (size), and the point of this assignment is to determine if there is a relationship between the size of the lot, and the time it takes to make the equipment.

1 Problem

Before attempting linear regression, we want to first confirm that the data appear to share a linear relationship. Create a scatterplot using ggplot2 that plots lot size on the x-axis and hours on the y-axis.

# Place scatterplot code in this chunk. 
#...#

2 Problem

Comment briefly: Does linear regression appear to be appropriate in this case? Explain why or why not.

Replace this text with your answer or discuss with a partner.

3 Problem

Assuming that linear regression is appropriate in this case, use the lm() function to create a model that uses lot size to predict hours. Use the summary function to see the model coefficients.

## tlm <- #...#

## summary(tlm)

4 Problem

Based on the linear model summary, does it appear that the observed relationship between work hours and lot size is statistically significant? On what basis did you make your decision?

Replace this text with your answer or discuss with a partner.

5 Problem

What is the predicted number of hours for a lot size of 30? How about the predicted number of hours for a lot size of 100? Get both answers at the same time by creating a dataframe with the lot sizes of interest, and then feeding that dataframe and your linear model into the predict function.

## tdf <- data.frame(#...#)

## predict(#...#)

6 Problem

What is the predicted number of hours for a lot size of 2? Why is this prediction not meaningful?

# Copy code from previous chunk and adapt as needed.
#...#

Replace this text with your answer or discuss with a partner.

7 Problem

Using the code for the previously created scatterplot, add a linear regression overlay on your plot using the model coefficients you calculated previously. You will do this using geom_abline() which will take two arguments (intercept and slope), which are the linear model coefficients from the regression model you calculated previously. For convenience, please feel free to round your coefficients to two decimal places when using the geom_abline() function.

# Put ggplot code in this chunk.
#...#

© Copyright 2026, Susan Vanderplas

 
  • Report an issue