logitr: Logistic Regression

Description Usage Arguments Details Value Examples

View source: R/logitr.R

Description

Fitting logit regression models.

Usage

1
2
3
4
5
6
7
logitr(formula, data, subset, na.action,
  model = TRUE, x = FALSE, y = TRUE,
  control = logitr_control(...), ...)

logitr_fit(x, y, control)

logitr_control(maxit = 5000, start = NULL, hessian = TRUE, ...)

Arguments

formula

a formula expression of the form y ~ x where y is the response and x are the regressor variables.

data

an optional data frame containing the variables occurring in the formulas.

subset

an optional vector specifying a subset of observations to be used for fitting.

na.action

a function which indicates what should happen when the data contain NAs.

model

logical. If TRUE model frame is included as a component of the returned value.

x, y

for logitr: logical. If TRUE the model matrix and response vector used for fitting are returned as components of the returned value. For logitr_fit: x is a design matrix with the regressors and y is a vector of observations.

...

arguments to be used to form the default control argument if it is not supplied directly.

control, maxit, start

a list of control parameters passed to optim .

hessian

logical or character. Should a numeric approximation of the (negative) Hessian matrix be computed? Either FALSE (or equivalently "none") or TRUE. Alternatively, in the latter case, hessian = "numDeriv" could be specified to signal that the Hessian should be approximated by hessian. Another option is hessian = "optim" so that optim is used for computing the Hessian.

Details

logitr fits logit regression models using maximum likelihood estimation. The model assumes an underlying latent binomial variable.

logitr_fit is the lower level function where the actual fitting takes place.

A set of standard extractor functions for fitted model objects is available for objects of class "logitr", including methods to the generic functions print, summary, coef, vcov, logLik, residuals, predict, terms, model.frame, model.matrix, update.

This is a simpler implementation of glm only modeling the "family = binomial" used for logistic regression. logitr was written for the sole purpose of learning how to write packages and is not recommended to ever be used instead of glm.

Value

logitr returns an object of class "logitr", i.e., a list with components as follows. logitr_fit returns an unclassed list with components up to df.

coefficients

a list containing the coefficients,

counts

count of function and gradient evaluations from optim,

convergence

convergence code from optim,

message

optional further information from optim,

vcov

covariance matrix of all parameters in the model,

residuals.pearson

a vector containing the Pearson Residuals of the model,

fitted.values

a list containing the latent fitted values,

method

the method argument passed to the optim call,

nobs

number of observations,

df

number of estimated parameters,

call

the original function call,

formula

the original formula,

terms

a list containing the terms objects for the model,

model

the full model frame (if model = TRUE),

y

the numeric response vector (if y = TRUE),

x

a list containing the model matrices (if x = TRUE).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
##  quick randomly generated dataset. Comparison package vs glm
set.seed(123)
x1 <- rnorm(30,3,2) + 0.1 * c(1:30)
x2 <- rbinom(30,1,0.3)
x3 <- rpois(n=30,lambda = 4)
x3[16:30] <- x3[16:30] - rpois(n=15, lambda = 2)
xdat <- cbind(x1,x2,x3)
ydat <- c(rbinom(5,1,0.1), rbinom(10,1,0.25), rbinom(10,1,0.75), rbinom(5,1,0.9))
(m0 <- logitr(ydat~xdat))
(m1 <- glm(ydat~xdat, family = "binomial"))
## comparing AIC and BIC
AIC(m0)
AIC(m1)
BIC(m0)
BIC(m1)

logitr documentation built on May 2, 2019, 4:58 p.m.