library(devtools) library(anesr) library(tidyverse) library(haven)

data(pilot_2016)

preview structure

names(pilot_2016)[1:15] nrow(pilot_2016) str(pilot_2016$pid7) # Party ID variable pilot_2016_clean <- pilot_2016 %>% filter(!is.na(pid7) & pid7 != 8) # 8 = Not sure (per codebook)

table(pilot_2016_clean$pid7) ggplot(data = pilot_2016_clean) + geom_bar(aes(x = factor(pid7))) + scale_x_discrete(labels = c(“Strong Dem”, “Weak Dem”, “Lean Dem”, “Independent”, “Lean Rep”, “Weak Rep”, “Strong Rep”)) + theme_bw() + xlab(“Party Identification”) + ylab(“Count”) + ggtitle(“ANES 2016 Pilot – Party ID Distribution”) set.seed(200230)

libcon <- rnorm(1000, mean = 4.5, sd = 1.1) views_college <- 50 - 2.4 * libcon + rnorm(1000, 0, 2.5)

toydata <- data.frame(libcon, views_college)

ggplot(toydata, aes(x = libcon, y = views_college)) + geom_point() + geom_smooth(method = lm, se = FALSE, linetype = “dashed”) + theme_bw() + xlab(“Liberal-Conservative Self Placement”) + ylab(“Attitudes toward College”) + ggtitle(“Ideology and Attitudes toward College (Simulated Data)”) mean(toydata$libcon)

toydata\(libcon[100] <- NA mean(toydata\)libcon, na.rm = TRUE)

summary(toydata$libcon) set.seed(200230) # same seed as above libcon2 <- rnorm(1000, mean = 4.5, sd = 1.1)

ggplot(data.frame(libcon2), aes(x = libcon2)) + geom_histogram(binwidth = 0.2, fill = “skyblue”, color = “black”) + geom_vline(xintercept = 4.5, color = “black”) + geom_vline(xintercept = c(3.4, 5.6), color = “red”) + geom_vline(xintercept = c(2.3, 6.7), color = “blue”) + geom_vline(xintercept = c(1.2, 7.8), color = “darkgreen”) + theme_bw() + ggtitle(“Normal Distribution with Mean and SD Boundaries”)