R.project.Student
PART A: Introducing the Dataset
Data Source and Explanation
For this project, we are analyzing the “Student Habits and Performance” dataset. This dataset contains records for 1000 students and includes variables that capture demographics, academic habits, lifestyle factors, and academic performance measured by exam_score. Our main goal is to explore how these daily habits and lifestyle choices impact a student’s final exam score.
Descriptive Statistics
First, we load the required libraries, import our dataset, and examine its general structure and descriptive statistics.
```{r setup, message=FALSE, warning=FALSE} # Load necessary libraries library(tidyverse) library(rstatix) library(ggplot2)
Load the dataset
df <- read_csv(“C:/Users/yozca/OneDrive/Belgeler/Student111/student_habits_performance.csv”)
Display descriptive statistics for numerical variables
get_summary_stats(df, type = “common”)
df_clean <- df %>% mutate( mental_health_rating = factor(mental_health_rating, ordered = TRUE), exercise_frequency = factor(exercise_frequency, ordered = TRUE), exam_status = ifelse(exam_score >= 50, “Pass”, “Fail”), exam_status = factor(exam_status, levels = c(“Fail”, “Pass”)) )
H1 Data
h1_data <- df_clean %>% select(student_id, gender, exam_score) %>% filter(gender %in% c(“Male”, “Female”))
H4 Data
h4_data <- df_clean %>% select(part_time_job, attendance_percentage) %>% filter(!is.na(part_time_job))
H5 Data
h5_data <- df_clean %>% filter(!is.na(parental_education_level)) %>% select(parental_education_level, exam_score)
Summary Stats for H1 (Gender)
h1_stats <- h1_data %>% group_by(gender) %>% get_summary_stats(exam_score, type = “common”) print(h1_stats)
Frequency Table for H2 (Diet Quality)
h2_freq <- df_clean %>% freq_table(diet_quality) print(h2_freq)
Summary Stats for H4 (Part-Time Job)
h4_stats <- h4_data %>% group_by(part_time_job) %>% get_summary_stats(attendance_percentage, type = “robust”) print(h4_stats)
Frequency Table for H5 (Parental Education)
h5_freq <- h5_data %>% freq_table(parental_education_level) print(h5_freq)
Scatter plot demonstrating color, shape, and facet_wrap
df_plot_h3 <- df_clean %>% mutate(study_intensity = ifelse(study_hours_per_day >= 4, “Heavy”, “Light”))
ggplot(df_plot_h3, aes(x = study_hours_per_day, y = exam_score, color = gender, shape = part_time_job)) + geom_point(alpha = 0.7, size = 3) + facet_wrap(~ study_intensity, scales = “free_x”) + scale_color_manual(values = c(“Female” = “#E69F00”, “Male” = “#56B4E9”)) + labs(title = “Impact of Study Hours on Exam Scores by Intensity”, x = “Study Hours per Day”, y = “Exam Score”, color = “Gender”, shape = “Part-Time Job”) + theme_minimal()
Boxplot demonstrating fill and facet_grid
ggplot(h5_data, aes(x = parental_education_level, y = exam_score, fill = parental_education_level)) + geom_boxplot(alpha = 0.8) + facet_grid(. ~ h5_data %>% pull(parental_education_level) %>% is.na() == FALSE) + labs(title = “Exam Scores by Parental Education Level”, x = “Parental Education Level”, y = “Exam Score”, fill = “Education Level”) + theme_bw() + theme(axis.text.x = element_text(angle = 45, hjust = 1)) ### Plot 3: Diet Quality vs. Exam Scores (Hypothesis 2 with ggpubr) For our ANOVA hypothesis regarding diet quality, we utilize the ggpubr package to create publication-ready plots. We add color and shape aesthetics based on gender, and facet the plots by whether the student has a part-time job. We also directly embed the ANOVA p-value into the plot for immediate statistical interpretation.
Load the required package
library(ggpubr)
Create a boxplot with ggpubr using color, shape, and facet.by
A 3-color palette is used to accommodate all gender categories in the dataset
h2_ggpubr <- ggboxplot( df_clean, x = “diet_quality”, y = “exam_score”, color = “gender”, shape = “gender”, palette = c(“#00AFBB”, “#E7B800”, “#FC4E07”), facet.by = “part_time_job”,
add = “jitter”,
short.panel.labs = FALSE ) + stat_compare_means(method = “anova”, label.y = 110) + labs( title = “Effect of Diet Quality on Exam Scores”, subtitle = “Faceted by Part-Time Job Status, colored by Gender”, x = “Diet Quality”, y = “Exam Score” )
print(h2_ggpubr)
Formal Hypothesis Testing and Interpretation
In this final section, we conduct formal statistical tests for each of our five hypotheses using the rstatix package. We will evaluate the \(p\)-values against a standard significance level of \(\alpha = 0.05\).
Testing H1: Gender vs. Exam Scores (Independent t-test)
Running an independent samples t-test
res_h1 <- df_clean %>% filter(gender %in% c(“Male”, “Female”)) %>% t_test(exam_score ~ gender)
print(res_h1)
Running a one-way ANOVA test
res_h2 <- df_clean %>% anova_test(exam_score ~ diet_quality)
print(res_h2)
Running a Pearson correlation test
res_h3 <- df_clean %>% cor_test(study_hours_per_day, exam_score, method = “pearson”)
print(res_h3)
Running an independent samples t-test for attendance
res_h4 <- df_clean %>% filter(!is.na(part_time_job)) %>% t_test(attendance_percentage ~ part_time_job)
print(res_h4)
Running a one-way ANOVA test
res_h5 <- h5_data %>% anova_test(exam_score ~ parental_education_level)
print(res_h5)