################################################################################ #### Inference: One Sample Mean, One sample Proportion, Variance #### ################################################################################ #### By Jimin Ding, 02/28/2017 ###### 1. One-sample z-test and z-CI ## using summary statistics library(BSDA) ?zsum.test zsum.test(mean.x=3500,sigma.x=300,n.x=200,conf.level=0.95) zsum.test(mean.x=3500,sigma.x=300,n.x=200,mu=3460,conf.level=0.95) ## using the raw data: ?z.test ####### 2. One-sample t-test and t-CI ## using the summary statistics library(BSDA) ?tsum.test tsum.test(mean.x=3400, s.x=300,n.x=9, mu=3500,conf.level=0.9) ## using the raw data: ?t.test ####### 3. One-sample proportion test and CI ## two-sided test, and 95% confidence interval using H_0 prop.test(983, 1821) ## 90% confidence interval using the sample proportion prop.test(983, 1821,p=983/1821, conf.level=0.9) ## one-sided test, prop.test(983, 1821,alternative="greater") ## without continuity correction prop.test(983, 1821,correct=FALSE) ####### 4. Power and Sample size calculation library(pwr) ## in Z-test pwr.norm.test(n=200,d=40/300, sig.level=0.05,alternative="two.sided") pwr.norm.test(power=0.8,d=40/300, sig.level=0.05,alternative="two.sided") ## in t-test pwr.t.test(n=200,d=40/300, sig.level=0.05,alternative="two.sided",type="one.sample") pwr.t.test(power=0.8,d=40/300, sig.level=0.05,alternative="two.sided",type="one.sample")