##### d2: The Practice of Confidence Intervals ##### ### Preamble source("http://rfs.kvasaheim.com/stat200.R") dt = read.csv("http://rfs.kvasaheim.com/data/crime.csv") attach(dt) ##### ### One-Population mean boxplot(vcrime90) shapiroTest(vcrime90) hildebrand.rule(vcrime90) t.test(vcrime90) wilcox.test(vcrime90, conf.int=TRUE) # Bootstrapping st = numeric () for (i in 1:1e4 ) { x = sample (vcrime90, replace=TRUE) st[i] = mean(x) } quantile( st, c(0.025,0.975) ) ##### ### One-Population median boxplot(vcrime90) wilcox.test(vcrime90, conf.int=TRUE) ##### ### One-Population proportion table( vcrime90>500 ) binom.plot(x=29, n=51, name="High Crime") binom.test(x=29, n=51) wald.test(x=29, n=51) st = numeric () for (i in 1:1e4 ) { x = sample (vcrime90>500, replace=TRUE) st[i] = mean(x) } quantile( st, c(0.025,0.975) ) ##### ### One-Population variance boxplot(vcrime90) shapiroTest(vcrime90) onevar.test(vcrime90) st = numeric() for (i in 1:1e4 ) { x = sample (vcrime90, replace=TRUE) st[i] = var(x) } quantile( st, c(0.025,0.975) ) ##### ##### ### Two-Population mean boxplot( vcrime90~(census4=="South") ) shapiroTest( vcrime90~(census4=="South") ) t.test( vcrime90~(census4=="South") ) wilcox.test( vcrime90~(census4=="South"), conf.int=TRUE ) boxplot(vcrime90,vcrime00, names=c("1990","2000"), ylab="Violent Crime Rate") shapiroTest(vcrime90) shapiroTest(vcrime00) t.test(vcrime90,vcrime00) wilcox.test(vcrime90,vcrime00) vcrimeDiff = vcrime00-vcrime90 shapiroTest(vcrimeDiff) hildebrand.rule(vcrimeDiff) t.test(vcrimeDiff) wilcox.test(vcrimeDiff, conf.int=TRUE) st = numeric() for (i in 1:1e4 ) { x = sample (vcrimeDiff, replace=TRUE) st[i] = mean(x) } quantile( st, c(0.025,0.975) ) ##### ##### ### Two-Population proportion table(vcrime90>500,census4) binom.plot(x=c(13,6), n=c(17,13), names=c("South","West")) prop.test(x=c(13,6), n=c(17,13)) wald.test(x=c(13,6), n=c(17,13)) ##### ##### ### Two-Population variance boxplot(vcrime90~census4=="South") shapiroTest(vcrime90~census4=="South") hildebrand.rule(vcrime90~census4=="South") var.test(vcrime90~census4=="South") boxplot(vcrime90,vcrime00, names=c("1990","2000")) shapiroTest(vcrime90) shapiroTest(vcrime00) hildebrand.rule(vcrime90) hildebrand.rule(vcrime00) var.test(vcrime90,vcrime00) ##### End of File