# devtools::install_github("tidymodels/discrim") # para instalar
# cargar el paquete
library(discrim)
# crear datos artificiales
parabolic_grid <-
expand.grid(X1 = seq(-5, 5, length = 100),
X2 = seq(-5, 5, length = 100))
# ajustar el modelo usando discrim
fda_mod <-
parsnip::discrim_flexible(num_terms = 3) %>%
parsnip::set_engine("earth") %>%
parsnip::fit(class ~ ., data = discrim::parabolic)
# asignar las predicciones al data frame
parabolic_grid$fda <-
predict(fda_mod, parabolic_grid, type = "prob")$.pred_Class1
# graficar las predicciones
ggplot2::ggplot(discrim::parabolic, ggplot2::aes(x = X1, y = X2)) +
ggplot2::geom_point(ggplot2::aes(col = class), alpha = .5) +
ggplot2::geom_contour(data = parabolic_grid, aes(z = fda),
col = "black", breaks = .5) +
ggplot2::theme_bw() +
ggplot2::theme(legend.position = "top") +
ggplot2::coord_equal()