library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ 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(ggthemes)
library(ggrepel)
library(AmesHousing)
library(boot)
library(broom)
my_data <- read.csv("/Users/shemaaeltayeb/Desktop/STATISTIC IN R /student_data.csv")

Introduction :

Dataset Name: Student Performance Dataset

Student Performance Dataset, it’s a collection of information related to student performance and various attributes that play a crucial role in shaping academic outcomes. The data set has 395 observations, 33 variables and most of it categorical variables, both nominal and ordinal.

Project’s Goals:

The aim of this project is to identify the factors that impact student performance.Explore how parental education levels (Medu and Fedu) correlate with student success and academic outcomes.Investigate and identify the key factors that influence student performance. Examine and compare the academic performance of male and female students to identify any gender-related disparities and their potential causes.Investigate reasons for choosing a particular school (reason) and determine if these reasons correlate with academic performance.Investigate the effect of family relationships (famrel) and free time (freetime) on student academic performance.

Reserch questions:

• Question: Does the reason for choosing the school (reason) have an impact on student performance (e.g., G3)?

• Question: Are there significant differences in student performance (G3) based on the type of address (address: urban or rural)?

• Question: How does the guardian type (guardian) influence students’ daily alcohol consumption (Dalc)?

• Question: Can we identify patterns in student absences (absences) based on the reason for school absence (reason)? Are there specific reasons that correlate with higher absence rates?

• Question: Do gender differences in academic performance vary based on other factors like parental education or family relationships?

• Question: Does the study time, absences, previous failures, and previous grades (G1 and G2) relate to a student’s final grade (G3)?

Data Description :

summary(my_data)
##     school              sex                 age         address         
##  Length:395         Length:395         Min.   :15.0   Length:395        
##  Class :character   Class :character   1st Qu.:16.0   Class :character  
##  Mode  :character   Mode  :character   Median :17.0   Mode  :character  
##                                        Mean   :16.7                     
##                                        3rd Qu.:18.0                     
##                                        Max.   :22.0                     
##    famsize            Pstatus               Medu            Fedu      
##  Length:395         Length:395         Min.   :0.000   Min.   :0.000  
##  Class :character   Class :character   1st Qu.:2.000   1st Qu.:2.000  
##  Mode  :character   Mode  :character   Median :3.000   Median :2.000  
##                                        Mean   :2.749   Mean   :2.522  
##                                        3rd Qu.:4.000   3rd Qu.:3.000  
##                                        Max.   :4.000   Max.   :4.000  
##      Mjob               Fjob              reason            guardian        
##  Length:395         Length:395         Length:395         Length:395        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##    traveltime      studytime        failures       schoolsup        
##  Min.   :1.000   Min.   :1.000   Min.   :0.0000   Length:395        
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:0.0000   Class :character  
##  Median :1.000   Median :2.000   Median :0.0000   Mode  :character  
##  Mean   :1.448   Mean   :2.035   Mean   :0.3342                     
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:0.0000                     
##  Max.   :4.000   Max.   :4.000   Max.   :3.0000                     
##     famsup              paid            activities          nursery         
##  Length:395         Length:395         Length:395         Length:395        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##     higher            internet           romantic             famrel     
##  Length:395         Length:395         Length:395         Min.   :1.000  
##  Class :character   Class :character   Class :character   1st Qu.:4.000  
##  Mode  :character   Mode  :character   Mode  :character   Median :4.000  
##                                                           Mean   :3.944  
##                                                           3rd Qu.:5.000  
##                                                           Max.   :5.000  
##     freetime         goout            Dalc            Walc      
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:3.000   1st Qu.:2.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :3.000   Median :3.000   Median :1.000   Median :2.000  
##  Mean   :3.235   Mean   :3.109   Mean   :1.481   Mean   :2.291  
##  3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:2.000   3rd Qu.:3.000  
##  Max.   :5.000   Max.   :5.000   Max.   :5.000   Max.   :5.000  
##      health         absences            G1              G2       
##  Min.   :1.000   Min.   : 0.000   Min.   : 3.00   Min.   : 0.00  
##  1st Qu.:3.000   1st Qu.: 0.000   1st Qu.: 8.00   1st Qu.: 9.00  
##  Median :4.000   Median : 4.000   Median :11.00   Median :11.00  
##  Mean   :3.554   Mean   : 5.709   Mean   :10.91   Mean   :10.71  
##  3rd Qu.:5.000   3rd Qu.: 8.000   3rd Qu.:13.00   3rd Qu.:13.00  
##  Max.   :5.000   Max.   :75.000   Max.   :19.00   Max.   :19.00  
##        G3       
##  Min.   : 0.00  
##  1st Qu.: 8.00  
##  Median :11.00  
##  Mean   :10.42  
##  3rd Qu.:14.00  
##  Max.   :20.00

Column Descriptions:

Provides a brief description of each column (attribute) in a dataset, including its data type and potential values:

1-school (Categorical): The name of the school (‘GP’ - Gabriel Pereira or ‘MS’ - Mousinho da Silveira).

2-sex (Categorical): Student’s gender (‘F’ for female or ‘M’ for male).

3-age (Numeric): Student’s age.

4-address (Categorical): Student’s home address type (‘U’ for urban or ‘R’ for rural).

5-famsize (Categorical): Family size (‘LE3’ for less or equal to 3, ‘GT3’ for greater than 3).

6-Pstatus (Categorical): Parent’s cohabitation status (‘A’ for apart or ‘T’ for together).

7-Medu (Numeric): Mother’s education level (0 - none, 1 - primary education, 2 - 5th to 9th grade, 3 - secondary education, 4 - higher education).

8-Fedu (Numeric): Father’s education level (0 - none, 1 - primary education, 2 - 5th to 9th grade, 3 - secondary education, 4 - higher education).

9-Mjob (Categorical): Mother’s job.

10-Fjob (Categorical): Father’s job.

11-reason (Categorical): Reason for choosing this school.

12-guardian (Categorical): Student’s guardian.

13-traveltime (Numeric): Travel time to school.

14-studytime (Numeric): Weekly study time.

15-failures (Numeric): Number of past class failures.

16-schoolsup (Categorical): Extra educational support (‘yes’ or ‘no’).

17-famsup (Categorical): Family educational support (‘yes’ or ‘no’).

18-paid (Categorical): Extra paid classes within the course subject (‘yes’ or ‘no’).

19-activities (Categorical): Extra-curricular activities (‘yes’ or ‘no’).

20-nursery (Categorical): Attended nursery school (‘yes’ or ‘no’).

21-higher (Categorical): Wants to take higher education (‘yes’ or ‘no’).

22-internet (Categorical): Internet access at home (‘yes’ or ‘no’).

23-romantic (Categorical): In a romantic relationship (‘yes’ or ‘no’).

24-famrel (Numeric): Quality of family relationships.

25-freetime (Numeric): Free time after school.

26-goout (Numeric): Going out with friends.

27-Dalc (Numeric): Weekday alcohol consumption.

28-Walc (Numeric): Weekend alcohol consumption.

29-health (Numeric): Current health status.

30-absences (Numeric): Number of school absences.

31-G1 (Numeric): First period grade.

32-G2 (Numeric): Second period grade.

33-G3 (Numeric): Final grade.

Categorical variables:

First a summary of the binary categorical variables.

# Sex (sex)
sex_summary <- prop.table(table(my_data $sex)) * 100

# Address (address)
address_summary <- prop.table(table(my_data $address)) * 100

# School (school)
school_summary <- prop.table(table(my_data $school)) * 100

# Family size (famsize)
famsize_summary <- prop.table(table(my_data $famsize)) * 100

# Parental status (Pstatus)
pstatus_summary <- prop.table(table(my_data $Pstatus)) * 100

# Nursery school (nursery)
nursery_summary <- prop.table(table(my_data $nursery)) * 100

# Higher education (higher)
higher_summary <- prop.table(table(my_data $higher)) * 100

