High School Student Performance Analysis

Understanding the Factors Influencing Final Grades in Mathematics

Author

Andreas Sanches

Published

December 5, 2023

Introduction

  • As a student, I understand the importance of having good grades and a great relationship with professors, classmates and family.
  • I’ll explore the a dataset created by Professor Paulo Cortez on Portuguese high school students. He collected school reports, surveys, demographic details, social factors, parental information, and school-related characteristics to create his Dataset.

Data Overview

  • Focus on Mathematics students.
  • 34 variables, reduced to 18 relevant ones.
  • Data collected from “Gabriel Pereira” and “Mousinho de Silveira” high schools
  • 395 observations (395 students)

Research Question

  • How do family characteristics, and personal habits influence the final grades of high school students in mathematics?

Data Analysis Plan

  • See if there’s any relationship between the “Final Grades” variable (response variable) and other variables, which include personal habits, study hours, family relationship and absences (explanatory variables)

Load and open packages

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plotly)

Attaching package: 'plotly'

The following object is masked from 'package:ggplot2':

    last_plot

The following object is masked from 'package:stats':

    filter

The following object is masked from 'package:graphics':

    layout
library(viridis)
Loading required package: viridisLite
library(rmarkdown)

Loading the dataset I’ll use

setwd("/cloud/project/Data")
students_data <- read_csv("student_math_clean.csv")
Rows: 395 Columns: 34
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (21): school, sex, address_type, family_size, parent_status, mother_educ...
dbl (13): student_id, age, class_failures, family_relationship, free_time, s...

ℹ 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.

Removing unecessary columns

students_data$sex <- NULL
students_data$age <- NULL
students_data$address_type <- NULL
students_data$family_size <- NULL
students_data$parent_status <- NULL
students_data$mother_education <- NULL
students_data$father_education <- NULL
students_data$mother_job <- NULL
students_data$father_job <- NULL
students_data$reason <- NULL
students_data$guardian <- NULL
students_data$travel_time <- NULL
students_data$class_failures <- NULL
students_data$activities <- NULL
students_data$nursery_school <- NULL
students_data$extra_paid_classes <- NULL
students_data$internet_access <- NULL
# Convert study_time to factor with ordered levels
students_data$study_time <- factor(students_data$study_time, 
                                    ordered = TRUE, 
                                    levels = c("<2 hours", "2 to 5 hours", "5 to 10 hours", ">10 hours"))

# Scatter plot with filled points: Study Time vs. Final Grade
ggplot(students_data, aes(x = study_time, y = final_grade, fill = study_time)) +
  geom_point(shape = 21, color = "black", size = 3) +  # Filled points with black border
  labs(title = "Study Time vs. Final Grade",
       x = "Weekly Study Time",
       y = "Final Grade") +
  theme_minimal() +
  scale_x_discrete(limits = c("<2 hours", "2 to 5 hours", "5 to 10 hours", ">10 hours")) +
  theme(legend.position = "none")  # Remove the legend

ggplot(students_data, aes(x = factor(family_relationship), y = final_grade, fill = factor(family_relationship))) +
  geom_boxplot() +
  labs(title = "Family Relationship Quality vs. Final Grade",
       x = "Family Relationship Quality",
       y = "Final Grade") +
  theme_minimal() +
  guides(fill = FALSE)  # Remove the fill legend
Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
of ggplot2 3.3.4.

plot_ly(students_data, x = ~health, y = ~absences, color = ~final_grade, size = ~final_grade, text = ~paste("Grade:", final_grade)) %>%
  add_markers() %>%
  layout(title = "Health vs. Absences",
         xaxis = list(title = "Health Status"),
         yaxis = list(title = "Number of Absences"),
         showlegend = FALSE)
Warning: `line.width` does not currently support multiple values.

Let’s create a new column that shows the week alcohol consumption!

Since the original dataset has 2 different alcohol columns (one for weekdays and another for weekends)

students_data_new <- mutate(students_data, weekly_alcohol_consump = weekday_alcohol + weekend_alcohol)

Let’s create a new variable for alcohol consumption levels

students_data_new <- students_data_new |>
  mutate(alcohol_level = case_when(
    weekly_alcohol_consump >= 0 & weekly_alcohol_consump <= 4 ~ "Drink little",
    weekly_alcohol_consump >= 5 & weekly_alcohol_consump <= 6 ~ "Drink regularly",
    weekly_alcohol_consump >= 7 & weekly_alcohol_consump <= 10 ~ "Drink a lot",
    TRUE ~ "Unknown"  # Add a default category for other values
  ))

Now, let’s create a scatterplot that illustrates this relation!

scatter_plot <- students_data_new |>
  ggplot(aes(x = weekly_alcohol_consump, y = final_grade, color = alcohol_level)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, linetype = "solid", color = "black") +
  labs(title = "Relationship between Weekly Alcohol Consumption \nand Final Grade",
       x = "Weekly Alcohol Consumption",
       y = "Final Grade",
       color = "Alcohol Consumption Level") +
  scale_color_manual(values = c("Drink little" = "blue", "Drink regularly" = "green", "Drink a lot" = "red")) +
  theme_minimal()
scatter_plot_interactive <- ggplotly(scatter_plot)
`geom_smooth()` using formula = 'y ~ x'
scatter_plot_interactive

Conclusion

Surprisingly, the first visualization, examining “Weekly Study Time” and “Final Grade,” showed minimal differences between students who studied a lot and those who studied less. Similarly, the second visualization, exploring “Family Relationship Quality” and “Final Grade,” indicated that students with both low and healthy family relationships performed similarly. In the third visualization, which considered “Health Status” and “Number of Absences,” the results confirmed the intuitive expectation that students with fewer absences, even when sick, tended to have higher grades. The fourth visualization, involving “Weekly Alcohol Consumption” and “Final Grades,” revealed that, contrary to expectations, students who consumed more alcohol did not show significantly worse academic performance compared to those who drank less. Overall, these findings underscore the importance of attendance and health-related factors in predicting academic success, while also challenging preconceived notions about the impact of study time and alcohol consumption on final grades.