library(MASS) data(Boston) mod <- lm(medv ~ lstat, data = Boston) # compute the correlation between medv and lstat # plot medv against lstat and add the regression line # compute the correlation between medv and lstat corr <- cor(Boston$medv, Boston$lstat) # plot medv against lstat and add the regression line plot(medv ~ lstat, data = Boston) abline(reg = mod, col = "red") ex() %>% check_object("corr") %>% check_equal() test_or({ex() %>% check_function("plot") %>% { check_arg(., "formula") %>% check_equal() check_arg(., "data") %>% check_equal() } },{ ex() %>% override_solution("plot(Boston$lstat, Boston$medv)") %>% check_function("plot") %>% { check_arg(., "x") %>% check_equal() check_arg(., "y") %>% check_equal() } },{ ex() %>% override_solution("plot(Boston$medv ~ Boston$lstat)") %>% check_function("plot") %>% check_arg("formula") %>% check_equal() }) ex() %>% check_function("abline") %>% check_arg("reg") %>% check_equal() success_msg("Correct! Although the correlation coefficient suggests that medv and lstat are negatively linearly dependent, the relationship between them clearly is nonlinear. Hence, this linear specification of the regression function is inappropriate here.")