pdf("ex0505.pdf") # Read in data from ASCII formatted (Fixed With File) ex0505dat <- read.fwf("http://www.stat.ufl.edu/~winner/data/biostat/ex0505.dat", width=c(8,8,8,8), col.names=c("trt","death","trt_r","death_r")) # Create a dataset (frame) from input data ex0505 <- data.frame(ex0505dat) # Attach the dataset for analysis attach(ex0505) # Obtain crosstabulation of trt and death freqtd <- table(trt, death) freqtd # Obtain the probabilities of death for each trt group # Note that death is labelled "0" and "1", and we are modelling probability of "1" # Note that trt is labelled "0" and "1", and we are modelling P(death=1|trt=1)/p(death=1|trt=0) probrow1 <- freqtd[1,2]/(freqtd[1,1]+freqtd[1,2]) probrow2 <- freqtd[2,2]/(freqtd[2,1]+freqtd[2,2]) probrow1 probrow2 # Obtain P-value based on Fisher's exact test (This gives a 2-sided P-value) fisher.test(freqtd) dev.off()