library(lattice) data <- read.table(file="C:/Documents and Settings/steeleb/Desktop/DonnerParty.txt",head=T) head(data) n <- dim(data)[1] dotplot(data$Age~data$Outcome|data$Sex,col="black",pch=16,ylab="Age") table(data$Sex,data$Outcome) Old <- data$Age > 29 table(data$Sex,data$Outcome,Old) mosaicplot(table(data$Sex,data$Outcome,Old)) bwplot(data$Outcome~data$Age) bwplot(data$Sex~data$Age) ####################################### formal comparison age differences between sexes ##################### TF.vector <- data$Sex=="FEMALE" n.true <- sum(TF.vector) n.false <- n - n.true mean.age.females <- mean(data$Age[TF.vector==T]) mean.age.males <- mean(data$Age[TF.vector==F]) c(n.true,mean.age.females) c(n.false,mean.age.males) ######################## simulate sample means assuming no difference between females and males ########## n.sims <- 10000 simulated.means <- rep(0,n.sims) for (i in 1:n.sims){ random.sample <- sample(1:n,size=n.true) simulated.means[i] <- mean(data$Age[random.sample]) } plot(density(simulated.means),main="") x <- sum(simulated.means <= mean.age.females) c(n.sims,x) mean(simulated.means<=mean.age.females) ######## Poisson approx lambda <- n.sims/2 ppois(x,lambda=lambda) ############################# Homework ############### # 1. Compare ages between survivors and those that died, and state whether there is # clear evidence that those that died tended to be older than the survivors. Support your # position with a graph and the results from the simulation # 2. The mortality rate among men is substantially greater than that among women. This result may be # attributed to gender differences or perhaps human behavior. What is your explanation?