# School support (schoolsup)
schoolsup_summary <- prop.table(table(my_data $schoolsup)) * 100

# Family support (famsup)
famsup_summary <- prop.table(table(my_data $famsup)) * 100

# Extra paid classes within the course subject (paid)
paid_summary <- prop.table(table(my_data$paid)) * 100

# Extra-curricular activities (activities)
activities_summary <- prop.table(table(my_data $activities)) * 100

# Internet at home (internet)
internet_summary <- prop.table(table(my_data $internet)) * 100

# Romantic relationship (romantic)
romantic_summary <- prop.table(table(my_data $romantic)) * 100

# Print the summaries
cat("Sex (sex):", sex_summary, "(female/male)\n")
## Sex (sex): 52.65823 47.34177 (female/male)
cat("Address (address):", address_summary, "(rural/urban)\n")
## Address (address): 22.27848 77.72152 (rural/urban)
cat("School (school):", school_summary, "(Gabriel Pereira (GP)/Mousinho da Silveira (MS))\n")
## School (school): 88.35443 11.64557 (Gabriel Pereira (GP)/Mousinho da Silveira (MS))
cat("Family size (famsize):", famsize_summary, "(3 or less/4 or more)\n")
## Family size (famsize): 71.13924 28.86076 (3 or less/4 or more)
cat("Parental status (Pstatus):", pstatus_summary, "(living together/living apart)\n")
## Parental status (Pstatus): 10.37975 89.62025 (living together/living apart)
cat("Nursery school (nursery):", nursery_summary, "(yes/no)\n")
## Nursery school (nursery): 20.50633 79.49367 (yes/no)
cat("Higher education (higher):", higher_summary, "(yes/no)\n")
## Higher education (higher): 5.063291 94.93671 (yes/no)
cat("School support (schoolsup):", schoolsup_summary, "(yes/no)\n")
## School support (schoolsup): 87.08861 12.91139 (yes/no)
cat("Family support (famsup):", famsup_summary, "(yes/no)\n")
## Family support (famsup): 38.73418 61.26582 (yes/no)
cat("Extra paid classes (paid):", paid_summary, "(yes/no)\n")
## Extra paid classes (paid): 54.17722 45.82278 (yes/no)
cat("Extra-curricular activities (activities):", activities_summary, "(yes/no)\n")
## Extra-curricular activities (activities): 49.11392 50.88608 (yes/no)
cat("Internet at home (internet):", internet_summary, "(yes/no)\n")
## Internet at home (internet): 16.70886 83.29114 (yes/no)
cat("Romantic relationship (romantic):", romantic_summary, "(yes/no)\n")
## Romantic relationship (romantic): 66.58228 33.41772 (yes/no)

These percentages provide information of the distribution of each category within the respective variables.

1- Sex (sex): Approximately 52.66% are female, and 47.34% are male.

2- Address (address): Around 22.28% are from rural areas, and 77.72% are from urban areas.

3- School (school): About 88.35% attend Gabriel Pereira (GP), and 11.65% attend Mousinho da Silveira (MS).

4- Family size (famsize): The majority, 71.14%, have a family size of 3 or less, while 28.86% have a family size of 4 or more.

5- Parental status (Pstatus): Only 10.38% of parents live apart, while 89.62% live together.

6- Nursery school (nursery): Approximately 20.51% attended nursery school, while 79.49% did not.

7- Higher education (higher): A small percentage, 5.06%, indicated they do not want higher education, while 94.94% expressed a desire for higher education.

1- The data shows that there are 208 female students and 187 male students. will investigate the gender distribution to see if it has any implications for other variables?

will explore whether family educational support (‘famsup’) varies by gender and if there differences in the level of support provided by families for education based on the gender of the student?

2- The data indicates that a larger proportion of students come from urban areas (307) compared to rural areas (88).

These investigations can help uncover patterns, disparities, or factors that may be associated with the students’ geographic locations (rural vs. urban) and how they relate to various aspects of their lives and academic performance.

3- The data reveals a significant difference in the number of students between the two schools. Gabriel Pereira (‘GP’) has a substantially larger student population compared to Mousinho da Silveira (‘MS’).

Several factors could contribute to this difference, such as the schools’ locations, reputations, or admission policies. Further investigation is needed to understand the reasons behind this disparity.

4- The data shows that there are 242 students who receive family educational support (‘yes’) and 153 students who do not receive such support (‘no’).

We can investigate whether family educational support has any correlation with academic performance? We can explore whether there are any gender-based differences in family educational support.?

5- In the ‘higher’ education category, which represents students aspiring to pursue higher education, the summary reveals a significant disparity. The data shows that a vast majority of students, specifically 375 individuals, express a strong desire to continue their education at a higher level. In contrast, only a small minority of 20 students indicate a lack of interest in pursuing higher education.

In further investigations, will gain a deeper understanding of the factors and influences behind students’ aspirations for higher education and how these aspirations relate to various aspects of their lives and academic performance.

Categorical Variables With More Than Two Categories Were Plotted As Bar Charts:

# Plot for Mother’s job (Mjob)
ggplot(my_data, aes(x = Mjob, fill = Mjob)) +
  geom_bar() +
  labs(title = "Distribution of Mother’s Job",
       x = "Job Categories",
       y = "Count") +
  theme_minimal()

# Plot for Father’s job (Fjob)
ggplot(my_data, aes(x = Fjob, fill = Fjob)) +
  geom_bar() +
  labs(title = "Distribution of Father’s Job",
       x = "Job Categories",
       y = "Count") +
  theme_minimal()

# Plot for Reason for choosing this school (Reason)
ggplot(my_data, aes(x = reason, fill = reason)) +
  geom_bar() +
  labs(title = "Reasons for Choosing the School",
       x = "Reason Categories",
       y = "Count") +
  theme_minimal()

# Plot for Student’s guardian (Guardian)
ggplot(my_data, aes(x = guardian, fill = guardian)) +
  geom_bar() +
  labs(title = "Distribution of Student’s Guardian",
       x = "Guardian Categories",
       y = "Count") +
  theme_minimal()

Quantitative Variables:

# Plot for Student’s age (age)
ggplot(my_data, aes(x = age)) +
  geom_histogram(binwidth = 1, fill = "skyblue", color = "black", alpha = 0.7) +
  labs(title = "Distribution of Student’s Age",
       x = "Age",
       y = "Count") +
  theme_minimal()

# Plot for Weekly study time (studytime)
ggplot(my_data, aes(x = studytime)) +
  geom_histogram(binwidth = 1, fill = "lightgreen", color = "black", alpha = 0.7) +
  labs(title = "Distribution of Weekly Study Time",
       x = "Study Time (hours)",
       y = "Count") +
  theme_minimal()

# Plot for Number of past class failures (failures)
ggplot(my_data, aes(x = failures)) +
  geom_histogram(binwidth = 1, fill = "salmon", color = "black", alpha = 0.7) +
  labs(title = "Distribution of Past Class Failures",
       x = "Number of Failures",
       y = "Count") +
  theme_minimal()

# Plot for Final grade (G3)
ggplot(my_data, aes(x = G3)) +
  geom_histogram(binwidth = 1, fill = "gold", color = "black", alpha = 0.7) +
  labs(title = "Distribution of Final Grades",
       x = "Final Grade",
       y = "Count") +
  theme_minimal()

# Plot for Travel time to school (traveltime)
ggplot(my_data, aes(x = traveltime)) +
  geom_histogram(binwidth = 1, fill = "orchid", color = "black", alpha = 0.7) +
  labs(title = "Distribution of Travel Time to School",
       x = "Travel Time",
       y = "Count") +
  theme_minimal()

# Plot for Free time after school (freetime)
ggplot(my_data, aes(x = freetime)) +
  geom_histogram(binwidth = 1, fill = "lightcoral", color = "black", alpha = 0.7) +
  labs(title = "Distribution of Free Time after School",
       x = "Free Time",
       y = "Count") +
  theme_minimal()

