请写一段代码,回答问题:
- User
请写一段代码,回答问题:
- Assistant
抱歉,你需要提供问题的具体内容才能编写相应的代码来回答。请提供更多细节和要求。
- User
The data awards.csv contains the number of awards earned by students at one high school. We consider two predictors: • prog: the type of program in which the student is enrolled (3 categories of general, academic or vocational). • math: a continuous variable representing students’ scores on their math final exam. Use the following to load data and address the questions using Poisson regression. awards <- read.csv('awards.csv') awardsprog, levels=c("General","Academic","Vocational"))
- Assistant
# Load the data awards <- read.csv('awards.csv') # Convert 'prog' variable to factor with specified levels awards$prog <- factor(awards$prog, levels=c("General","Academic","Vocational")) # 1. Check if mean is roughly equal to variance for each program type means <- tapply(awards$num_awards, awards$prog, mean) variances <- tapply(awards$num_awards, awards$prog, var) mean_equal_to_variance <- abs(means - variances) < 0.001 print(mean_equal_to_variance) # 2. Compare model_1 and model_2 using anova test model_1 <- glm(num_awards ~ math + prog, data=awards, family=poisson()) model_2 <- glm(num_awards ~ math, data=awards, family=poisson()) anova_test <- anova(model_2, model_1, test='Chisq') print(anova_test) # 3. Predict the number of awards for an academic program with math score 90 compared to general program academic_program <- data.frame(math=90, prog="Academic") general_program <- data.frame(math=90, prog="General") academic_predictions <- predict(model_1, newdata=academic_program, type="response") general_predictions <- predict(model_1, newdata=general_program, type="response") expected_difference <- academic_predictions - general_predictions print(expected_difference)