Fit Multivariate Logistic Regression Model
fit_logistic.RdA wrapper around glm() for fitting multivariate
logistic regression models for binary classification problems.
Usage
fit_logistic(x, ..., strip)
# S3 method for class 'formula'
fit_logistic(formula, ..., strip = FALSE)
# S3 method for class 'data.frame'
fit_logistic(x, y = NULL, strip = FALSE, ...)
# S3 method for class 'tr_data'
fit_logistic(x, ..., strip = FALSE)
# S3 method for class 'matrix'
fit_logistic(x, y, strip = FALSE, ...)Arguments
- strip
logical(1). Should certain entries of the model object be stripped viastripLMC()to reduce object size? If true, some downstream functionality is compromised, e.g.summary()andresiduals(), however when iterating over 1000s of models this may be an acceptable trade-off to limit runaway memory consumption.- formula, x, ...
Either a formula, data frame, or matrix. If a
formula(preferred) should be a model of the form: \(class ~ x_1 + x_2 + ... + x_n\). If a data frame (preferably atr_dataobject), containing features or predictors. If a matrix object containing ONLY predictors, in which caseymust be passed (see examples below). Unmatched arguments eventually be passed toglm()via the....- y
Can be one of two options:
- character
A
character(1)indicating the column inxcontaining the true class names.- vector
A vector
factor(n)of true class names for each sample (row) inx.
Value
A glm model object as returned by glm(), logistic regression model.
Methods (by class)
fit_logistic(formula): S3 formula method forfit.fit_logistic(data.frame): S3data.framemethod forfit_logistic.fit_logistic(tr_data): S3tr_datamethod forfit_logistic.fit_logistic(matrix): S3 matrix method forfit_logistic.
See also
The fit*() family:
fit_gbm(),
fit_kknn(),
fit_nb()
Examples
# formula S3 method
# This is the preferred syntax
class(tr_iris)
#> [1] "tr_data" "tbl_df" "tbl" "data.frame"
df <- tibble::as_tibble(tr_iris) # strip tr_data class
# tr_data S3 method:
model <- fit_logistic(tr_iris)
# data frame S3 method:
model <- fit_logistic(df, "Species")
# formula S3 method:
model <- fit_logistic(Species ~ ., data = df)
# data frame S3 method (2):
model <- fit_logistic(df[, -5L], y = df$Species) # vector of class names
# matrix S3 method:
model <- fit_logistic(as.matrix(df[, -5L]), y = df$Species) # 'glmnet' syntax