# Plot for Going out with friends (goout)
ggplot(my_data, aes(x = goout)) +
  geom_histogram(binwidth = 1, fill = "dodgerblue", color = "black", alpha = 0.7) +
  labs(title = "Distribution of Going Out with Friends",
       x = "Goout",
       y = "Count") +
  theme_minimal()

# Plot for Weekday alcohol consumption (Dalc)
ggplot(my_data, aes(x = Dalc)) +
  geom_histogram(binwidth = 1, fill = "mediumseagreen", color = "black", alpha = 0.7) +
  labs(title = "Distribution of Weekday Alcohol Consumption",
       x = "Weekday Alcohol Consumption",
       y = "Count") +
  theme_minimal()

# Plot for Weekend alcohol consumption (Walc)
ggplot(my_data, aes(x = Walc)) +
  geom_histogram(binwidth = 1, fill = "darkorange", color = "black", alpha = 0.7) +
  labs(title = "Distribution of Weekend Alcohol Consumption",
       x = "Weekend Alcohol Consumption",
       y = "Count") +
  theme_minimal()

# Plot for Current health status (health)
ggplot(my_data, aes(x = health)) +
  geom_histogram(binwidth = 1, fill = "tomato", color = "black", alpha = 0.7) +
  labs(title = "Distribution of Current Health Status",
       x = "Health Status",
       y = "Count") +
  theme_minimal()

# Plot for Number of school absences (absences)
ggplot(my_data, aes(x = absences)) +
  geom_histogram(binwidth = 1, fill = "cornflowerblue", color = "black", alpha = 0.7) +
  labs(title = "Distribution of Number of School Absences",
       x = "Number of Absences",
       y = "Count") +
  theme_minimal()

Visualization Relationship Between Weekend Alcohol Consumption And Third Period Grade:

# Create a scatter plot
ggplot(data = my_data, aes(x = Walc , y = G3)) +
  geom_point(aes(color = G3), size = 3) +
  labs(
    x = "weekend alcohol consumption",
    y = "Third Period Grade (G3)",
    title = "Relationship Between weekend alcohol consumption and Third Period Grade"
  ) +
  theme_minimal()

Visualization Relationship Between Weekday Alcohol Consumption And Final Grade:

# Create a scatter plot
ggplot(data = my_data, aes(x = Dalc , y = G3)) +
  geom_point(aes(color = G3), size = 3) +
  labs(
    x = "weekday alcohol consumption",
    y = "Third Period Grade (G3)",
    title = "Relationship Between weekday alcohol consumption and Final Grade"
  ) +
  theme_minimal()

The columns “Dalc” and “Walc” in the student performance dataset represent the weekday and weekend alcohol consumption of students, respectively. These columns use a discrete ordinal scale with values ranging from 1 to 5, where:

1: Very low alcohol consumption 2: Low alcohol consumption 3: Moderate alcohol consumption 4: High alcohol consumption 5: Very high alcohol consumption

The outliers, where some students have high alcohol consumption but still achieve high grades, are interesting and important to consider. These cases suggest that while alcohol consumption may be a factor, it’s not the sole determinant of academic success. Other factors, such as innate intelligence, effective study strategies, and a supportive environment, can mitigate the negative effects of alcohol consumption. Further analysis would be needed to establish a relationship and explore the complex interplay of these factors.

Creating three sets to identify and understand the factors that influence a student’s performance:

SET ONE: “Family Realtionship Factors Influencing Student Performance”

Response Variable: Final Grade (G3)

Explanatory Variables:

Mother education (Medu) Father education (Fedu) Family relationship quality (famrel) Free time (freetime) Health (health)

Creating this set to identify and understand the factors that influence a student’s performance, particularly their final grade (G3), based on variables such as maternal education (Medu), paternal education (Fedu), family relationship quality (famrel), free time (freetime), and overall health (health).

# Select the columns for set one
set_one <- my_data %>%
  select(G3, Medu, Fedu, famrel, freetime, health)

Visualization For Set One :

# Scatter plot: G3 vs Medu
ggplot(set_one, aes(y = Medu, x = G3)) +
  geom_point() +
  labs(y = "Mother education (Medu)", x = "Final Grade (G3)")

# Scatter plot: G3 vs Fedu
ggplot(set_one, aes(y = Fedu, x = G3)) +
  geom_point() +
  labs(y = "Father education (Fedu)", x = "Final Grade (G3)")

# Scatter plot: G3 vs famrel
ggplot(set_one, aes(y = famrel, x = G3)) +
  geom_point() +
  labs(y = "Family relationship quality (famrel)", x = "Final Grade (G3)")

# Scatter plot: G3 vs freetime
ggplot(set_one, aes(y = freetime, x= G3)) +
  geom_point() +
  labs(y = "Free time", x = "Final Grade (G3)")

# Scatter plot: G3 vs health
ggplot(set_one, aes(y = health, x = G3)) +
  geom_point() +
  labs(y = "Health", x = "Final Grade (G3)")

It appears from the visualization that family relationship quality, mother’s education (Medu), and father’s education (Fedu) have an impact on the final grade (G3) of students. However, there doesn’t seem to be a significant correlation between the final grade and students’ health.

This suggests that family dynamics and parental education might play a more substantial role in students’ academic performance compared to their health status.

SET TWO: “Social Student Performance Factors”

Response Variable: Final Grade (G3)

Explanatory Variables:

Workday alcohol consumption (Dalc) Weekend alcohol consumption (Walc) Go out (goout) Age (age) Travel Time(traveltime)

Creating this set with “G3” as the response variable and explanatory variables like “age,” “health,” “goout,” “Dalc” (workday alcohol consumption), and “Walc” (weekend alcohol consumption) to provide insights into how these factors may be associated with a student’s final grade (G3).

# Select the columns for set two
set_two <- my_data %>%
  select(G3, Dalc, Walc ,goout , age , traveltime)

Visualization for set two:

# Scatter plot: G3 vs Dalc
ggplot(set_two, aes(y = Dalc, x = G3)) +
  geom_point() +
  labs(y = "Weekday Alcohol Consumption (Dalc)", x = "Final Grade (G3)")

# Scatter plot: G3 vs Walc
ggplot(set_two, aes(y = Walc, x = G3)) +
  geom_point() +
  labs(y = "Weekend Alcohol Consumption (Walc)", x = "Final Grade (G3)")

# Scatter plot: G3 vs goout
ggplot(set_two, aes(y = goout, x = G3)) +
  geom_point() +
  labs(y = "Going Out (goout)", x = "Final Grade (G3)")

# Scatter plot: G3 vs age
ggplot(set_two, aes(y = age, x= G3)) +
  geom_point() +
  labs(y = "Age", x = "Final Grade (G3)")

# Scatter plot: G3 vs health
ggplot(set_two, aes(y = traveltime, x = G3)) +
  geom_point() +
  labs(y = "Travel Time", x = "Final Grade (G3)")

The visualization indicates that higher weekday alcohol consumption tends to correspond with lower final grades. Students who consume alcohol more frequently on weekdays are likely to have lower grades. This suggests a negative correlation between weekday alcohol consumption and academic performance.

Students who consume alcohol primarily on weekends (lower Walc) seem to have a slightly better chance of achieving higher grades compared to those who consume alcohol more frequently on weekdays (higher Dalc). Weekend alcohol consumption appears to have a lesser negative impact on grades compared to weekday consumption.

The analysis suggests that there is not a significant linear relationship between age and final grades. In other words, the age of the student doesn’t appear to strongly influence the final grade. There might be other factors at play that affect academic performance more directly.

The visualization indicates that as travel time increases, final grades tend to decrease. Students who spend more time traveling from home to school are likely to have lower grades. This suggests a negative correlation between travel time and academic performance.

