# R doce for ex 1.28 p37 crime=read.table("C:/Users/Mihinda/Desktop/CH01PR28.txt", header=0) #the data file y <- crime[,1] x <- crime[,2] par(mfrow=c(3,1)) plot(x, y) fit = lm(y ~x) summary(fit) yhat = predict.lm(fit) lines(x,yhat) anova(fit) plot(fitted(fit),residuals(fit)) qqnorm(residuals(fit)) #prdicting EY at a given value x0 x0 <- data.frame(x=74) predict(fit, x0) #CI for the mean of Y at x=x0 predict(fit, x0, interval="confidence", level=0.95) # prediction interval for a new Y at x = x0 predict(fit, x0, interval="prediction", level=0.95) #Bonferroni simultaneous PI at k given points x0 <- data.frame(x=c(75, 80)) k <- dim(x0)[1] alpha <- 0.05 predict(fit, x0, interval="prediction", level=1-alpha/k)