Develop a scatter plot to visualize the relationship between CityCO2 and HwyCO2| statistics
Respond to all questions and complete all tasks thorough the document
and follow the directions
also download this file :
http://www.wikiupload.com/G2DRMKMQ1KJMTJN
Code for Data Analysis:
In R go to File< New Script (New Document on MAC) – A new script window will pop up. You should write all of your code in a script window and not directly in the console.
The R code can be uploaded directly into R by copying and pasting everything below R Code DA5 into a script window.
Note: Any time you see # this means that R will not read what follows. I will use this to make comments about the following command.
R Code DA5
RCODE
#Upload Data
co2data = read.csv(file.choose(), header = TRUE)
#Look at data
head(co2data)
# Attach Data Set! Very Important Step!
# This allows you to not call the variable every time!
attach(co2data)
# develop a scatterplot to visualize the relationship between CityCO2 and HwyCO2
plot(CityCO2, HwyCO2, main = “Relationship between City CO2 Emissions
and Highway CO2 Emissions”, xlab = “CityCO2 for 2017 Vehicles”, ylab = “Highway FE”)
# Compute the correlation coefficient between CityCO2 and HwyCO2
cor(CityCO2, HwyCO2)
# Obtain the least squares regression line and t test for the slope p-value
mod = lm(HwyCO2~CityCO2)
summary(mod)
# Plot the residuals for the analysis between CityCO2 and HwyCO2
plot(CityCO2, mod$residuals, main = “Residuals”)
abline(h = 0, lty =2, lwd = 2, col = “red”)
# Calculate the 95% CI for the slope.
confint(mod, level = 0.95)
# Predict the Highway CO2 when City CO2 is 360.
predict(mod, data.frame(CityCO2 = 550))
# Compute a 95% confidence interval for when the Highway CO2 when City CO2 is 550.
predict(mod, data.frame(CityCO2 = 550), interval = “confidence”, level = 0.95)
# Compute a 95% prediction interval for when the Highway CO2 when City CO2 is 550.
predict(mod, data.frame(CityCO2 = 550), interval = “prediction”, level = 0.95)