In summary, weekday alcohol consumption (Dalc), weekend alcohol consumption (Walc), and travel time to school are factors that appear to influence final grades in set_two. Specifically, higher alcohol consumption, especially on weekdays, and longer travel times are associated with lower academic performance. Age, however, does not show a strong linear correlation with final grades in this analysis.

SET THREE: “Factors Affecting G3”

Response Variable: Final Grade (G3)

Explanatory Variables:

Study Time (studytime) Absences (absences) Previous Failures (failures) Previous Grades (G1 and G2)

Creating this set can perform various analyses to understand how study time, absences, previous failures, and previous grades (G1 and G2) relate to a student’s final grade (G3).

# Select the columns for set three
set_three <- my_data %>%
  select(G3,studytime , absences , failures, G1 , G2)

Visualization For Set Three:

# Scatter plot for G3 vs absences
ggplot(set_three, aes(y = absences, x = G3)) +
  geom_point(color = "skyblue", alpha = 0.7) +
  labs(y = "Number of Absences", x = "Final Grade (G3)") +
  theme_minimal()

# Scatter plot for G3 vs studytime
ggplot(set_three, aes(y = studytime , x = G3)) +
  geom_point(color = "skyblue", alpha = 0.7) +
  labs(y = "studytime", x = "Final Grade (G3)") +
  theme_minimal()

# Scatter plot for G3 vs G2
ggplot(set_three, aes(y = G2 , x = G3)) +
  geom_point(color = "skyblue", alpha = 0.7) +
  labs(y = "G2", x = "Final Grade (G3)") +
  theme_minimal()

# Scatter plot for G3 vs G1
ggplot(set_three, aes(y = G1 , x = G3)) +
  geom_point(color = "skyblue", alpha = 0.7) +
  labs(y = "G1", x = "Final Grade (G3)") +
  theme_minimal()

# Scatter plot for G3 vs failures
ggplot(set_three, aes(y = failures , x = G3)) +
  geom_point(color = "skyblue", alpha = 0.7) +
  labs(y = "Failures", x = "Final Grade (G3)") +
  theme_minimal()

G1 and G2 (First and Second Period Grades): These variables have a strong positive correlation with the final grade (G3). It’s common for students who perform well in the earlier periods to also perform well in the final period.

Absences: There is a negative correlation between absences and final grades. More absences tend to be associated with lower final grades. High absenteeism can indicate missed lessons and could impact a student’s understanding of the material.

Studytime: the study time doesn’t strongly influence final grades. It’s possible that other factors might be more influential in determining a student’s academic performance.

Failures: There is a clear negative correlation between past failures and final grades. Students who have failed previous classes tend to have lower final grades. This highlights the importance of addressing past academic challenges to improve overall performance.

These insights provide valuable information for understanding the factors that impact student performance in set_three. Further analysis and modeling could help explore these relationships in more depth and potentially predict student outcomes based on these factors.

Correlation Coefficient For Each Of These Combinations:

correlation coefficient for set one:

# correlation coefficient for set_one:

round(cor(set_one$G3, set_one$Medu), 2)
## [1] 0.22
round(cor(set_one$G3, set_one$Fedu), 2)
## [1] 0.15
round(cor(set_one$G3, set_one$famrel), 2)
## [1] 0.05
round(cor(set_one$G3, set_one$freetime), 2)
## [1] 0.01
round(cor(set_one$G3, set_one$health), 2)
## [1] -0.06

Correlation Analysis:

G3 and Medu (Mother’s Education): The correlation coefficient is 0.22. This positive correlation suggests a weak positive relationship between a student’s final grade and their mother’s education level. As mother’s education level increases, the final grade tends to increase slightly.

G3 and Fedu (Father’s Education): The correlation coefficient is 0.15. Similar to mother’s education, there is a weak positive relationship between a student’s final grade and their father’s education level. As father’s education level increases, the final grade tends to increase, though the effect is relatively weak.

G3 and Famrel (Family Relationship Quality): The correlation coefficient is 0.05. There is a very weak positive relationship between family relationship quality and the final grade. A higher family relationship quality is associated with a slightly higher final grade, but the effect is minimal.

G3 and Freetime (Free Time): The correlation coefficient is 0.01. There is an extremely weak positive relationship between free time and the final grade. This indicates that free time does not significantly influence a student’s final grade in set_one.

G3 and Health: The correlation coefficient is -0.06. This negative correlation suggests a weak negative relationship between a student’s final grade and their health. As health decreases (worsens), the final grade tends to decrease slightly.

That means the correlations in set_one indicate weak to very weak relationships between the final grade and these explanatory variables. The strongest relationship exists with mother’s education, followed by father’s education, while family relationship quality, free time, and health have minimal influence on the final grade.

correlation coefficient for set_two :

# correlation coefficient for set_two:
round(cor(set_two$G3, set_two$Dalc), 2)
## [1] -0.05
round(cor(set_two$G3, set_two$Walc), 2)
## [1] -0.05
round(cor(set_two$G3, set_two$goout), 2)
## [1] -0.13
round(cor(set_two$G3, set_two$age), 2)
## [1] -0.16
round(cor(set_two$G3, set_two$traveltime), 2)
## [1] -0.12

G3 and Dalc (Weekday Alcohol Consumption): The correlation coefficient is -0.05. This negative correlation suggests a very weak negative relationship between a student’s final grade and their weekday alcohol consumption. As weekday alcohol consumption increases slightly, the final grade tends to decrease very slightly, but the effect is minimal.

G3 and Walc (Weekend Alcohol Consumption): The correlation coefficient is -0.05. Similar to weekday alcohol consumption, there is a very weak negative relationship between weekend alcohol consumption and the final grade. As weekend alcohol consumption increases slightly, the final grade tends to decrease very slightly.

G3 and Goout (Going Out with Friends): The correlation coefficient is -0.13. There is a weak negative relationship between how often a student goes out with friends and the final grade. As the frequency of going out increases, the final grade tends to decrease slightly. The effect, while weak, is more noticeable compared to alcohol consumption.

G3 and Age: The correlation coefficient is -0.16. There is a weak negative relationship between a student’s age and the final grade. As a student’s age increases, the final grade tends to decrease slightly. This suggests that older students might, on average, have slightly lower final grades compared to younger students.

G3 and Traveltime: The correlation coefficient is -0.12. There is a weak negative relationship between travel time from home to school and the final grade. As travel time increases, indicating a longer commute, the final grade tends to decrease slightly. Students with longer travel times may have slightly lower final grades on average.

Since these factors in set_two exhibit weak negative relationships with the final grade. While the correlations are statistically significant due to the dataset’s size, the actual impact on the final grade is minimal for each of these factors.

correlation coefficient for set_three:

# correlation coefficient for set_three:

round(cor(set_three$G3, set_three$studytime), 2)
## [1] 0.1
round(cor(set_three$G3, set_three$absences), 2)
## [1] 0.03
round(cor(set_three$G3, set_three$failures), 2)
## [1] -0.36
round(cor(set_three$G3, set_three$G1), 2)
## [1] 0.8
round(cor(set_three$G3, set_three$G2), 2)
## [1] 0.9

Study Time (studytime) vs. Final Grade (G3) [0.1]:

There is a weak positive correlation between study time and final grades. While there is a positive trend, it’s not very strong, indicating that increased study time only slightly influences higher grades.

Absences vs. Final Grade (G3) [0.03]:

The correlation between absences and final grades is very weak and positive. This suggests that there is almost no linear relationship between the number of absences and final grades.

Past Failures (failures) vs. Final Grade (G3) [-0.36]:

There is a moderate negative correlation between past failures and final grades. A higher number of past failures is associated with lower final grades. This negative correlation indicates that students who have failed before are likely to have lower final grades.

First Period Grade (G1) vs. Final Grade (G3) [0.8]:

There is a very strong positive correlation between the first period grade (G1) and the final grade (G3). This means that students who perform well in the first period are highly likely to perform well in the final period.

