#statistical modeling
getwd()
list.files()
if (!requireNamespace(“ggplot2”, quietly = TRUE)) { install.packages(“ggplot2”) } if (!requireNamespace(“dplyr”, quietly = TRUE)) { install.packages(“dplyr”) }
library(ggplot2) library(dplyr)
pdf(“student_enrollment_analysis.pdf”, width = 8, height = 6)
enrollment_data <- read.csv(“enrollmentForecast.csv”)
print(str(enrollment_data)) print(summary(enrollment_data))
ggplot(enrollment_data, aes(x = UNEM, y = ROLL)) + geom_point() + labs(title = “Enrollment vs. Unemployment Rate”, x = “Unemployment Rate (%)”, y = “Enrollment”)
ggplot(enrollment_data, aes(x = HGRAD, y = ROLL)) + geom_point() + labs(title = “Enrollment vs. High School Graduates”, x = “High School Graduates”, y = “Enrollment”)
ggplot(enrollment_data, aes(x = INC, y = ROLL)) + geom_point() + labs(title = “Enrollment vs. Per Capita Income”, x = “Per Capita Income ($1961)”, y = “Enrollment”)
fit_enrollment <- lm(ROLL ~ UNEM + HGRAD, data = enrollment_data)
print(summary(fit_enrollment))
print(anova(fit_enrollment))
plot(fit_enrollment, which = 1)
new_data <- data.frame(UNEM = 9, HGRAD = 25000) predicted_enrollment <- predict(fit_enrollment, new_data) print(predicted_enrollment)
fit_enrollment_with_income <- lm(ROLL ~ UNEM + HGRAD + INC, data = enrollment_data)
print(anova(fit_enrollment, fit_enrollment_with_income))
dev.off()
#To see if per capita incone improves the model, we use the ANOVA funciton to compare the two models: one without per captia income and one with. The ANOVA showed the following:The model without per capita income only includes the unemployment rate and the number of high school graduates as predictors for fall enrollment. The model with per capita income includes the per capita income, unemployment rate, and the number of highschool graduates as predictors for fall enrollment. When comparing these models using ANNOVA, looking at the f-statistics and the p-value to asses whether the inclusion of the additional variable significantly improves the model. If the ANNOVA shows a low p-value (typically 0.005) it means that including per capita income significantly improves the model. This suggests that the per captia income is a valuable predictor variable for enrollment. If the p-value is high, it means the per capita income is not a valuable predictor variable.