BWselection: BackWard Selection

Description Usage Arguments Value Examples

View source: R/backward_selection.R

Description

Perform Backward selection on regression models

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
BWselection(
  data,
  qvarlist = NULL,
  lvarlist = NULL,
  spvarlist = NULL,
  spclist = NULL,
  catvarlist = NULL,
  outcome,
  type = "lm",
  sig = 0.05,
  complete_case = TRUE,
  track = "Simple"
)

Arguments

data

input Data used for the regression

qvarlist

Variable list in vector format, including all the variables needed for the quadratic form

lvarlist

Variable list in vector format, including all the variables in the continuous linear form

spvarlist

variable list in vector format, including all the variables for the spline form

spclist

if spvarlist is not empty, specify the outpoints for the spline term

catvarlist

variable list in the vector format, including all the categorical variables

outcome

Outcome variable for the regression model

type

type of regression model, default is lm, logistic regression use type="logistic"

sig

significant level used for exit the model, default is 0.05

complete_case

whether to use the complete case for all the variables in the model, default is TRUE

track

Whether print the selection process, could select from "Simple","All", "None"

Value

a list of original formula, final fit model and final fit formula

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#Load NHANES DATA
library(NHANES)
data("NHANES")
data=NHANES

#Created variable lists for the model selection
qvarlist<-c("BPSysAve","SleepHrsNight","TotChol")
lvarlist<-c("Age","BPDiaAve","Weight","Height")
spvarlist<-c("Pulse","DirectChol")
spclist<-c(70,1.2)
catvarlist<-c("Depressed","Marijuana","Gender")

#Run the model selection, this will return a list
fit_test1=BWselection(data=NHANES,qvarlist=qvarlist,lvarlist=lvarlist,spvarlist=spvarlist,
                     spclist=spclist,catvarlist=catvarlist,outcome="BMI",type="lm",sig=0.05,complete_case=TRUE)

xuetao666/BWselection documentation built on Dec. 23, 2021, 7:13 p.m.