Second Period Grade (G2) vs. Final Grade (G3) [0.9]: The correlation between the second period grade (G2) and the final grade (G3) is extremely strong, indicating that students who do well in the second period also do exceptionally well in the final period.

These correlations provide insights into the relationships between different variables and the final grade (G3). The strong positive correlations with G1 and G2 suggest that early academic performance is highly predictive of final grades. On the other hand, the negative correlation with failures indicates the impact of past academic difficulties on current performance. The weak correlations with study time and absences suggest that these factors have limited influence on final grades in this dataset.

Hypothesis Testing:

Null Hypothesis 1: Impact of Mother’s Education (Medu) on Student Performance

Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their mother’s education level (Medu).

Alternative Hypothesis (H1): There is a significant difference in the final grades (G3) of students based on their mother’s education level (Medu).

Null Hypothesis 2: Impact of Father’s Education (Fedu) on Student Performance

Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their father’s education level (Fedu).

Alternative Hypothesis (H1): There is a significant difference in the final grades (G3) of students based on their father’s education level (Fedu).

Null Hypothesis 3: Impact of Family Relationship Quality (famrel) on Student Performance

Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their family relationship quality (famrel).

Alternative Hypothesis (H1): There is a significant difference in the final grades (G3) of students based on their family relationship quality (famrel).

Null Hypothesis 4: Impact of Health (health) on Student Performance

Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their health status (health).

Alternative Hypothesis (H1): There is a significant difference in the final grades (G3) of students based on their health status (health).

These hypotheses aim to explore the influence of parental education, family relationship quality, and health status on students’ final grades. The null hypotheses state that there is no effect, while the alternative hypotheses suggest there is a significant impact.

The t.test for Null Hypothesis 1:

# Subset the data for different levels of Medu
G3_medu_0 <- my_data$G3[my_data$Medu == 0]
G3_medu_1 <- my_data$G3[my_data$Medu == 1]
G3_medu_2 <- my_data$G3[my_data$Medu == 2]
G3_medu_3 <- my_data$G3[my_data$Medu == 3]
G3_medu_4 <- my_data$G3[my_data$Medu == 4]

# Perform Welch's Two Sample t-tests
t_test_result_0_1 <- t.test(G3_medu_0, G3_medu_1)
t_test_result_0_2 <- t.test(G3_medu_0, G3_medu_2)
t_test_result_0_3 <- t.test(G3_medu_0, G3_medu_3)
t_test_result_0_4 <- t.test(G3_medu_0, G3_medu_4)

t_test_result_1_2 <- t.test(G3_medu_1, G3_medu_2)
t_test_result_1_3 <- t.test(G3_medu_1, G3_medu_3)
t_test_result_1_4 <- t.test(G3_medu_1, G3_medu_4)

t_test_result_2_3 <- t.test(G3_medu_2, G3_medu_3)
t_test_result_2_4 <- t.test(G3_medu_2, G3_medu_4)

t_test_result_3_4 <- t.test(G3_medu_3, G3_medu_4)

# Print the t-test results
print(t_test_result_0_1)
## 
##  Welch Two Sample t-test
## 
## data:  G3_medu_0 and G3_medu_1
## t = 2.0787, df = 2.3354, p-value = 0.1546
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -3.498781 12.142848
## sample estimates:
## mean of x mean of y 
## 13.000000  8.677966
print(t_test_result_0_2)
## 
##  Welch Two Sample t-test
## 
## data:  G3_medu_0 and G3_medu_2
## t = 1.5948, df = 2.214, p-value = 0.2398
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -4.785819 11.329508
## sample estimates:
## mean of x mean of y 
## 13.000000  9.728155
print(t_test_result_0_3)
## 
##  Welch Two Sample t-test
## 
## data:  G3_medu_0 and G3_medu_3
## t = 1.3135, df = 2.2216, p-value = 0.3082
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -5.344491 10.738431
## sample estimates:
## mean of x mean of y 
##  13.00000  10.30303
print(t_test_result_0_4)
## 
##  Welch Two Sample t-test
## 
## data:  G3_medu_0 and G3_medu_4
## t = 0.60785, df = 2.1414, p-value = 0.6015
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -6.985689  9.458972
## sample estimates:
## mean of x mean of y 
##  13.00000  11.76336
print(t_test_result_1_2)
## 
##  Welch Two Sample t-test
## 
## data:  G3_medu_1 and G3_medu_2
## t = -1.4404, df = 127.03, p-value = 0.1522
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.4929011  0.3925226
## sample estimates:
## mean of x mean of y 
##  8.677966  9.728155
print(t_test_result_1_3)
## 
##  Welch Two Sample t-test
## 
## data:  G3_medu_1 and G3_medu_3
## t = -2.2139, df = 127.71, p-value = 0.02861
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -3.0775011 -0.1726273
## sample estimates:
## mean of x mean of y 
##  8.677966 10.303030
print(t_test_result_1_4)
## 
##  Welch Two Sample t-test
## 
## data:  G3_medu_1 and G3_medu_4
## t = -4.5398, df = 109.63, p-value = 1.451e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -4.432321 -1.738464
## sample estimates:
## mean of x mean of y 
##  8.677966 11.763359
print(t_test_result_2_3)
## 
##  Welch Two Sample t-test
## 
## data:  G3_medu_2 and G3_medu_3
## t = -0.88223, df = 199.73, p-value = 0.3787
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.8598074  0.7100575
## sample estimates:
## mean of x mean of y 
##  9.728155 10.303030
print(t_test_result_2_4)
## 
##  Welch Two Sample t-test
## 
## data:  G3_medu_2 and G3_medu_4
## t = -3.4514, df = 210.04, p-value = 0.0006741
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -3.197630 -0.872777
## sample estimates:
## mean of x mean of y 
##  9.728155 11.763359
print(t_test_result_3_4)
## 
##  Welch Two Sample t-test
## 
## data:  G3_medu_3 and G3_medu_4
## t = -2.4511, df = 201.77, p-value = 0.01509
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.6350832 -0.2855737
## sample estimates:
## mean of x mean of y 
##  10.30303  11.76336

For the first t-test (G3_medu_0 vs. G3_medu_1) with a p-value of 0.1546, since 0.1546 > 0.05, that means fail to reject the null hypothesis.

For the second t-test (G3_medu_0 vs. G3_medu_2) with a p-value of 0.2398, since 0.2398 > 0.05, that means fail to reject the null hypothesis.

For the third t-test (G3_medu_0 vs. G3_medu_3) with a p-value of 0.3082, since 0.3082 > 0.05, that means fail to reject the null hypothesis.

For the fourth t-test (G3_medu_0 vs. G3_medu_4) with a p-value of 0.6015, since 0.6015 > 0.05, that means fail to reject the null hypothesis.

For the fifth t-test (G3_medu_1 vs. G3_medu_2) with a p-value of 0.1522, since 0.1522 > 0.05, that means fail to reject the null hypothesis.

For the sixth t-test (G3_medu_1 vs. G3_medu_3) with a p-value of 0.02861, since 0.02861 ≤ 0.05, that means reject the null hypothesis.

For the seventh t-test (G3_medu_1 vs. G3_medu_4) with a p-value of 1.451e-05, since 1.451e-05 ≤ 0.05, that means reject the null hypothesis.

For the eighth t-test (G3_medu_2 vs. G3_medu_3) with a p-value of 0.3787, since 0.3787 > 0.05, that means fail to reject the null hypothesis.

For the ninth t-test (G3_medu_2 vs. G3_medu_4) with a p-value of 0.0006741, since 0.0006741 ≤ 0.05, that means reject the null hypothesis.

For the tenth t-test (G3_medu_3 vs. G3_medu_4) with a p-value of 0.01509, since 0.01509 ≤ 0.05, that means reject the null hypothesis.

