Question 5
unknown
plain_text
2 years ago
1.9 kB
6
Indexable
```{r} #| message: false #| warning: false modelq5 <- lm(nazivote/nvoter ~ other, nazisdata) modelq5_pred <- expand.grid( other = seq(from = 0, to = 1, by = .01), nazivote = nazisdata$nazivote) modelq5_pred$nazivote = predict(modelq5, newdata = modelq5_pred) conf_interval2 <- predict(modelq5, newdata = modelq5_pred, interval = "confidence", level = 0.95) merged_predict2 <- cbind(conf_interval2, modelq5_pred) merged_predict2$bad_case <- 1 - merged_predict2$lwr merged_predict2$good_case <- 1 - merged_predict2$upr ggplot(merged_predict2, aes(x = other, y = bad_case)) + geom_line() + labs( title = "Min. nº of blue-collars vote for nazis", x = "Other workers", y = "Blue collar" ) + theme_bw() + theme(plot.title = element_text(hjust = 0.5)) ggplot(merged_predict2, aes(x = other, y = good_case)) + geom_line() + labs( title = "Max. nº of blue-collars vote for nazis", x = "Other workers", y = "Blue collar" ) + theme_bw() + theme(plot.title = element_text(hjust = 0.5)) ``` ```{r} #| message: false #| warning: false denominator <- sum(nazisdata$nazivote * nazisdata$shareblue) average_mean <- (nazisdata$nazivote* nazisdata$shareblue) / denominator nazisdata$average_mean <- average_mean modelq52 <- lm(nazivote/nvoter ~ average_mean, nazisdata) modelq52_pred <- expand.grid( other = seq(from = 0, to = 1, by = .01), nazivote = nazisdata$nazivote) modelq52_pred$nazivote = predict(modelq52, newdata = modelq52_pred) conf_interval3 <- predict(modelq52, newdata = modelq52_pred, interval = "confidence", level = 0.95) lower_bound <- conf_interval3[, "lwr"] upper_bound <- conf_interval3[, "upr"] min_lower_bound <- min(lower_bound) max_upper_bound <- max(upper_bound) min_lower_bound max_upper_bound ```
Editor is loading...
Leave a Comment