This is an assignment about Statistics course by using the R Studio.

profileShelby1
ch16_R.R

climate <- read.table('Climate_Change.txt', sep = '\t', header = TRUE) str(climate) plot(climate$CO2, climate$Temp, xlab = 'CO2 Concentration', ylab = 'Temperature') imod <- lm(Temp ~ CO2, data = climate) summary(imod) summary(imod)$coefficients confint(imod, level = 0.95) par(mfrow = c(1, 2)) plot(climate$year, imod$residuals, xlab = 'Time', ylab = 'Residual') abline(a = 0, b = 0) plot(imod$fitted.values, imod$residuals, xlab = 'Fitted value', ylab = 'Residual') abline(a = 0, b = 0) par(mfrow = c(1, 1)) par(mfrow = c(1,2)) hist(imod$residuals, xlab = 'Residual', main = 'Histogram of Residuals') qqnorm(imod$residuals) qqline(imod$residuals) par(mfrow = c(1, 1)) range(climate$CO2) new <- data.frame(CO2 = c(355)) predict(imod, newdata = new, interval = 'confidence', level = 0.95) predict(imod, newdata = new, interval = 'prediction', level = 0.95) xx <- seq(min(climate$CO2), max(climate$CO2), length.out = 100) new.band <- data.frame(CO2 = xx) conf <- predict(imod, newdata = new.band, interval = 'confidence', level = .95) pred <- predict(imod, newdata = new.band, interval = 'prediction', level = .95) plot(climate$CO2, climate$Temp, xlab = 'CO2 Concentration', ylab = 'Temperature') abline(imod) lines(xx, conf[, 'lwr'], lty = 2, col = 'red') lines(xx, conf[, 'upr'], lty = 2, col = 'red') lines(xx, pred[, 'lwr'], lty = 3, col = 'blue') lines(xx, pred[, 'upr'], lty = 3, col = 'blue')