DAT 301 | Homework 3

1. The Question

Do students who study more hours tend to earn higher exam scores?

  • We’ll use graphs and statistics to look for a pattern.
  • We made up data for 80 students to practice. These are not real scores.
  • We’re checking if the two are related, not if studying directly causes higher scores.

2. Why This Matters

  • Students might wonder if studying longer helps their grades.
  • A scatterplot helps us see if there’s a pattern.
  • Correlation tells us how strongly two things are related in a straight-line pattern.
  • Regression gives us a line we can use to predict scores.

Keep in mind: Sleep and how someone studies can affect scores too.

3. Statistical Idea: Correlation

Correlation tells us if two numbers tend to go up or down together in a straight-line pattern.

  • \(r\) ranges from \(-1\) to \(1\).
  • Positive \(r\): more study hours usually go with higher scores.
  • Negative \(r\): more study hours usually go with lower scores.
  • \(r\) near zero: there isn’t much of a straight-line pattern.

For our simulated data, \(r =\) 0.82.

4. Mathematics: Correlation

We can calculate correlation using this formula:

\[ r = \frac{\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})} {\sqrt{\sum_{i=1}^{n}(x_i-\bar{x})^2}\sqrt{\sum_{i=1}^{n}(y_i-\bar{y})^2}} \]

Here, \(x_i\) means study hours, \(y_i\) means exam scores, and the bars mean averages.

What it means: Our positive \(r\) shows that students who studied more usually scored higher in this example.

5. Statistical Idea: Linear Regression

A regression line helps us see the overall pattern and predict scores.

  • The slope tells us how much the predicted score changes for one more hour of studying.
  • The intercept is the predicted score at zero study hours. Our data starts at one hour, so that prediction may not be reliable.
  • Predicted scores are just estimates, not exact answers.

6. Mathematics: Regression

This is the formula for simple linear regression:

\[ Y_i = \beta_0 + \beta_1 X_i + \varepsilon_i \]

Once we find the line, we can write it like this:

\[ \widehat{Y} = \widehat{\beta}_0 + \widehat{\beta}_1 X \]

For our example:

\[ \widehat{\mathrm{Score}} = 42.63 + 5.42 \times \mathrm{Hours} \]

What it means: Each extra hour of studying goes with about 5.4 more predicted points in our made-up data.

7. R Code: Fit the Model

Here’s the R code we used to find correlation and make the regression line:

library(ggplot2)
library(plotly)

r <- cor(students$study_hours, students$exam_score)
fit <- lm(exam_score ~ study_hours, data = students)
summary(fit)

ggplot(students, aes(study_hours, exam_score)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE)

What the code does: cor() finds correlation, and lm() makes the regression line.

8. ggplot2: Study Hours vs. Scores

What we see: The line goes up, so students who studied longer usually had higher scores.

9. ggplot2: Compare Study Groups

What we see: We can compare the middle scores and how spread out each group is. This doesn’t prove studying caused the difference.

10. Interactive Plotly Visualization

Move your mouse over a dot to see that student’s study hours and score.

What we see: We can check each student’s score instead of just looking at the overall pattern.

11. What Did We Learn?

  • In our made-up data, students who studied more usually scored higher.
  • Correlation: 0.82.
  • Regression slope: 5.42 score points per additional hour.
  • \(R^2 = 0.67\): the line helps explain about 67% of the differences in scores in this example.

Conclusion: In our made-up data, more study hours go with higher scores. But we can’t say studying more is what caused those scores, or that real students would show the same pattern.

Next step: Try this again with real student data and look at other things that might affect scores.