In summary, will reject the null hypothesis and conclude a significant difference in means for the comparisons between G3_medu_1 vs. G3_medu_3, G3_medu_1 vs. G3_medu_4, G3_medu_2 vs. G3_medu_4, and G3_medu_3 vs. G3_medu_4. For the other comparisons, there is not enough evidence to conclude a significant difference in means.

The t. test for the Null Hypothesis 4 (H0): There is no significant difference in the final grades (G3) of students based on their health status (health).

# Subset the data for different health groups
health_1 <- my_data$G3[my_data$health == 1]
health_2 <- my_data$G3[my_data$health == 2]
health_3 <- my_data$G3[my_data$health == 3]
health_4 <- my_data$G3[my_data$health == 4]

# Perform pairwise t-tests
t_test_1_2 <- t.test(health_1, health_2)
t_test_1_3 <- t.test(health_1, health_3)
t_test_1_4 <- t.test(health_1, health_4)
t_test_2_3 <- t.test(health_2, health_3)
t_test_2_4 <- t.test(health_2, health_4)
t_test_3_4 <- t.test(health_3, health_4)

# Print the t-test results
print(t_test_1_2)
## 
##  Welch Two Sample t-test
## 
## data:  health_1 and health_2
## t = 1.5918, df = 83.788, p-value = 0.1152
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.4113903  3.7116267
## sample estimates:
## mean of x mean of y 
##  11.87234  10.22222
print(t_test_1_3)
## 
##  Welch Two Sample t-test
## 
## data:  health_1 and health_3
## t = 2.4125, df = 89.914, p-value = 0.01787
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.3285218 3.3941810
## sample estimates:
## mean of x mean of y 
##  11.87234  10.01099
print(t_test_1_4)
## 
##  Welch Two Sample t-test
## 
## data:  health_1 and health_4
## t = 2.0228, df = 105.35, p-value = 0.04563
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.03495424 3.49760539
## sample estimates:
## mean of x mean of y 
##  11.87234  10.10606
print(t_test_2_3)
## 
##  Welch Two Sample t-test
## 
## data:  health_2 and health_3
## t = 0.22726, df = 69.999, p-value = 0.8209
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.642533  2.064999
## sample estimates:
## mean of x mean of y 
##  10.22222  10.01099
print(t_test_2_4)
## 
##  Welch Two Sample t-test
## 
## data:  health_2 and health_4
## t = 0.1144, df = 86.864, p-value = 0.9092
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.902167  2.134490
## sample estimates:
## mean of x mean of y 
##  10.22222  10.10606
print(t_test_3_4)
## 
##  Welch Two Sample t-test
## 
## data:  health_3 and health_4
## t = -0.12798, df = 126.91, p-value = 0.8984
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.565022  1.374879
## sample estimates:
## mean of x mean of y 
##  10.01099  10.10606

Interpret the results:

For the first t-test (health_1 vs. health_2) with a p-value of 0.1152, since 0.1152 > 0.05, that means fail to reject the null hypothesis.

For the second t-test (health_1 vs. health_3) with a p-value of 0.01787, since 0.01787 ≤ 0.05, that means reject the null hypothesis.

For the third t-test (health_1 vs. health_4) with a p-value of 0.04563, since 0.04563 ≤ 0.05, that means reject the null hypothesis.

Build visualizations that best illustrate the results from the two pairs of hypothesis tests(1 and 4), one for each null hypothesis.

# Box plot
ggplot(my_data, aes(x = as.factor(Medu), y = G3)) +
  geom_boxplot() +
  xlab("Mother Education Level") +
  ylab("Final Grades (G3)") +
  ggtitle("Distribution of Final Grades by Mother Education Level")

Based on the box plot, it appears that there is no substantial difference in the final grades (G3) of students based on their mother’s education level (Medu). For instance, in both the low and high levels of education, there are students with high G3 final grades, reaching up to 15 points. This suggests that maternal education level may not be a significant factor influencing students’ final grades.

# Box plot
ggplot(my_data, aes(x = as.factor(health), y = G3)) +
  geom_boxplot() +
  xlab("Health Status") +
  ylab("Final Grades (G3)") +
  ggtitle("Distribution of Final Grades by Health Status")

The box plot indicates that there is no significant variation in students’ final grades (G3) based on their health statuses. Both low and high health status categories exhibit students with high G3 scores, reaching up to 13 points, even in the case of minimum health status (1). This implies that health status may not play a significant role in determining students’ final grades.

Null hypotheses based on the final grade (G3) and other factors: study time, absences, previous failures, and previous grades.

Null Hypothesis 1: Impact of Study Time (studytime) on Student Performance

Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their study time (studytime).

Alternative Hypothesis (H1): There is a significant difference in the final grades (G3) of students based on their study time (studytime).

Null Hypothesis 2: Impact of Absences (absences) on Student Performance

Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their number of absences (absences).

Alternative Hypothesis (H1): There is a significant difference in the final grades (G3) of students based on their number of absences (absences).

Null Hypothesis 3: Impact of Previous Failures (failures) on Student Performance

Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their number of previous failures (failures).

Alternative Hypothesis (H1): There is a significant difference in the final grades (G3) of students based on their number of previous failures (failures).

Null Hypothesis 4: Impact of Previous Grades (G1 and G2) on Student Performance

Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their previous grades (G1 and G2).

Alternative Hypothesis (H1): There is a significant difference in the final grades (G3) of students based on their previous grades (G1 and G2).

These hypotheses aim to explore the influence of study time, absences, previous failures, and previous grades on students’ final grades. The null hypotheses state that there is no effect, while the alternative hypotheses suggest there is a significant impact.

Null Hypothesis 1:

Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their study time (studytime).

Alternative Hypothesis (H1): There is a significant difference in the final grades (G3) of students based on their study time (studytime).

Alpha Level (α): will choose alpha level of 0.05, because that means willing to accept a 5% chance of making a Type I error (incorrectly rejecting a true null hypothesis).

Power Level (1 - β): will choose a power level of 0.80, beacuse it is indicating an 80% chance of detecting a real effect. Will set 1 - β = 0.80.

Minimum Effect Size: a 1-hour increase in study time per week is significant for student performance, then the minimum effect size is 1 hours. Because that means a 1-hour increase in study time is considered practically significant and worth detecting.

Null Hypothesis 4:

Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their previous grades (G1 and G2).

Alternative Hypothesis (H1): There is a significant difference in the final grades (G3) of students based on their previous grades (G1 and G2).

Alpha Level (α): will choose α = 0.05.The alpha level (α) represents the probability of making a Type I error, which is the chance of incorrectly rejecting a true null hypothesis.When Setting α = 0.05 indicates a 5% risk of making this error.

Power Level (1 - β): will choose 1 - β = 0.80. A power level of 0.80 means there is an 80% probability of detecting a true effect. This value provides a good balance between detecting the effects and the risk of Type II errors.

Minimum Effect Size: a 1-point increase in the average of G1 and G2 is significant, then the minimum effect size is 5 points.It determined that a 1-point increase in the previous grades (G1 and G2) is meaningful and relevant to research question.

count_G3 <- my_data %>%
  group_by(studytime) %>%
  summarize(count_G3 = n()) %>%
  arrange(studytime)

count_G3
## # A tibble: 4 × 2
##   studytime count_G3
##       <int>    <int>
## 1         1      105
## 2         2      198
## 3         3       65
## 4         4       27
count_G3 <- my_data %>%
  group_by(failures) %>%
  summarize(count_G3 = n()) %>%
  arrange(failures)

count_G3
## # A tibble: 4 × 2
##   failures count_G3
##      <int>    <int>
## 1        0      312
## 2        1       50
## 3        2       17
## 4        3       16

For Null Hypothesis 1: Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their study time (studytime).

# Subset the data for different levels of studytime:
G3_studytime_1 <- my_data$G3[my_data$studytime == 1]
G3_studytime_2 <- my_data$G3[my_data$studytime == 2]
G3_studytime_3 <- my_data$G3[my_data$studytime == 3]
G3_studytime_4 <- my_data$G3[my_data$studytime == 4]

