coinToss = function(x){
toss = runif(1,min=0,max=1)
if (toss > .5){return('H')}
else{return('T')}
}
coinToss()
## [1] "H"
coinTosses = function(n){
tosses = rep(NA,n)
tosses = sapply(tosses,coinToss)
proportion = sum(tosses=='H')/sum(tosses=='T')-.5
return(proportion)
}
records = vector()
for(x in 200:300){
z = coinTosses(x)
records[x-199] = z
}
records
## [1] 0.4801980 0.6157895 0.5404040 0.2500000 0.4615385 0.5707071 0.5000000
## [8] 0.5700000 0.4082569 0.5490196 0.5388350 0.5485437 0.4813084 0.5882353
## [15] 0.4279279 0.4545455 0.3782609 0.4035088 0.4122807 0.6262136 0.3032787
## [22] 0.5462963 0.4646018 0.5272727 0.3983051 0.4911504 0.5733945 0.6826923
## [29] 0.4487179 0.5630631 0.3548387 0.3629032 0.6090909 0.4914530 0.3281250
## [36] 0.5982143 0.5000000 0.4586777 0.5695652 0.4430894 0.3181818 0.5423729
## [43] 0.4055118 0.6504425 0.5165289 0.4600000 0.3222222 0.4448819 0.4682540
## [50] 0.6652174 0.7727273 0.5241935 0.4687500 0.4612403 0.6166667 0.4615385
## [57] 0.4104478 0.4037037 0.3169014 0.5077519 0.4847328 0.7500000 0.4552239
## [64] 0.7288136 0.3857143 0.4064748 0.3732394 0.7627119 0.7905983 0.5534351
## [71] 0.5454545 0.2947020 0.5298507 0.5222222 0.3767123 0.8706897 0.6068702
## [78] 0.5367647 0.4440559 0.3979592 0.4178082 0.6615385 0.4315068 0.7109375
## [85] 0.2750000 0.6111111 0.6343284 0.4657534 0.4328859 0.6094891 0.3709677
## [92] 0.5785714 0.5277778 0.4150327 0.2926829 0.4407895 0.7424242 0.4411765
## [99] 0.4735099 0.6510791 0.5979021
Not quite sure how to best approach making the confidence interval for the second part of the question, who wants to help.
bigMeans = vector()
smallMeans = vector()
bigHospital = vector()
smallHospital = vector()
for(p in 1:50){
for(day in 1:365){
bH = coinTosses(45)
sH = coinTosses(15)
bigHospital[day] = bH
smallHospital[day] = sH
}
bigMeans[p] =mean(bigHospital)
smallMeans[p]=mean(smallHospital)
}
mean(bigMeans)
## [1] 0.5467684
mean(smallMeans)
## [1] 0.6730934
Answer is (b) the small hospital. People get this wrong because instinctual thought is that big numbers are associated with other big numbers. 45 > 15 so big hospital with big number must have big proportion.