In: Statistics and Probability
Question 4. Your friend Joanna is running for class president and has the support of 55% of the total student body. You poll a group of N students (N=50 or N=150) and compute the total number of students who state that they will vote for Joanna. For samples of size N=50 or N=150, use R to simulate 10,000 independent samples and record the total votes for Joanna in each sample. For each sample, compute a Z-score test statistic for the specified null hypothesis and α given below.
Compute the following (a-f) for both N=50 and N=150 separately.
a) Plot a histogram of the resulting Z-score distribution under H0: p=0.55. Based on a rejection region of |Z|>1.96, does the simulated Type I error probability match the expected Type I error probability (α).
b) Plot a histogram of the resulting Z-score distribution under H0: p=0.6. Based on a rejection region of |Z|>1.96, does the simulated Type II error probability match the expected Type II error probability. You will need to compute the expected Type II error probability (β).
c) Plot a histogram of the resulting Z-score distribution under H0: p=0.65. Based on a rejection region of |Z|>1.96, does the simulated Type II error probability match the expected Type II error probability. You will need to compute the expected Type II error probability (β).
d) Plot a histogram of the resulting Z-score distribution under H0: p=0.55. Based on a rejection region of |Z|>2.575, does the simulated Type I error probability match the expected Type I error probability (α).
e) Plot a histogram of the resulting Z-score distribution under H0: p=0.6. Based on a rejection region of |Z|>2.575, does the simulated Type II error probability match the expected Type II error probability. You will need to compute the expected Type II error probability (β).
f) Plot a histogram of the resulting Z-score distribution under H0: p=0.65. Based on a rejection region of |Z|>2.575, does the simulated Type II error probability match the expected Type II error probability. You will need to compute the expected Type II error probability (β).
g) What factors (N, α, |?0−??|) (if any) influence the Type I error probability? Explain.
h) What factors (N, α, |?0−??|) (if any) influence the Type II error probability? Explain.
rm(list=ls(all=TRUE)) N=50; x=c(0,1) #Here 1=Jaonna get vote and 0=not vote s=0; votes=0 for(i in 1:10000) { s=sample(x,N,replace = TRUE) votes[i]=sum(s) } length(votes) ## [1] 10000 #votes ##a) p=0.55 p=0.55 z_score=0 for(i in 1:50) { test1=prop.test(votes[i],N,p,alternative = "two.sided",conf.level=0.95) z_score[i]=(test1$statistic) } histogram=hist(z_score) ##b) p=0.6 p=0.6 z_score=0 for(i in 1:50) { test1=prop.test(votes[i],N,p,alternative = "two.sided",conf.level=0.95) z_score[i]=(test1$statistic) } histogram=hist(z_score) ##c) p=0.65 p=0.65 z_score=0 for(i in 1:50) { test1=prop.test(votes[i],N,p,alternative = "two.sided",conf.level=0.95) z_score[i]=(test1$statistic) } histogram=hist(z_score) ##d) p=0.55 |z|>2.575 alpha=0.01 p=0.55 z_score=0 for(i in 1:50) { test1=prop.test(votes[i],N,p,alternative = "two.sided",conf.level=0.99) z_score[i]=(test1$statistic) } histogram=hist(z_score) ##e) p=0.6 p=0.6 z_score=0 for(i in 1:50) { test1=prop.test(votes[i],N,p,alternative = "two.sided",conf.level=0.99) z_score[i]=(test1$statistic) } histogram=hist(z_score) ##f) p=0.65 p=0.65 z_score=0 for(i in 1:50) { test1=prop.test(votes[i],N,p,alternative = "two.sided",conf.level=0.99) z_score[i]=(test1$statistic) } histogram=hist(z_score)