Data <- read.table(file="C:/Documents and Settings/steeleb/My Documents/Stat 341/Challenger.txt",header=T) head(Data) p <- Data$y/Data$trials plot(Data$pressure,p,xlab="Pressure",ylab="Est'd probability",pch=16) plot(jitter(Data$pressure),p,xlab="Pressure",ylab="Est'd probability",pch=16) plot(Data$temperature,p,xlab="Temperature",ylab="Est'd probability",pch=16) lm.obj <- lm(p~Data$temperature) abline(lm.obj$coeff) plot(x=c(30,90),y=c(0,1),xlab="Temperature",ylab="Est'd probability",type="n") points(Data$temperature,p,pch=16) abline(lm.obj$coeff) emp.logits <- log((Data$y+0.5)/(Data$trials-Data$y+0.5)) plot(Data$temperature,emp.logits,xlab="Temperature",ylab="Empirical logits",pch=16) lm.obj <- lm(emp.logits~Data$temperature) abline(lm.obj$coeff) x <- seq(from=0,to=85) logit.fit <- lm.obj$coeff[1] + lm.obj$coeff[2]*x p.fit <- 1/(1 + exp(-logit.fit)) plot(x=c(0,90),y=c(0,1),xlab="Temperature",ylab="Est'd probability",type="n") points(Data$temperature,p,pch=16) lines(x,p.fit) cbind(x,p.fit) ########################### randomization test of significance lm.obj <- lm(emp.logits~Data$temperature) summary(lm.obj) fitted.slope <- lm.obj$coeff[2] y <- emp.logits x <- Data$temperature summary(lm(y~x)) n <- length(y) n.sims <- 1000 simulated.slopes <- rep(0,n.sims) for (i in 1:n.sims){ randomized.x <- sample(x,size=n,replace = FALSE) simulated.slopes[i] <- lm(y~randomized.x)$coeff[2] } plot(density(simulated.slopes),main="",xlab="Simulated slope coefficients") p.value <- sum(simulated.slopes <= fitted.slope)/n.sims c(n.sims,p.value) ########################## Homework 1. Repeat the analysis above, but instead of investigating the relationship between temperature and probability of o-ring failure, investigate the relationship between pressure and temperature a. Plot the empirical logits against pressure and graph the linear regression line b. Plot the observed and fitted probablities against pressure c. Assess the significance of the slope coefficient using the randomization test d. Based on this analysis, is there evidence that pressure (within the range of experimental values) affects the likelihood of o-ring failure? Extra-credit problem (5 points): Using the data set "anesthetic" in the DAAG library, 1. Plot the empirical logits against concentration 2. Compute a good estimate the concentration of anesthetic for which the probability of patient movement is less than 0.1 Note : the help file help(anesthetic) has some helpful code