# Perform Welch's Two Sample t-tests for study time groups
t_test_result_1_2 <- t.test(G3_studytime_1, G3_studytime_2)
t_test_result_1_3 <- t.test(G3_studytime_1, G3_studytime_3)
t_test_result_1_4 <- t.test(G3_studytime_1, G3_studytime_4)

t_test_result_2_3 <- t.test(G3_studytime_2, G3_studytime_3)
t_test_result_2_4 <- t.test(G3_studytime_2, G3_studytime_4)

t_test_result_3_4 <- t.test(G3_studytime_3, G3_studytime_4)

# Print the t-test results
print(t_test_result_1_2)
## 
##  Welch Two Sample t-test
## 
## data:  G3_studytime_1 and G3_studytime_2
## t = -0.21809, df = 184.82, p-value = 0.8276
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.2467170  0.9985207
## sample estimates:
## mean of x mean of y 
##  10.04762  10.17172
print(t_test_result_1_3)
## 
##  Welch Two Sample t-test
## 
## data:  G3_studytime_1 and G3_studytime_3
## t = -1.799, df = 142.58, p-value = 0.07413
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.8383682  0.1336063
## sample estimates:
## mean of x mean of y 
##  10.04762  11.40000
print(t_test_result_1_4)
## 
##  Welch Two Sample t-test
## 
## data:  G3_studytime_1 and G3_studytime_4
## t = -1.0764, df = 38.615, p-value = 0.2884
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -3.489111  1.065831
## sample estimates:
## mean of x mean of y 
##  10.04762  11.25926
print(t_test_result_2_3)
## 
##  Welch Two Sample t-test
## 
## data:  G3_studytime_2 and G3_studytime_3
## t = -1.8931, df = 101.02, p-value = 0.06121
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.51539929  0.05883363
## sample estimates:
## mean of x mean of y 
##  10.17172  11.40000
print(t_test_result_2_4)
## 
##  Welch Two Sample t-test
## 
## data:  G3_studytime_2 and G3_studytime_4
## t = -1.0263, df = 30.688, p-value = 0.3128
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -3.249608  1.074524
## sample estimates:
## mean of x mean of y 
##  10.17172  11.25926
print(t_test_result_3_4)
## 
##  Welch Two Sample t-test
## 
## data:  G3_studytime_3 and G3_studytime_4
## t = 0.1205, df = 43.524, p-value = 0.9046
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.213899  2.495380
## sample estimates:
## mean of x mean of y 
##  11.40000  11.25926

G3_studytime_1 vs. G3_studytime_2: t = -0.21809 p-value = 0.8276 The p-value (0.8276) is higher than the significance level (usually 0.05), indicating no significant difference in final grades between these study time categories.

G3_studytime_1 vs. G3_studytime_3: t = -1.799 p-value = 0.07413 The p-value (0.07413) is slightly above 0.05, suggesting weak evidence against the null hypothesis.

G3_studytime_1 vs. G3_studytime_4: t = -1.0764 p-value = 0.2884 The p-value (0.2884) is higher than 0.05, indicating no significant difference in final grades between these study time categories.

G3_studytime_2 vs. G3_studytime_3: t = -1.8931 p-value = 0.06121 The p-value (0.06121) is slightly above 0.05, suggesting weak evidence against the null hypothesis.

G3_studytime_2 vs. G3_studytime_4: t = -1.0263 p-value = 0.3128 The p-value (0.3128) is higher than 0.05, indicating no significant difference in final grades between these study time categories.

G3_studytime_3 vs. G3_studytime_4: t = 0.1205 p-value = 0.9046 The p-value (0.9046) is much higher than 0.05, indicating no significant difference in final grades between these study time categories.

In summary, based on these t-tests and the chosen significance level, there is only weak evidence against the null hypothesis in the comparison between G3_studytime_1 and G3_studytime_3, as well as G3_studytime_2 and G3_studytime_3, in all there is no significant difference in final grades between the study time categories.

For Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their number of previous failures (failures).

# Subset the data for different levels of failures:
G3_failures_0 <- my_data$G3[my_data$failures == 0]
G3_failures_1 <- my_data$G3[my_data$failures == 1]
G3_failures_2 <- my_data$G3[my_data$failures == 2]
G3_failures_3 <- my_data$G3[my_data$failures == 3]

# Perform Welch's Two Sample t-tests for failures groups
t_test_result_0_1 <- t.test(G3_failures_0, G3_failures_1)
t_test_result_0_2 <- t.test(G3_failures_0, G3_failures_2)
t_test_result_0_3 <- t.test(G3_failures_0, G3_failures_3)

t_test_result_1_2 <- t.test(G3_failures_1, G3_failures_2)
t_test_result_1_3 <- t.test(G3_failures_1, G3_failures_3)
t_test_result_2_3 <- t.test(G3_failures_2, G3_failures_3)

# Print the t-test results
print(t_test_result_0_1)
## 
##  Welch Two Sample t-test
## 
## data:  G3_failures_0 and G3_failures_1
## t = 4.4332, df = 61.924, p-value = 3.869e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  1.720375 4.546035
## sample estimates:
## mean of x mean of y 
##  11.25321   8.12000
print(t_test_result_0_2)
## 
##  Welch Two Sample t-test
## 
## data:  G3_failures_0 and G3_failures_2
## t = 4.1894, df = 17.318, p-value = 0.0005937
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  2.494398 7.541424
## sample estimates:
## mean of x mean of y 
## 11.253205  6.235294
print(t_test_result_0_3)
## 
##  Welch Two Sample t-test
## 
## data:  G3_failures_0 and G3_failures_3
## t = 5.1824, df = 16.56, p-value = 8.14e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  3.295258 7.836152
## sample estimates:
## mean of x mean of y 
##  11.25321   5.68750
print(t_test_result_1_2)
## 
##  Welch Two Sample t-test
## 
## data:  G3_failures_1 and G3_failures_2
## t = 1.396, df = 27.042, p-value = 0.1741
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.8852026  4.6546144
## sample estimates:
## mean of x mean of y 
##  8.120000  6.235294
print(t_test_result_1_3)
## 
##  Welch Two Sample t-test
## 
## data:  G3_failures_1 and G3_failures_3
## t = 1.9592, df = 28.171, p-value = 0.06005
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.110001  4.975001
## sample estimates:
## mean of x mean of y 
##    8.1200    5.6875
print(t_test_result_2_3)
## 
##  Welch Two Sample t-test
## 
## data:  G3_failures_2 and G3_failures_3
## t = 0.34809, df = 30.796, p-value = 0.7301
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.662660  3.758249
## sample estimates:
## mean of x mean of y 
##  6.235294  5.687500

Based on the provided Welch Two Sample t-tests for different levels of failures (failures 0, 1, 2, and 3) and their corresponding final grades (G3).

** interpret the results for each comparison:

G3_failures_0 vs. G3_failures_1: t = 4.4332, p-value = 3.869e-05 The p-value is significantly less than 0.05, indicating strong evidence against the null hypothesis. We reject the null hypothesis and conclude that there is a significant difference in mean final grades between students with 0 failures and students with 1 failure.

G3_failures_0 vs. G3_failures_2: t = 4.1894, p-value = 0.0005937

The p-value is significantly less than 0.05, indicating strong evidence against the null hypothesis. We reject the null hypothesis and conclude that there is a significant difference in mean final grades between students with 0 failures and students with 2 failures.

G3_failures_0 vs. G3_failures_3: t = 5.1824, p-value = 8.14e-05

The p-value is significantly less than 0.05, indicating strong evidence against the null hypothesis. We reject the null hypothesis and conclude that there is a significant difference in mean final grades between students with 0 failures and students with 3 failures.

