Part 2: (10 points) Now input the data into R and create a scatter plot with the fitted regression line.
#Creating the given data
x_i = c(22, 52, 60, 42, 47, 65)
y_i = c(41, 49, 69, 55, 60, 62)
data = data.frame(x_i, y_i)
#Checking work
mod = lm(y_i~x_i)
summary(mod)
##
## Call:
## lm(formula = y_i ~ x_i)
##
## Residuals:
## 1 2 3 4 5 6
## -1.083 -9.141 6.577 2.212 4.535 -3.100
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 30.3064 9.3605 3.238 0.0317 *
## x_i 0.5353 0.1873 2.858 0.0460 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.385 on 4 degrees of freedom
## Multiple R-squared: 0.6713, Adjusted R-squared: 0.5891
## F-statistic: 8.168 on 1 and 4 DF, p-value: 0.04603
plot(data)
abline(coefficients(mod)[1],coefficients(mod)[2],lty=1, col = "red")