STA 111 Lab: Regression

Complete all Questions, and submit final documents in PDF form on Canvas.

Submission Set Up

Create a Google Doc or Microsoft Word document for your responses. You will be answering each of the Questions in the boxes below. When you are done, submit your document as a PDF!

Goal

In the last lab, we focused on visualizations as well as summary statistics for one numeric variable. Today, we are going to use visualizations and numeric measures to describe the relationship between two numeric variables. The primary visualization we will use is a scatter plot, and the primary numeric measure we will use is called correlation. We will also see how to create a least squares linear regression line. This is another tool we use to describe the relationship between two numeric variables.

The Data

We are going to continue to work on the data set on student stress and sleep from our last lab. Recall that the data were collected from \(n=1442\) university students who wore a Fit Bit 3 device that recorded information on student sleep, stress, and motion.

If you already have it downloaded from last lab, you do not need to download it again. However, if you need it the data set can be found on Canvas and is also linked here: https://www.dropbox.com/scl/fi/vj2cr3xdjo4gces1273d1/StressStudy.csv?rlkey=napepcy0dpo56ysw4xpeskpkd&st=9a1o84vi&dl=1

Visualization: 2 Numeric Variables

Suppose a counselor from a University Counseling Center is interested in three variables:

  • Sleep Score: A daily score of sleep quality, where higher scores mean better sleep quality.
  • Deep Sleep: A daily measure of how many minutes of deep sleep a student got the night before.
  • Stress Tolerance: A daily score on the scale of 0-100 where a higher stress tolerance score means your body is more ready to adapt to stress/heavy thinking/emotions/ workouts/etc. during the day.

Specifically, the client wants to know about:

    1. The relationship between X = sleep score and Y = stress tolerance
    1. The relationship between X = deep sleep and Y = stress tolerance
    1. The relationship between X = deep sleep and Y = sleep score

Let’s start with (1).

Question 1

What type of plot would you use to visualize the relationship between X = sleep score and Y = stress tolerance score?

Now that we know what type of plot we need, let’s make it! As we did in the previous lab, we are going to use StatKey to do our analysis. However, we will use a different StatKey tool today.

Open the following in a new tab (so copy and paste into a new tab): https://www.lock5stat.com/StatKey/descriptive_2_quant/descriptive_2_quant.html

Once you upload your data, you should see this on your screen:

Click the column for sleep score first, and then the column for stress. The order you click tells the applet which variable is X and which is Y.

Question 2

Take a screen shot of your plot and include it here as your answer to this question.

Question 3

Is the relationship between X = sleep and Y = stress tolerance positive or negative?

Question 4

Does it look reasonable to use a line to describe this relationship?

Question 5

Do you see any visually evident outliers? If so, state the coordinates of the outlier(s). Hint: you can get the coordinates by hovering your mouse over a point.

NOTE: In STA 112 you will learn numeric ways to detect outliers. For now, we are only looking at points that very clearly don’t match what is going on with the rest of the pattern. If you are not sure, it likely not a visually evident outlier!!

So far, everything we have done has involved just looking at the plot. Now, let’s get some numbers involved and find the correlation.

Question 6

What does the correlation measure?

Question 7

What is the correlation between X = sleep score and Y= stress tolerance score?

Hint: The information you need is to the right hand side of your plot.

Question 8

Does the correlation suggest (a) a strong relationship, (b) a moderate relationship, (c) a weak relationship, or (d) no relationship?

Hint: A good rule of thumb is that anything over .7 is strong, and anything below .3 is weak, and anything in the middle is moderate, but this can differ depending on your field of study!!

So far we have only explored one of the three relationships the client was interested. Let’s try the other two.

At the top of your StatKey screen, you should see an option labelled Change Columns. This will allow you to explore other relationships, or come back to the original one when you need it!

Question 9

  1. Create a plot of the relationship between X = deep sleep and Y = stress tolerance score.

  2. Is the relationship positive or negative?

  3. What is the correlation?

  4. Is the relationship strong, moderate, or weak?

Question 10

  1. Create a plot of the relationship between X = deep sleep and Y = sleep score.

  2. Is the relationship positive or negative?

  3. What is the correlation?

  4. Is the relationship strong, moderate, or weak?

Question 11

Which of the three relationships we have explored thus far (sleep score vs. stress, deep sleep vs. stress, and deep sleep vs. sleep score) has the weakest linear relationship?

Concepts: Regression Line

Our client finds the plots that we have created so far to be interesting, but they want something more specific. They want to be able to tell their students how much their stress tolerance might increase if they can increase their sleep score. Answering this question involves creating a regression line.

Question 12

Does answering the client’s question involve the intercept or the slope of a regression line?

A regression line is essentially a line that we draw to try to capture the relationship between X and Y the best we can. However, it can be hard to know how to do that.

Question 13

