Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

stepCriterion.glm

Variable Selection in Generalized Linear Models


Description

Performs variable selection in generalized linear models.

Usage

## S3 method for class 'glm'
stepCriterion(
  model,
  criterion = c("bic", "aic", "adjr2", "p-value"),
  test = c("wald", "lrt", "score", "gradient"),
  direction = c("backward", "forward"),
  level = 0.05,
  verbose = TRUE,
  ...
)

Arguments

model

an object of the class glm which is obtained from the fit of a generalized linear model. The linear predictor of the model whose fit is stored in this glm object is the more complex candidate which should be considered by the variable selection procedure.

criterion

an (optional) character string indicating the criterion which should be used to compare the candidate models. The available options are: AIC ("aic"), BIC ("bic"), adjusted deviance-based R-squared ("adjr2"), and p-value of the test test ("p-value"). By default, criterion is set to be "bic".

test

an (optional) character string indicating the statistical test which should be used to compare nested models. The available options are: Wald ("wald"), Rao's score ("score"), likelihood ratio ("lrt") and gradient ("gradient") tests. By default, test is set to be "wald".

direction

an (optional) character string indicating the mode of variable selection which should be used. The available options are: deleting variables ("backward") and adding variables ("forward"). By default, direction is set to be "backward".

level

an (optional) numeric value in the interval (0,1) indicating the significance level chosen to perform the F tests. This is only appropiate if criterion="p-value". By default, level is set to be 0.05.

verbose

an (optional) logical switch indicating if should the report of results be printed. By default, verbose is set to be TRUE.

...

further arguments passed to or from other methods. For example, k, that is, the magnitude of the penalty in the AIC, which by default is set to be 2.

Value

A list which contains the following objects:

  • initial: an expression describing the linear predictor of the "initial" model.

  • final: an expression describing the linear predictor of the "final" model.

  • criterion: a character string describing the criterion chosen to compare the candidate models.

See Also

Examples

## Example 1
Auto <- ISLR::Auto
mod <- mpg ~ cylinders + displacement + acceleration + origin + horsepower*weight
fit1 <- glm(mod, family=inverse.gaussian("log"), data=Auto)
stepCriterion(fit1, direction="forward", criterion="p-value", test="lrt")
stepCriterion(fit1, direction="backward", criterion="adjr2")

## Example 2
burn1000 <- aplore3::burn1000
burn1000 <- within(burn1000, death <- factor(death, levels=c("Dead","Alive")))
mod2 <- death ~ age + gender + race + tbsa + inh_inj + flame + age*inh_inj + tbsa*inh_inj
fit2 <- glm(mod2, family=binomial("logit"), data=burn1000)
stepCriterion(fit2, direction="backward", criterion="bic")
stepCriterion(fit2, direction="forward", criterion="p-value", test="score")

## Example 3
fit3 <- glm(cases ~ offset(log(population)) + city*age, family=poisson("log"), data=skincancer)
stepCriterion(fit3, direction="backward", criterion="adjr2")
stepCriterion(fit3, direction="forward", criterion="p-value", test="lrt")

glmtoolbox

Set of Tools to Data Analysis using Generalized Linear Models

v0.1.0
GPL-2 | GPL-3
Authors
Luis Hernando Vanegas [aut, cre], Luz Marina Rondón [aut], Gilberto A. Paula [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.