# Comparing an observed proportion to a population value # - The Binomial test # from website: mydataframe <- read.delim("http://www.robin-beaumont.co.uk/virtualclassroom/book2data/binary_n1361.dat", header=TRUE) ### local ignore: # mydataframe <- read.delim("D:\\web_sites_mine\\HIcourseweb new\\book2data\\binary_n1361.dat", # header=TRUE) ### names(mydataframe) mytable <- xtabs(~ value , data= mydataframe ) mytable binom.test(rbind(mytable), alternative='two.sided', p=.25, conf.level=.95) binom.test(c(328, 1033), alternative='two.sided', p=.25, conf.level=.95) # If we can't even be bothered to work out # how many there are in the second category you can use: binom.test(328, 1361, alternative='two.sided', p=.25, conf.level=.95) #### drawing distribution # auto generated from R Commander .x <- 289:394 plotDistr(.x, dbinom(.x, size=1361, prob=0.25), xlab="Number of Successes", ylab="Probability Mass", main="Binomial Distribution: Binomial trials=1361, Probability of success=0.25", discrete=TRUE) remove(.x) # adding the line manually abline(v=328, lwd=5, col="red") abline(v=352, lwd=5, col="blue") # now consider the critical values for CV= 0.05 qbinom(c(.025,.975), size=1361, prob=0.25, lower.tail=TRUE) # [1] 309 372 # add then to the plot abline(v=309, lwd=5, col="red", lty=2) abline(v=372, lwd=5, col="blue", lty=2) text(309,.02,"lower CV") text(372,.02,"upper CV")