The slope of our regression line will describe how much \(Y\) = stress tolerance tends to change when \(X\) = sleep score increases by 1. Based on our data, should the slope of our regression line be positive or negative?

Question 14

In this graph it’s actually easier to see how much \(Y\) tends to change when \(X\) increases by 10.

Using the scatter plot, how much in does it look like mean (average value) of \(Y\)= stress tolerance increases when \(X\)= sleep score increases by 10?

Hint: Looking at X = 80 versus X = 90 or X = 60 versus X = 70 are good places to check this.

Question 15

The slope describes how much \(Y\) tends to change when \(X\) increases by 1, so to get an estimate of the slope, all we have to do is divide your answer to Question 14 by 10.

What is your estimate of the slope, i.e., what do you get when you divide your answer to Question 14 by 10?

The Theory: Regression Line

The process we did in Question 14 and Question 15 give us an approximate value of the slope, but it is likely that across the class, we came up with slightly different answers! Is there one “best” choice of a slope and an intercept for our regression line??

When we choose our slope, the goal is to make the residuals as small as possible. Remember, the residuals measure the difference between the y coordinate of a data point \(x_i\) and the y value we predict for that value of \(x_i\) using the line.

In the plot below, we can see a line in blue, the data points in red, and the residuals visualized as the green vertical lines.

There are a lot of red lines! Specifically, there is one line (residual) per data point. What we want to do is find the intercept and slope that makes the overall sum of these residuals squared as small as possible. Why squared? Well, just like with the standard deviation, we have to get rid of those negatives!

So, we need to find a slope and an intercept that make the sum of squared residuals as small as possible. The values that do this are:

  • Slope: \(R\frac{s_y}{s_x}\)
  • Intercept: \(\bar{y} - Slope (\bar{x})\)

where

  • \(R\) = the correlation between \(X\) and \(Y\)
  • \(s_y\) = the standard deviation of \(Y\)
  • \(s_x\) = the standard deviation of \(X\)
  • \(\bar{y}\) = the mean of \(Y\)
  • \(\bar{x}\) = the mean of \(X\)

Any other slope or intercept you choose will result in a higher sum of squared residuals, meaning the line is further from the actual data. Want to know why? Ask me!!

Question 16

Without using any statistical jargon like residuals, explain to a student who has not taken STA 111 what the regression line is.

Using the Line

One of the nice things about the StatKey tool that we are using is that the slope and intercept of the regression line, calculated using the formulas in the previous section, are given on the right hand side of the screen!

Question 17

Click the button to add a regression line to the scatter plot and take a screen shot.

Question 18

Write down the equation for the regression line you visualized in Question 17. This means you should have numbers for the intercept and the slope. You can write “y hat” since I know making the symbol can be annoying!

Hint: The information you need is to the right hand side of your plot.

Question 19

Interpret the slope in the context of the data.

Hint: The units for both X and Y are points.

To practice this concept a little more, let’s look at a different regression line.

Question 20

The slope of the relationship between X = deep sleep in minutes and Y = sleep score (in points out of 100) is 0.188. Interpret this slope in the context of the data.

Making Predictions

In addition to describing relationships, we also use regression lines for making predictions. Basically, we do this by taking a value for X, putting it in the equation for the regression line, and then solving for \(\hat{y}\).

For example, in our line of \(X\) = sleep score and \(Y\) = stress tolerance score, the line is

\[\hat{y} = 54.07 + 0.283 x\]

Question 21

  1. What stress tolerance score would you predict for a student with a sleep score of 72? Show your work!

  2. Is it reasonable to make a prediction for \(X\) = 72 using this line? Explain.

Question 22

  1. What stress tolerance score would you predict for a student with a sleep score of 2? Show your work!

  2. Is it reasonable to make a prediction for \(X\) = 2 using this line? Explain.

Question 23

Using the plot, there is only one student with a sleep score of 52.

  1. What is the residual for this student with a sleep score of 52? Show your work.

  2. Interpret the residual from (a).

Addressing the Client

Question 24

Recall that we have a client who works in a counseling center and is interested in the relationship between student sleep and stress. Based on these data, what would you tell them? Make sure to comment on how confident you are in the conclusions based on the data that we have and the analysis we have run, and make sure to avoid statistical jargon your client may not be familiar with!

Creative Commons License
This work was created by Nicole Dalzell is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Last updated 2026 September 18.

The data set used in this lab is from:

“A Dataset of University Students’ Stress and Anxiety Levels based on Questionnaires and Wearable Sensors”, Enrique Garcia-Ceja, Joanna Alvarado-Uribe, Ponciano Jorge Escamilla-Ambrosio, Adriana Lara, Alma Mena-Martinez, Gina Gallegos-Garcia, Miguel Gonzalez-Mendoza, Raul Monroy, Gilberto Martinez Luna, Juan Manuel Fernández-Cárdenas (2026). .