library(rio)
sm.pa <- import("https://github.com/marctrussler/IIS-Data/raw/main/PAFinalWeeks.csv")Problem Set 4
Problem Set Due XXXXXXXX at 7pm on Canvas.
You will hand in a .Rmd file and a knitted html output.
I have provided the raw RMD of this problem set you can use as a template for answering.
For this problem set we are going to use the SurveyMonkey data on Pennsylvania voters from the last two weeks before the 2022 election. While this is not a perfect random sample of Pennsylvanians (or of PA voters, in particular), we can pretend like it is for the purposes of this assignment.
We are going to investigate the variable predicted.vote.prob. This is a variable that we generated which gives each individual in the data set a probability of voting from 0 to 1 based on their demographics and stated likelihood of voting.
Without using the
t.test()function, perform the 5-step hypothesis test discussed in class on the null hypothesis that those who identify as Democrats and Republicans have equal predicted probabilities of voting. (This is a two-tailed test. So you don’t have to calculate it with a terrible equation, the degrees of freedom for the t-test will be 3543.9.) Confirm your calculated answer using thet.test()function.Assume that the difference in the predicted probability of turning out in Democrats vs. Republicans (about 3.2%) is the truth in the population. Using the methodology from class, visualize and calculate \(\beta\), the probability of a false negative, for the hypothesis test from (1). Similar to what I did in class, you can assume (for this question, not above) that the sampling distribution of the difference in means is normally distributed, as opposed to \(t\) distributed. Describe briefly what you see in your visualization and how it relates to your calculated \(\beta\).
Having seen the results of (2), I might be concerned that I have wasted my money getting so many respondents. Calculate and visualize \(\beta\) for sample sizes ranging from 100 to 10000. Eye-balling it, what sample size would result in a \(\beta\) of 20%? You can again assume that the difference of means in the sample is representative of the true population difference in means. You can further assume that the sample variances for each of the groups is representative of the true variances in the population. Finally, for simplicity assume that each sample is 50/50 Democrats and Republicans.
We now want to investigate the relationship between
ageandpredicted.vote.prob. Create a scatter-plot withageon the x-axis andpredicted.vote.probon the y-axis. Briefly describe what you see.Without using the
cov()andcor()functions, calculate the covariance and correlation ofageandpredicted.vote.prob. Confirm your answers using thecov()andcor()functions. In political terms, what do these numbers mean?Is the correlation you found in (5) statistically distinguishable from 0? Use the bootstrap to generate a sampling distribution around this correlation, and determine the 95% confidence interval using the
quantile()function.We can summarize the same relationship using regression.
Calculate the slope and intercept of the regression \(\hat{predicted.vote.prob} = \hat{\alpha} + \hat{\beta} \; age_i\) without using the
lm()function. Confirm your results using thelm()function. Interpret these values, and interpret the hypothesis test being performed on \(\hat{\beta}\).Create a new variable that measures age in decades, re-estimate the regression (with
lm()) using it, and re-interpret the slope. Is this relationship now larger?