pdf("ex0506.pdf") # Read in data from ASCII formatted (Fixed With File) ex0506dat <- read.fwf("http://www.stat.ufl.edu/~winner/data/biostat/ex0506.dat", width=c(8,8,8,8), col.names=c("selfrep","surgical","selfrep_r","surgical_r")) # Create a dataset (frame) from input data ex0506 <- data.frame(ex0506dat) # Attach the dataset for analysis attach(ex0506) # Obtain crosstabulation of selfrep and surgical freqss <- table(selfrep, surgical) freqss # Obtain the probabilities of surgical for each selfrep group # Note that surgical is labelled "0" and "1" # Note that selfrep is labelled "0" and "1" mcnemar <- (freqss[1,2]-freqss[2,1])/sqrt(freqss[1,2]+freqss[2,1]) mcnemar.pval <- 2*(1-pnorm(abs(mcnemar))) mcnemar mcnemar.pval dev.off()