#parts of Chapter 10 excercise 26 iridrhod<-read.table("http://math.cmc.edu/moneill/Math152/Handouts/IRIDRHOD.txt",header=T,na.strings="*") iridrhod attach(iridrhod) Ir<-Ir[!is.na(Ir)] #stem and leaf stem(Ir) #regular plotting plot(1:length(Ir),Ir) plot(1:length(Ir),Ir,ylim=c(157,163)) #measures of location mean(Ir,trim=.20) median(Ir) #a naive confidence interval plot(1:length(Ir),Ir,ylim=c(157,163)) lines(c(0,30),c(156.84,156.84)) lines(c(0,30),c(160.785,160.785)) #a non-parametric confidence interval pbinom(0:27,27,.5) c(Ir[order(Ir)][10],Ir[order(Ir)][27-10 +1]) #some bootstrapping #Iridium 20% trimmed mean d<-replicate(1000,mean(sample(Ir,replace=T),trim=.2)) sd(d) [1] 0.2828064 #A bootstrap confidence interval d<-replicate(1000,mean(sample(Ir,replace=T),trim=.2)) thetahat<-mean(Ir,trim=.2) deltahigh<-d[order(d)][950]-thetahat deltalow<-d[order(d)][50]-thetahat c(thetahat-deltahigh,thetahat-deltalow) #Comparing two samples #Simulating a rank sum distribution: f<-function(x){R=sum(sample(1:21,8)) min(R,8*22 -R)} d<-sapply(1:30000,f) hist(d) length(d[d<52])/30000 #Simulating the signed rank test f<-function(x){sum((1:10)*sample(c(0,1),10,replace=T))} d<-sapply(1:10000,f) hist(d) #chapter 10, problem 48 lottery<-read.table("http://math.cmc.edu/moneill/Math152/Handouts/1970lottery.txt",header=T) attach(lottery) names(lottery) boxplot(Draft_No~Month_Number)