Q0 ‐ 1 pt): First and last name of all group members (up to four members per group): Quiz 05 _____________________, _____________________, ______________________, ______________________. Show your work and write numeric answers to 4 decimals. Don't round your calculations until the very end. We will deduct points for rounding errors. Please include R/Stata code when showing your work. This quiz/workshop will help you practice with the ideas of two‐sample hypothesis testing and the tools from Ch 9 and 10. Please create an electronic document (pdf, doc, docx, etc.) and email your group's solutions with the subject heading "Quiz 4 ‐ [YOUR NAMES]", e.g. "Quiz 4 ‐ Robert, Laurie, Jeffrey", to me by midnight this Friday (hopefully sooner, the extra time is just in case you need it). Q setup) Consider a small experiment comparing the efficacy of a new blood pressure medication (drug A) to a placebo (drug B). Ten patients with hypertension are randomly assigned to the new drug and twenty to the placebo. Patients' systolic blood pressure (SBP in mmHg) is measured after the patients have been on their assigned drug for one week. Suppose SBP is Normally distributed with a standard deviation of 5 mmHg for both groups. Using R, let's generate the realization of one such experiment assuming the new medication has no effect. Run the following code to generate the data. set.seed(13) A = rnorm(10, 130, 5) B = rnorm(20, 130, 5) Q1 ‐ 5 pts) By hand, test for a difference in means between the two groups using a two‐sample Z test (assuming you know the true sd's, which are both = 5 mmHg). Include your Ho, Ha, RR, TS, p‐value, and conclusion. Q2 ‐ 5 pts) By hand, test for a difference in means between the two groups using an unequal variance two‐
sample t‐test. Include your Ho, Ha, RR, TS, p‐value, and conclusion. Q3 ‐ 5 pts) By hand, test for a difference in means between the two groups using an equal variance two‐
sample t‐test. Include your Ho, Ha, RR, TS, p‐value, and conclusion. Q4 ‐ 5 pts) By hand, test for a difference in means between the two groups using a Wilcoxon Rank‐Sum test. Include your Ho, Ha, RR, TS, p‐value, and conclusion. Note the Ho and Ha are different then Q1‐Q3. 1 Q setup) Check your answers for p‐value to the previous questions using the following R commands. # R doesn't have a native function to do 2‐sample Z‐test, but we can easily create one. # hat tip to http://www.r‐bloggers.com/two‐sample‐z‐test/ z.test = function(a, b, sd.a, sd.b){ # a & b are vectors of the outcome values # sd.a & sd.b are the true standard deviations n.a = length(a) n.b = length(b) zeta = (mean(a) ‐ mean(b)) / (sqrt(sd.a^2/n.a + sd.b^2/n.b)) pval = 2*pnorm(‐abs(zeta)) return(pval) } ## Calculate and print the p‐values # Normal Z test z = z.test(A,B,5,5) # Unequal var t‐test tu = t.test(A,B,var.equal=F)$p.value # Equal var t‐test te = t.test(A,B,var.equal=T)$p.value # Wilcoxon rank‐sum test using the Normal approximation with continuity correction w = wilcox.test(A,B,exact=F,correct=T)$p.value # vector of the p‐values p = c(z,tu,te,w) round(p, digits=4) Using a 0.05 significance level for a two‐sided alternative for all of the tests, discuss among yourselves what you think the true Type I error rate should be for each method. Q5 ‐ 5 pts) To two decimals of accuracy, empirically calculate the true Type I error rate for each of the four methods used above. Q setup) Consider the following change to the experiment. Assume the new drug doesn't impact the mean SBP, but it does increase the variance a little bit. A = rnorm(10, 130, 9) B = rnorm(20, 130, 5) Discuss among yourselves the impact this will have on the Type I error of each method. Q6 ‐ 5 pts) To two decimals of accuracy, empirically calculate the true Type I error rate for each of the four methods used above. 2 Q setup) Consider the following change to the experiment. Assume the new drug does impact the mean SBP, and does not increase the variance. A = rnorm(10, 120, 5) B = rnorm(20, 130, 5) Discuss among yourselves how the methods should compare in terms of Type II error (Power). Q7 ‐ 5 pts) To two decimals of accuracy, empirically calculate the true Type II error rate for each of the four methods used above. Q8 ‐ up to 1 bonus pt) Use Rosner's equation 8.28 to solve for the difference in true means that yields 80% power for a two sample Z‐test. I'll set it up for you. 0.80 = P( Z < qnorm(0.025) + delta/sqrt(25/10+25/20) ) qnorm(0.80) = qnorm(0.025) + delta/sqrt(25/10+25/20) Note qnorm(0.025) = ‐qnorm(0.975). Also note Rosner's equation 8.28 is approximate, though the precision is quite good for moderate to large delta's. Q9 ‐ up to 4 bonus pts) To two decimals of accuracy, empirically calculate the true Type II error rate for each of the four methods used in Q1‐Q4 assuming the new medication reduces SBP by the delta you solved for in Q8. 3
© Copyright 2026 Paperzz