library(AER) library(MASS) # estimate the restricted model and save it in `model_res` # compute the SSR of the restricted model and assign it to `RSSR` # estimate the unrestricted model and save it in `model_unres` # compute the SSR of the unrestricted model and assign it to `USSR` # estimate the restricted model and save it in `model_res` model_res <- lm(medv ~ lstat + I(crim + age), data = Boston) # compute the SSR of the restricted model and assign it to `RSSR` RSSR <- sum(model_res$residuals^2) # estimate the unrestricted model and save it in `model_unres` model_unres <- lm(medv ~ lstat + crim + age, data = Boston) # compute the SSR of the unrestricted model and assign it to `USSR` USSR <- sum(model_unres$residuals^2) test_or({ test_function("lm", args = c("formula", "data"), not_called_msg = "Something is wrong.", args_not_specified_msg = "Something is wrong.") },{ sol <- ex() %>% override_solution("model_res <- lm(medv ~ lstat + I(crim + age), data = Boston)") sol %>% check_function("lm") %>% check_arg("formula") %>% check_equal() },{ sol <- ex() %>% override_solution("model_res <- lm(Boston$medv ~ Boston$lstat + I(Boston$crim + Boston$age))") sol %>% check_function("lm") %>% check_arg("formula") %>% check_equal()}) test_object("model_res", eval = F) test_object("RSSR") test_or({ test_function("lm", args = c("formula", "data"), not_called_msg = "Something is wrong.", args_not_specified_msg = "Something is wrong.") },{ sol <- ex() %>% override_solution("model_unres <- lm(medv ~ lstat + crim + age, data = Boston)") sol %>% check_function("lm") %>% check_arg("formula") %>% check_equal() },{ sol <- ex() %>% override_solution("model_unres <- lm(Boston$medv ~ Boston$lstat + Boston$crim + Boston$age)") sol %>% check_function("lm") %>% check_arg("formula") %>% check_equal() }) test_object("model_unres", eval = F) test_object("USSR") success_msg("Correct! Note that the SSR of the restricted model is always greater or equal than the SSR of the unrestricted model.")