library(readr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)

students <- read_csv("StudentsPerformance.csv")
## Rows: 1000 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): gender, race/ethnicity, parental level of education, lunch, test pr...
## dbl (3): math score, reading score, writing score
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
dim(students)
## [1] 1000    8

Introduction

Is there a difference in average math scores between students who completed a test preparation course and those who did not?

This project looks at students’ math scores and test preparation. I am using the Students Performance in Exams dataset, which has 1,000 students and 8 variables.

I will focus on math scores and test preparation. Math scores are quantitative because they use numbers. Test preparation is categorical because students are placed into two groups. I will compare their average math scores to see if there is a difference.

Data Analysis

In this section, I will look at students’ math scores and compare the two groups. I will check for missing data and find the average math score for each group. I will also make graphs to see how the scores compare.

# Check for missing values
colSums(is.na(students))
##                      gender              race/ethnicity 
##                           0                           0 
## parental level of education                       lunch 
##                           0                           0 
##     test preparation course                  math score 
##                           0                           0 
##               reading score               writing score 
##                           0                           0
# Show a summary of the dataset 
summary(students)
##        gender       race/ethnicity parental level of education       lunch     
##  Length   :1000   Length   :1000   Length   :1000              Length   :1000  
##  N.unique :   2   N.unique :   5   N.unique :   6              N.unique :   2  
##  N.blank  :   0   N.blank  :   0   N.blank  :   0              N.blank  :   0  
##  Min.nchar:   4   Min.nchar:   7   Min.nchar:  11              Min.nchar:   8  
##  Max.nchar:   6   Max.nchar:   7   Max.nchar:  18              Max.nchar:  12  
##                                                                                
##  test preparation course   math score     reading score    writing score   
##  Length   :1000          Min.   :  0.00   Min.   : 17.00   Min.   : 10.00  
##  N.unique :   2          1st Qu.: 57.00   1st Qu.: 59.00   1st Qu.: 57.75  
##  N.blank  :   0          Median : 66.00   Median : 70.00   Median : 69.00  
##  Min.nchar:   4          Mean   : 66.09   Mean   : 69.17   Mean   : 68.05  
##  Max.nchar:   9          3rd Qu.: 77.00   3rd Qu.: 79.00   3rd Qu.: 79.00  
##                          Max.   :100.00   Max.   :100.00   Max.   :100.00
#check the dataset size
dim(students)
## [1] 1000    8
# Show students who completed test preparation
students %>%
  filter(`test preparation course` == "completed") %>%
  head()
## # A tibble: 6 Ă— 8
##   gender `race/ethnicity` parental level of educa…¹ lunch test preparation cou…²
##   <chr>  <chr>            <chr>                     <chr> <chr>                 
## 1 female group C          some college              stan… completed             
## 2 female group B          some college              stan… completed             
## 3 male   group D          high school               free… completed             
## 4 male   group A          some college              stan… completed             
## 5 male   group C          master's degree           free… completed             
## 6 female group B          some college              free… completed             
## # ℹ abbreviated names: ¹​`parental level of education`,
## #   ²​`test preparation course`
## # ℹ 3 more variables: `math score` <dbl>, `reading score` <dbl>,
## #   `writing score` <dbl>

I used the filter function to look at students who completed test preparation. This helped me focus on one group of students in the dataset.

library(dplyr)

# Compare average math scores by test preparation
students %>%
  group_by(`test preparation course`) %>%
  summarise(
    average_math = mean(`math score`),
    number_students = n()
  )
## # A tibble: 2 Ă— 3
##   `test preparation course` average_math number_students
##   <chr>                            <dbl>           <int>
## 1 completed                         69.7             358
## 2 none                              64.1             642

Students who completed test preparation had an average math score of 69.70, while students who did not had an average of 64.08. Students who completed the course scored about 5.62 points higher on average.

library(ggplot2)

ggplot(students, aes(x = `test preparation course`,
                     y = `math score`,
                     fill = `test preparation course`)) +
  geom_boxplot() +
  labs(
    title = "Math Scores by Test Preparation",
    x = "Test Preparation",
    y = "Math Score"
  ) +
  theme_minimal()

# Histogram of math scores 
ggplot(students, aes(x = `math score`)) +
  geom_histogram(binwidth = 5, fill = "lightblue",
                 color = "black") +
  labs(
    title = "Distribution of Math Scores",
    x = "Math Scores",
    y = "Number of Students"
  ) +
  theme_minimal()

The histogram shows how students’ math scores are spread out. The average math score is about 66. Most students scored around the middle of the score range.

Statistical Analysis

Null Hypothesis:

\[ H_0:\mu_{\text{completed}}=\mu_{\text{none}} \]

Alternative Hypothesis:

\[ H_a:\mu_{\text{completed}}\ne\mu_{\text{none}} \]

I will use an independent two-sample t-test to compare the average math scores of students who completed test preparation and those who did not. I will use a significance level of 0.05 to see if the difference is statistically significant.

# Independent two-sample t-test
t.test(
  `math score` ~ `test preparation course`,
  data = students
)
## 
##  Welch Two Sample t-test
## 
## data:  math score by test preparation course
## t = 5.787, df = 770.08, p-value = 1.043e-08
## alternative hypothesis: true difference in means between group completed and group none is not equal to 0
## 95 percent confidence interval:
##  3.712041 7.523257
## sample estimates:
## mean in group completed      mean in group none 
##                69.69553                64.07788

The t-test showed a difference in math scores between the two groups. Students who completed test preparation had an average score of 69.70, while students who did not had an average of 64.08. The p-value was less than 0.05, so I rejected the null hypothesis. This means there is a statistically significant difference in average math scores between the two groups.

Conclusion and Future Directions

This project looked at whether test preparation made a difference in students’ math scores. Students who completed test preparation had an average score of 69.70, while students who did not had an average of 64.08. The results showed a statistically significant difference between the two groups.

In the future, I would like to see if test preparation also makes a difference in reading and writing scores. It would also be interesting to see if the amount of time students spend studying affects their scores.

References

Students Performance in Exams. (n.d.). Kaggle. https://www.kaggle.com/datasets/spscientist/students-performance-in-exams