Nothing
knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
VariableSelection()
.VariableSelection()
can accept either a BranchGLM
object or a formula along with the data and the desired family and link to perform the variable selection.VariableSelection()
returns some information about the search, more detailed
information about the best models can be seen by using the summary()
function.VariableSelection()
will properly handle interaction terms and
categorical variables.keep
can also be specified if any set of variables are desired to be kept in every model.# Loading BranchGLM package library(BranchGLM) # Fitting gamma regression model cars <- mtcars # Fitting gamma regression with inverse link GammaFit <- BranchGLM(mpg ~ ., data = cars, family = "gamma", link = "inverse") # Forward selection with mtcars forwardVS <- VariableSelection(GammaFit, type = "forward") forwardVS ## Getting final model fit(forwardVS, which = 1)
# Backward elimination with mtcars backwardVS <- VariableSelection(GammaFit, type = "backward") backwardVS ## Getting final model fit(backwardVS, which = 1)
showprogress
is true, then progress of the branch and bound algorithm will be reported occasionally.# Branch and bound with mtcars VS <- VariableSelection(GammaFit, type = "branch and bound", showprogress = FALSE) VS ## Getting final model fit(VS, which = 1)
BranchGLM
object. # Can also use a formula and data formulaVS <- VariableSelection(mpg ~ . ,data = cars, family = "gamma", link = "inverse", type = "branch and bound", showprogress = FALSE, metric = "AIC") formulaVS ## Getting final model fit(formulaVS, which = 1)
# Finding top 10 models formulaVS <- VariableSelection(mpg ~ . ,data = cars, family = "gamma", link = "inverse", type = "branch and bound", showprogress = FALSE, metric = "AIC", bestmodels = 10) formulaVS ## Plotting results plot(formulaVS, type = "b") ## Getting best model fit(formulaVS, which = 1)
# Finding all models with an AIC within 2 of the best model formulaVS <- VariableSelection(mpg ~ . ,data = cars, family = "gamma", link = "inverse", type = "branch and bound", showprogress = FALSE, metric = "AIC", cutoff = 2) formulaVS ## Plotting results plot(formulaVS, type = "b")
keep
will ensure that those variables are kept through the selection process.# Example of using keep keepVS <- VariableSelection(mpg ~ . ,data = cars, family = "gamma", link = "inverse", type = "branch and bound", keep = c("hp", "cyl"), metric = "AIC", showprogress = FALSE, bestmodels = 10) keepVS ## Getting summary and plotting results plot(keepVS, type = "b") ## Getting final model fit(keepVS, which = 1)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.