Proposal

Author

Andreas Sanches

Proposal - Section 1 (Introduction)

As a student, I understand the importance of having good grades and a great relationship with professors, classmates and family. My in-class performance is intimately related to my interpersonal relations and daily habits. If I’m stressed or anxious for some reason, I’ll probably perform poorly, affecting my relations with people I love and appreciate. Having a broad understanding of students’ profiles can explain certain patterns. That said, Professor Paulo Cortez created a dataset containing student data from two Portuguese high schools (Gabriel Pereira and Mousinho de Silveira). Data was gathered through school reports and surveys, encompassing student grades, demographic details, social factors, parental information, and school-related characteristics. Cortez’s work originally had two different subject datasets analyses: the Mathematics one and the Portuguese one. I’ll focus only on the Mathematics students’ performances in this project. Each observation corresponds to a student and its respective information. With all this information, my question is: How do family characteristics, and personal habits influence the final grades of high school students in mathematics? Based on common sense, I believe that students who have better health conditions, good familiar relationships, and put more effort into their studies tend to get better grades than students who have poor relationships and are not engaged with school. I’ll explore the variables on this dataset and see if my predictions are correct.

Section 2

Information for this project was collected from school reports and surveys, covering a range of factors such as student grades, demographic details, social influences, parental information, and school-related characteristics. Cortez initially conducted analyses on two distinct subject datasets: Mathematics and Portuguese. For the purpose of this project, I will concentrate solely on the performance of students in Mathematics. Each data point corresponds to an individual student and their relevant information.

The original dataset has 34 variables and 395 observations, but I removed 16 of (so my dataset only will contain 18 variables initially) them that are “irrelevant” and later added 2 new columns. From the beginning, the variables that I’m considering for this project are:

1. student_id - Student ID for each student

2. school - Student’s school (binary: “GP” - Gabriel Pereira or “MS” - Mousinho da Silveira)

3. school_choice_reason - Reason to choose this school (nominal: close to “home”, school “reputation”, “course” preference, or “other”)

4. study_time - Weekly study time (ordinal: 1 - “<2 hours”, “2 to 5 hours”, “5 to 10 hours”, or “>10 hours”)

5. school_support - Extra educational support (binary: yes or no)

6. family_support - Family educational support (binary: yes or no)

7. higher_ed - Wants to take higher education (binary: yes or no)

8. romantic_relationship - With a romantic relationship (binary: yes or no)

9. family_relationship - Quality of family relationships (numeric: from 1 - very bad to 5 - excellent)

10. free_time - Free time after school (numeric: from 1 - very low to 5 - very high)

11. social - Going out with friends (numeric: from 1 - very low to 5 - very high)

12. weekday_alcohol - Workday alcohol consumption (numeric: from 1 - very low to 5 - very high)

13. weekend_alcohol - Weekend alcohol consumption (numeric: from 1 - very low to 5 - very high)

14. health - Current health status (numeric: from 1 - very bad to 5 - very good)

15. absences - Number of school absences (numeric: from 0 to 93)

16. grade_1 - First period grade (numeric: from 0 to 20)

17. grade_2 - Second period grade (numeric: from 0 to 20)

18. final_grade - Final grade (numeric: from 0 to 20, output target)

I got this dataset from Kagle, and the link to it is https://www.kaggle.com/datasets/dillonmyrick/high-school-student-performance-and-demographics?select=student_math_clean.csv

Citation: P. Cortez and A. Silva. Using Data Mining to Predict Secondary School Student Performance. In A. Brito and J. Teixeira Eds., Proceedings of 5th FUture BUsiness TEChnology Conference (FUBUTEC 2008) pp. 5-12, Porto, Portugal, April, 2008, EUROSIS, ISBN 978-9077381-39-7.

Section 3 (Data Analysis Plan)

In the codes below, my main objective was to see if the “Final Grades” (response variables) had a strong relationship with any other explanatory variables (personal habits, study hours, family relationship and absences). When comparing all these variables, I was able to see that the absence of classes seems to be a strong predictor of final grades, that is, students who miss a little tend to have higher grades than those who miss a lot. This variable proved to be more significant than the variable of weekly alcohol consumption, the quality of family relationships or even the hours studied outside of school. I think Prof. Paulo could in the future include 2 other variables that I believe are related to the final grades to make the study more complete: the students’ happiness index (on a scale of 1-10) and the students’ degree of satisfaction (1-10) in relation to the school.

In the first visualization, my exploratory variable was “Weekly Study Time”, and the response variable was “Final Grade.” The results didn’t differ much, which surprised me because students who study a lot perform similarly to those who study little.

In the second, my exploratory variable was “Family Relationship Quality,” and the response variable was “Final Grade.” Again, students with low-income family relationships performed similarly to students with healthy family relationships.

In the third view, my exploratory variable was “Health Status” and the response variable was “Number of Absences.” In this case, I added a gradient indicating “final grade,” I could see that contrary to the other visualizations, common sense was confirmed: students who miss fewer classes (even if they are sick) have higher grades than the others.

Finally, my fourth visualization had the explanatory variable “Weekly Alcohol Consumption” and the response variable was the “final grades.” I included a regression line and was able to see that no matter how bad the effect of alcohol is on young people, students who drink a lot were not significantly worse than those who drink little.

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
glimpse(students_data)
Rows: 395
Columns: 18
$ student_id            <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1…
$ school                <chr> "GP", "GP", "GP", "GP", "GP", "GP", "GP", "GP", …
$ school_choice_reason  <chr> "course", "course", "other", "home", "home", "re…
$ study_time            <chr> "2 to 5 hours", "2 to 5 hours", "2 to 5 hours", …
$ school_support        <chr> "yes", "no", "yes", "no", "no", "no", "no", "yes…
$ family_support        <chr> "no", "yes", "no", "yes", "yes", "yes", "no", "y…
$ higher_ed             <chr> "yes", "yes", "yes", "yes", "yes", "yes", "yes",…
$ romantic_relationship <chr> "no", "no", "no", "yes", "no", "no", "no", "no",…
$ family_relationship   <dbl> 4, 5, 4, 3, 4, 5, 4, 4, 4, 5, 3, 5, 4, 5, 4, 4, …
$ free_time             <dbl> 3, 3, 3, 2, 3, 4, 4, 1, 2, 5, 3, 2, 3, 4, 5, 4, …
$ social                <dbl> 4, 3, 2, 2, 2, 2, 4, 4, 2, 1, 3, 2, 3, 3, 2, 4, …
$ weekday_alcohol       <dbl> 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …
$ weekend_alcohol       <dbl> 1, 1, 3, 1, 2, 2, 1, 1, 1, 1, 2, 1, 3, 2, 1, 2, …
$ health                <dbl> 3, 3, 3, 5, 5, 5, 3, 1, 1, 5, 2, 4, 5, 3, 3, 2, …
$ absences              <dbl> 6, 4, 10, 2, 4, 10, 0, 6, 0, 0, 0, 4, 2, 2, 0, 4…
$ grade_1               <dbl> 5, 5, 7, 15, 6, 15, 12, 6, 16, 14, 10, 10, 14, 1…
$ grade_2               <dbl> 6, 5, 8, 14, 10, 15, 12, 5, 18, 15, 8, 12, 14, 1…
$ final_grade           <dbl> 6, 6, 10, 15, 10, 15, 11, 6, 19, 15, 9, 12, 14, …
# 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