library(MASS) # conduct the regression and assign it to mod_log # draw a scatterplot and add the regression line # conduct the regression and assign it to mod_log mod_log <- lm(medv ~ log(lstat), data = Boston) # draw a scatterplot and add the regression line plot(medv ~ log(lstat), data = Boston) abline(mod_log, col = "red") ex() %>% check_object("mod_log") %>% check_equal() test_or(ex() %>% check_function("plot") %>% { check_arg(., "formula") %>% check_equal() check_arg(., "data") %>% check_equal() }, ex() %>% override_solution("plot(log(Boston$lstat), Boston$medv)") %>% check_function("plot") %>% { check_arg(., "x") %>% check_equal() check_arg(., "y") %>% check_equal() }, ex() %>% override_solution("plot(Boston$medv ~ log(Boston$lstat))") %>% check_function("plot") %>% check_arg("formula") %>% check_equal() ) ex() %>% check_function("abline") #%>% check_arg("reg") %>% check_equal() success_msg("Correct! Although the relationship is not perfectly linear, a log transformation considerably improves our model fit and seems to be a reasonable model specification.")