year_levels <- c("Freshman", "Sophomore", "Junior", "Senior", "Graduate",
"1st Year", "2nd Year", "3rd Year", "4th Year")
skill_levels <- c("Beginner", "Intermediate", "Advanced")
burnout_levels <- c("Low", "Medium", "Moderate", "High", "Very High")
clean_df <- raw_df |>
rename_with(tolower) |>
mutate(
# Engineer learning analytics metrics
gpa_change = post_semester_gpa - pre_semester_gpa,
total_study_hours = weekly_genai_hours + traditional_study_hours,
ai_study_share = if_else(total_study_hours > 0, weekly_genai_hours / total_study_hours, 0),
# Clean underscores in categorical labels for cleaner plots
primary_use_case = str_replace_all(primary_use_case, "_", " "),
institutional_policy = str_replace_all(institutional_policy, "_", " "),
# Apply logical factor ordering
year_of_study = if (length(intersect(year_levels, unique(year_of_study))) > 0) {
factor(year_of_study, levels = intersect(year_levels, unique(year_of_study)))
} else {
factor(year_of_study)
},
prompt_engineering_skill = if (length(intersect(skill_levels, unique(prompt_engineering_skill))) > 0) {
factor(prompt_engineering_skill, levels = intersect(skill_levels, unique(prompt_engineering_skill)))
} else {
factor(prompt_engineering_skill)
},
burnout_risk_level = if (length(intersect(burnout_levels, unique(burnout_risk_level))) > 0) {
factor(burnout_risk_level, levels = intersect(burnout_levels, unique(burnout_risk_level)))
} else {
factor(burnout_risk_level)
}
)
# Preview engineered features
clean_df |>
select(student_id, primary_use_case, pre_semester_gpa, post_semester_gpa,
gpa_change, total_study_hours, ai_study_share) |>
head(6) |>
kable(digits = 2, caption = "Preview of Engineered Learning Analytics Variables")