logisticr: Logistic Regression

Description Usage Arguments Value Examples

View source: R/logistic.R

Description

Computes the coefficient estimates for logistic regression. ridge regularization and bridge regularization optional.

Usage

1
2
3
4
logisticr(X, y, lam = seq(0, 2, 0.1), alpha = 1.5, penalty = c("none",
  "ridge", "bridge"), intercept = TRUE, method = c("IRLS", "MM"),
  tol = 1e-05, maxit = 1e+05, vec = NULL, init = 1,
  criteria = c("logloss", "mse", "misclass"), K = 5)

Arguments

X

matrix or data frame

y

matrix or vector of response values 0,1

lam

optional tuning parameter(s) for ridge regularization term. If passing a list of values, the function will choose optimal value based on K-fold cross validation. Defaults to 'lam = seq(0, 2, 0.1)'

alpha

optional tuning parameter for bridge regularization term. If passing a list of values, the function will choose the optimal value based on K-fold cross validation. Defaults to 'alpha = 1.5'

penalty

choose from c('none', 'ridge', 'bridge'). Defaults to 'none'

intercept

Defaults to TRUE

method

optimization algorithm. Choose from 'IRLS' or 'MM'. Defaults to 'IRLS'

tol

tolerance - used to determine algorithm convergence. Defaults to 10^-5

maxit

maximum iterations. Defaults to 10^5

vec

optional vector to specify which coefficients will be penalized

init

optional initialization for MM algorithm

criteria

specify the criteria for cross validation. Choose from c('mse', 'logloss', 'misclass'). Defauls to 'logloss'

K

specify number of folds for cross validation, if necessary

Value

returns selected tuning parameters, beta estimates (includes intercept), MSE, log loss, misclassification rate, total iterations, and gradients.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
library(dplyr)
X = dplyr::select(iris, -Species)
y = dplyr::select(iris, Species)
y$Species = ifelse(y$Species == 'setosa', 1, 0)
logisticr(X, y)

# ridge Logistic Regression with IRLS
logisticr(X, y, lam = 0.1, penalty = 'ridge')

# ridge Logistic Regression with MM
logisticr(X, y, lam = 0.1, penalty = 'ridge', method = 'MM')

MGallow/logitr documentation built on May 6, 2019, 12:06 a.m.