Learn R Programming

discrim (version 0.1.2)

discrim_quad: General Interface for Quadratic Discriminant Models

Description

discrim_quad() is a way to generate a specification of a quadratic discriminant analysis (QDA) model before fitting and allows the model to be created using different packages in R.

Usage

discrim_quad(mode = "classification")

# S3 method for discrim_quad update(object, fresh = FALSE, ...)

Arguments

mode

A single character string for the type of model. The only possible value for this model is "classification".

object

A quadratic discriminant model specification.

fresh

A logical for whether the arguments should be modified in-place of or replaced wholesale.

...

Not used for update().

Engine Details

Engines may have pre-set default arguments when executing the model fit call. For this type of model, the template of the fit calls are:

discrim_linear() %>% 
  set_engine("MASS") %>% 
  translate()

## Linear Discriminant Model Specification (classification)
## 
## Computational engine: MASS 
## 
## Model fit template:
## MASS::lda(formula = missing_arg(), data = missing_arg())

Details

For discrim_quad(), the mode will always be "classification".

The model can be created using the fit() function using the following engines:

  • R: "MASS"

This argument is converted to its specific names at the time that the model is fit. Other options and argument can be set using set_engine(). If left to their defaults here (NULL), the values are taken from the underlying model functions. If parameters need to be modified, update() can be used in lieu of recreating the object from scratch.

Examples

Run this code
# NOT RUN {
parabolic_grid <-
  expand.grid(X1 = seq(-5, 5, length = 100),
              X2 = seq(-5, 5, length = 100))

qda_mod <-
  discrim_quad() %>%
  set_engine("MASS") %>%
  fit(class ~ ., data = parabolic)

parabolic_grid$qda <-
  predict(qda_mod, parabolic_grid, type = "prob")$.pred_Class1

library(ggplot2)
ggplot(parabolic, aes(x = X1, y = X2)) +
  geom_point(aes(col = class), alpha = .5) +
  geom_contour(data = parabolic_grid, aes(z = qda), col = "black", breaks = .5) +
  theme_bw() +
  theme(legend.position = "top") +
  coord_equal()
# }

Run the code above in your browser using DataLab