G3_failures_1 vs. G3_failures_2: t = 1.396, p-value = 0.1741 The p-value is higher than 0.05, indicating lack of strong evidence against the null hypothesis. We do not reject the null hypothesis, suggesting no significant difference in mean final grades between students with 1 failure and students with 2 failures.

G3_failures_1 vs. G3_failures_3: t = 1.9592, p-value = 0.06005 The p-value is slightly higher than 0.05 ,it might suggest a potential difference in mean finalgrades between students with 1 failure and students with 3 failures, but it’s not strongly significant.

G3_failures_2 vs. G3_failures_3: t = 0.34809, p-value = 0.7301 The p-value is significantly higher than 0.05, indicating lack of evidence against the null hypothesis. We do not reject the null hypothesis, suggesting no significant difference in mean final grades between students with 2 failures and students with 3 failures.

In summary, based on the provided t-tests, there is strong evidence to suggest significant differences in mean final grades between students with 0 failures and those with 1, 2, or 3 failures. The comparison between students with 1 failure and 3 failures shows a result that is close to the significance threshold.

Perform a Fisher’s style test for significance, and interpret the p-value.For Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their number of previous failures (failures).

# Create a contingency table
contingency_table <- table(my_data$G3, my_data$studytime)

# Perform Fisher's exact test with simulation
fisher_test_result <- fisher.test(contingency_table, simulate.p.value = TRUE, B = 10000)

# Print the test result
print(fisher_test_result)
## 
##  Fisher's Exact Test for Count Data with simulated p-value (based on
##  10000 replicates)
## 
## data:  contingency_table
## p-value = 0.3089
## alternative hypothesis: two.sided

Output Interpretation:

p-value = 0.2964:suggests there is no true association between ‘G3’ and ‘study time’.

In summary, the result suggests that there is no significant association between the final grades (G3) and the different levels of study time.

Perform a Fisher’s style test for significance, and interpret the p-value. For Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their number of previous failures (failures).

# Create a contingency table
contingency_table <- table(my_data$G3, my_data$failures)

# Perform Fisher's exact test with simulation
fisher_test_result <- fisher.test(contingency_table, simulate.p.value = TRUE, B = 10000)

# Print the test result
print(fisher_test_result)
## 
##  Fisher's Exact Test for Count Data with simulated p-value (based on
##  10000 replicates)
## 
## data:  contingency_table
## p-value = 9.999e-05
## alternative hypothesis: two.sided

Output Interpretation:

p-value = 9.999e-05: In this case, the p-value is extremely small (9.999e-05 or 0.00009999). This small p-value indicates that there is very strong evidence against the null hypothesis.

In summary, the test results suggest that there is a significant relationship between the final grades of students and the number of failures they have. Students with different numbers of failures tend to have significantly different final grades, based on the data analysis.

Build two visualizations that best illustrate the results from the two pairs of hypothesis tests, one for each null hypothesis.

Visualization for Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their number of previous failures (failures).

# Box plot for G3 and failures
ggplot(my_data, aes(x = as.factor(failures), y = G3)) +
  geom_boxplot() +
  xlab("Number of Failures") +
  ylab("Final Grades (G3)") +
  ggtitle("Distribution of Final Grades by Number of Failures")

The box plot reveals a clear and significant relationship between students’ final grades and the number of failures they have. Students with no failures consistently achieve higher final grades, whereas those with more failures tend to attain lower final grades.

Visualization for Null Hypothesis (H0): There is no significant difference in the final grades (G3) of students based on their study time (studytime).

# Box plot based on G3 and studytime
ggplot(my_data, aes(x = as.factor(studytime), y = G3)) +
  geom_boxplot() +
  xlab("Study Time") +
  ylab("Final Grades (G3)") +
  ggtitle("Distribution of Final Grades by Study Time")

The box plot shows no significant association between final grades (G3) and the different levels of study time. The results are very similar across students with varying study hours, indicating that the time spent studying does not strongly correlate with their final grade.

Linear Regression Model:

# Build a linear regression model
lm_model <- lm(G3 ~ Pstatus + paid + Walc + Dalc, data = my_data)
# Display the summary of the model
summary(lm_model)
## 
## Call:
## lm(formula = G3 ~ Pstatus + paid + Walc + Dalc, data = my_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.1050  -1.8929   0.1101   2.9996   9.9009 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  11.3965     0.8531  13.359   <2e-16 ***
## PstatusT     -0.9643     0.7541  -1.279   0.2018    
## paidyes       1.0059     0.4622   2.176   0.0301 *  
## Walc         -0.1046     0.2344  -0.446   0.6556    
## Dalc         -0.2285     0.3391  -0.674   0.5008    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.561 on 390 degrees of freedom
## Multiple R-squared:  0.01886,    Adjusted R-squared:  0.008793 
## F-statistic: 1.874 on 4 and 390 DF,  p-value: 0.1142

Created the linear regression model and indicates that the response variable is G3, and the predictor variables are Pstatus, paid, Walc, and Dalc from the dataset.

The summarize, the model does not seem to have a strong explanatory power based on the variables (Pstatus, paid, Walc, and Dalc), as indicated by the low R-squared values and non-significant coefficients for most predictors. This means that these variables do not provide a strong linear relationship with the final grade (G3).

plot(lm_model, which = 1)

plot(lm_model, which = 2)

In the Residuals vs. Fitted Values plot, I noticed that the data points deviate both above and below the horizontal line. However, on the Normal Q-Q plot, most of the points closely follow the diagonal line, suggesting that the residuals approximately follow a normal distribution. The line in the Q-Q plot represents the expected distribution of the residuals, and the data points indicates a good fit to a normal distribution.

lm_model <- lm(G3 ~ Pstatus + paid + Walc + Dalc, data = my_data)
summary(lm_model)
## 
## Call:
## lm(formula = G3 ~ Pstatus + paid + Walc + Dalc, data = my_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.1050  -1.8929   0.1101   2.9996   9.9009 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  11.3965     0.8531  13.359   <2e-16 ***
## PstatusT     -0.9643     0.7541  -1.279   0.2018    
## paidyes       1.0059     0.4622   2.176   0.0301 *  
## Walc         -0.1046     0.2344  -0.446   0.6556    
## Dalc         -0.2285     0.3391  -0.674   0.5008    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.561 on 390 degrees of freedom
## Multiple R-squared:  0.01886,    Adjusted R-squared:  0.008793 
## F-statistic: 1.874 on 4 and 390 DF,  p-value: 0.1142

Interpret the coefficient for the paid_yes(Student get extra paid classes outside of the school) variable in the given linear regression model:

The estimate for paidyes is 1.0059. This means that students who receive extra educational support have a final grade (G3) that is approximately 1.0059 units higher than students who do not receive extra educational support.

The t-value for paidyes is 2.176. A larger t-value indicates that the coefficient is more significant.

The p-value for paidyes is 0.0301 and since the p-value is less than the significance level of 0.05, that menas we have evidence to reject the null hypothesis. Therefore, the paidyes variable is statistically significant in predicting the final grade.

The positive coefficient for paidyes indicates that students who receive extra educational support tend to have higher final grades compared to students who do not receive such support. This suggesting that the provision of extra educational support has a positive impact on students’ academic performance.

Interpret the coefficient for the PstatusT variable in the given linear regression model:

The estimate for PstatusT is -0.9643. This means that, on average, students whose parents are not living together (PstatusT = 1) have final grades (G3) that are approximately 0.9643 units lower than students whose parents are living together.

The t-value for PstatusT is -1.279. Since the t-value is relatively small, that means the coefficient for PstatusT is not statistically significant.

The p-value associated with PstatusT is 0.2018. Since the p-value (0.2018) is larger than significance level of 0.05, we do not have enough evidence to reject the null hypothesis. Therefore, the PstatusT variable is not statistically significant in predicting the final grade.

The non-significant coefficient for PstatusT suggests that the parent status (PstatusT) does not have a statistically significant impact on students’ final grades.