# Examples Test of Binomial proportion # Edps 587 # C.J.Anderson # # Exact tests and confidence intervals for # US presidents # GSS regarding abortion # 2000 election: Bush vs Gore # library(binom) # For asympotic CI and alternative method ####################################################### # Example 1: US presidents # ####################################################### # US presidents: Taller candidate won (as in the lecture notes) N<- 15 y<- 13 # Exact tests: # --- one sided (binom.test(y,N,alternative=c("less"),conf.level=.95)) # --- two sided (binom.test(y,N,alternative=c("two.sided"),conf.level=.95)) # Asymptotic test statistic: # --- no correction for continuity (prop.test(y,N,p=.5, alternative="two.sided",conf.level=0.95,correct=FALSE)) # --- Note on asympototic: "X-squared is z^2". sqrt(8.0667) # compare this with.... # To check the asympotitc w/o continunity p <- y/N z <- (p-.5)/sqrt(.5*(1-.5)/N) # --- with Yate's correction for continuity (prop.test(y,N,p=.5, alternative="two.sided",conf.level=0.95,correct=TRUE)) # More on confidence intervals # - here are 8 different methods binom.confint(y,N,conf.level=.95, methods="all") # Among these are asymptotic, exact and "wilson", which is the # one based on finding pi such that would retain null. ################################################################ # Example 2: GSS # ################################################################ # GSS: ok for pregnant woman to have aborition if can't afford it ? yes <- 971 no <- 954 N <- yes+no # Exact: (binom.test(yes,N,alternative=c("two.sided"),conf.level=.95)) # Asymptotic test: (prop.test(yes,N,p=.5, alternative="two.sided",conf.level=0.95,correct=FALSE)) binom.confint(yes,N,conf.level=.95, methods="all") ############################################################## # Example 3: 2000 election: Bush vs Gore in Florida # ############################################################## bush <- 2912790 gore <- 2912253 n <- bush + gore (binom.test(bush,n,alternative=c("greater"),conf.level=.999)) # An setting alpha=.001 and doing 2-sided (binom.test(bush,n,alternative=c("two.sided"),conf.level=.999)) # This should be *very* close to asymptotic result (prop.test(bush,n,alternative="two.sided",conf.level=0.999,correct=TRUE)) binom.confint(y,N,conf.level=.99, methods="all")