Complete the code to fit a linear model predicting mpg from hp.
model <- lm(mpg ~ [1], data = mtcars)The formula mpg ~ hp fits a linear model predicting miles per gallon (mpg) using horsepower (hp) as the predictor.
Complete the code to view the summary of the linear model.
summary([1])The summary() function shows details about the fitted linear model object named model.
Fix the error in the code to extract coefficients from the model.
coef <- [1](model)The function coef() extracts the coefficients from a fitted model object.
Fill both blanks to create a new data frame with predicted mpg values.
new_data <- data.frame(hp = c(100, 150, 200)) predictions <- predict([1], newdata = [2])
Use the fitted model object 'model' and the new data frame 'new_data' to get predictions.
Fill all three blanks to create a scatter plot with regression line.
plot(mtcars$hp, mtcars$mpg, xlab = [1], ylab = [2], main = [3]) abline(model, col = "red")
The x-axis label is 'Horsepower', y-axis label is 'Miles per Gallon', and the plot title is 'MPG vs Horsepower'.