library(AER)
library(MASS)
# generar la variable binaria `old` y agregarla al conjunto de datos
# realizar la regresión y asignarla a `mod_bb`
# imprimir un resumen sólido en la consola
# generar la variable binaria `old` y agregarla al conjunto de datos
Boston$old <- as.numeric(Boston$age >= 95)
# realizar la regresión y asignarla a `mod_bb`
mod_bb <- lm(medv ~ chas*old, data = Boston)
# imprimir un resumen sólido en la consola
coeftest(mod_bb, vcov. = vcovHC)
ex() %>% check_object("Boston") %>% check_column("old", col_missing_msg = "Have you added the column `old` to `Boston`?") %>%
check_equal(incorrect_msg = "Have you correctly calculated the column `old` based on `age`?")
test_or({
test_object("mod_bb")
},{
f <- ex() %>% override_solution("lm(medv ~ old*chas, data = Boston)") %>% check_function("lm")
f %>% check_arg("formula") %>% check_equal()
},{
f <- ex() %>% override_solution("lm(Boston$medv ~ Boston$chas*Boston$old)") %>% check_function("lm")
f %>% check_arg("formula") %>% check_equal()
},{
f <- ex() %>% override_solution("lm(Boston$medv ~ Boston$old*Boston$chas)") %>% check_function("lm")
f %>% check_arg("formula") %>% check_equal()
},{
f <- ex() %>% override_solution("attach(Boston);lm(medv ~ chas*old)") %>% check_function("lm")
f %>% check_arg("formula") %>% check_equal()
},{
f <- ex() %>% override_solution("attach(Boston);lm(medv ~ old*chas)") %>% check_function("lm")
f %>% check_arg("formula") %>% check_equal()
},{
f <- ex() %>% override_solution("lm(medv ~ chas + old + chas:old, data = Boston)") %>% check_function("lm")
f %>% check_arg("formula") %>% check_equal()
},{
f <- ex() %>% override_solution("lm(medv ~ old + chas + old:chas, data = Boston)") %>% check_function("lm")
f %>% check_arg("formula") %>% check_equal()
},{
f <- ex() %>% override_solution("lm(Boston$medv ~ Boston$chas + Boston$old + Boston$chas:Boston$old)") %>% check_function("lm")
f %>% check_arg("formula") %>% check_equal()
},{
f <- ex() %>% override_solution("lm(Boston$medv ~ Boston$old + Boston$chas + Boston$old:Boston$chas)") %>% check_function("lm")
f %>% check_arg("formula") %>% check_equal()
},{
f <- ex() %>% override_solution("attach(Boston);lm(medv ~ chas + old + chas:old)") %>% check_function("lm")
f %>% check_arg("formula") %>% check_equal()
},{
f <- ex() %>% override_solution("attach(Boston);lm(medv ~ old + chas + old:chas)") %>% check_function("lm")
f %>% check_arg("formula") %>% check_equal()
})
ex() %>% check_function("coeftest") %>% {
check_arg(., "x") %>% check_equal()
check_arg(., "vcov.") %>% check_equal()
}
success_msg("¡Correcto! El efecto estimado de pasar de un suburbio con una baja proporción de edificios antiguos a uno con una alta proporción es -7.13 + 10.55 * chas. Entonces, dependiendo del paso del río Charles por un suburbio, el efecto es positivo o negativo.")