Does small dose of aspirin prevent heart attacks in healthy middle-aged men?
Stanford University, Spring 2016, STATS 205
Does small dose of aspirin prevent heart attacks in healthy middle-aged men?
labels = c("nattacks","nsubjects") aspirin = c(104,11037) placebo = c(189,11034) data = data.frame(aspirin,placebo) rownames(data) = labels data
## aspirin placebo ## nattacks 104 189 ## nsubjects 11037 11034
Ratio of the rates:
rate = function(v) v[1]/v[2] theta.hat = rate(data$aspirin)/rate(data$placebo) theta.hat
## [1] 0.550115
This means that in this sample aspirin-takers only have 55% as many heart attacks as placebo-takers.
population.one = c( rep(1,data["nattacks","aspirin"]), rep(0,data["nsubjects","aspirin"]-data["nattacks","aspirin"]) ) population.two = c( rep(1,data["nattacks","placebo"]), rep(0,data["nsubjects","placebo"]-data["nattacks","placebo"]) ) draw.bootstrap.sample = function() { boot.pop.one = sample(population.one,replace = TRUE) boot.pop.two = sample(population.two,replace = TRUE) rate.one = sum(boot.pop.one)/length(boot.pop.one) rate.two = sum(boot.pop.two)/length(boot.pop.two) return(rate.one/rate.two) }
and now simulate:
nrep = 10000 theta.boot = replicate(nrep,draw.bootstrap.sample()) hist(theta.boot,breaks=100) # sample estimate abline(v=theta.hat,col = "red",lwd = 4) # bootstrap confidence interval confidence.lower = sort(theta.boot)[nrep*.025] confidence.upper = sort(theta.boot)[nrep*.975] abline(v=c(confidence.lower,confidence.upper),col = "blue",lwd = 4)
We can conclude that aspirin was found to be significantly beneficial for preventing heart attacks.