# Confidence interval estimate and hypothesis testing for #of the difference between two population proportions #Classroom Lecture n1 <- 150 pass1 <- 107 fail1 <- 43 #sample proportion p1 <- pass1/n1 p1 #Audio-Visual Instruction n2 <- 100 pass2 <- 63 fail2 <- 37 #sample proportion p2 <- pass2/n2 p2 #difference bertween sample proportions p1-p2 #standard error se <- sqrt((p1*(1-p1)/n1) +(p1*(1-p1)/n1)) se #97.5th percentile of the standard normal distribution z025 <- qnorm(.975) z025 #Lower confidence limit LCL <- (p1-p2) - (z025 *se) LCL #Upper confidence limit UCL <- (p1-p2) + (z025 *se) UCL #95% confidence interval estimate of pi1-pi2 cbind(LCL, UCL) #H0: pi1-pi2 = 0; H1: pi1-pi2 > 0 #pooled proportion pbar <- (n1/(n1+n2)*p1) + (n2/(n1+n2)*p2) pbar sep <- sqrt(pbar*(1-pbar)*(1/n1 + 1/n2)) sep #Compute test statistic ts <- (p1-p2)/sep ts #p-value = P(Z > ts) pvalue <-pnorm(ts,lower.tail = FALSE ) pvalue