Problem 1

x <- c(12.8, 12.9, 12.9, 13.6, 14.5, 14.6, 15.1, 17.5, 19.5, 20.8) #road width y <- c(5.5, 6.2, 6.3, 7.0, 7.8, 8.3, 7.1, 10.9, 10.8, 11.0) #separation between a bike and a passing car

#1 plot(x, y, main=“Road width vs seperation between a bike and a passing car”, xlab=“Road width”, ylab=“Seperation between a bike and a passing car”, pch=19, col=“blue”) # comment print(‘There appears to be a strong positive linear association between the width of a road and the serpation between a bike and a passing car. I think that it is reasonable to use simple linaer regression on this data.’)

#2 Line of best fit bikelane <- lm(y ~ x) abline(bikelane, col=“red”) intercept <- coef(bikelane) [1] slope <- coef(bikelane) [2] cat(“line of best fit equation: y =”, intercept, “+”, slope, “* x”)

#3 Anova anovabike <- anova(bikelane) print(anovabike)

#4 confint(bikelane, level=0.95)

#5 new_x <- data.frame(x=13.2) predict(bikelane, newdata=new_x, interval=“confidence”, level=0.95)

#6 predict(bikelane, newdata=new_x, interval=“prediction”, level=0.95)

#7 par(mfrow=c(2,2)) plot(bikelane) ##test statistically

#Residuals vs Fitted plot ncvTest(bikelane) #null hypothesis: Errors have a constant variance #alternative hypothesis: Errors have a non-constant variance print(“Since the p-value is >0.05, we do not have enough evidence to reject the null hypothesis. This implies that constant error variance assumption is violated”)

#Q-Q Residuals plot #null hypothesis: Errors are normally distributed #alternative hypothesis: Errors are not normally distributed shapiro.test(bikelane$residuals) print(“Since the p-value is >0.05 we do not have enough evidence to reject the null hypothesis. This implies that normality error assumption is not violated.”)

#Scale location plot #null hypothesis: Errors are uncorrelated #alternative hypothesis: Errors are correlated durbinWatsonTest(bikelane) print(“Since the p-value is >0.05, so we do not have enough evidence to reject the null hypothesis. This implies that uncorrelated error assumption is not violated.”)