R/backward.r
backward.Rd
These functions provide simple backward elimination/forward selection procedures for logistf models.
backward(object, ...)
# S3 method for class 'logistf'
backward(
object,
scope,
data,
steps = 1000,
slstay = 0.05,
trace = TRUE,
printwork = FALSE,
full.penalty = FALSE,
...
)
# S3 method for class 'flic'
backward(
object,
scope,
steps = 1000,
slstay = 0.05,
trace = TRUE,
printwork = FALSE,
full.penalty = FALSE,
...
)
forward(object, ...)
# S3 method for class 'logistf'
forward(
object,
scope,
data,
steps = 1000,
slentry = 0.05,
trace = TRUE,
printwork = FALSE,
pl = TRUE,
...
)
A fitted logistf model object. To start with an empty model, create a model fit with a formula= y~1, pl=FALSE. (Replace y by your response variable.)
Further arguments to be passed to methods.
The scope of variables to add/drop from the model. Can be missing for backward, backward will use the terms of the object fit. Alternatively, an arbitrary vector of variable names can be given, to allow that only some of the variables will be competitively selected or dropped. Has to be provided for forward.
The data frame used to fit the object.
The number of forward selection/backward elimination steps.
For backward
, the significance level to stay in the model.
If TRUE
, protocols selection steps.
If TRUE
, prints each working model that is visited by the selection procedure.
If TRUE
penalty is not taken from current model but from start model.
For forward
, the significance level to enter the model.
For forward, computes profile likelihood confidence intervals for the final model if TRUE
.
An updated logistf, flic
or flac
fit with the finally selected model.
The variable selection is simply performed by repeatedly calling add1 or drop1 methods for logistf, and is based on penalized likelihood ratio test.
Note that selecting among factor variables is not supported. One way to use forward or backward with factor variables is to first convert them into numeric variables (0/1 coded dummy variables, choosing a sensible reference category). Forward and backward will then perform selection on the dummy variables, meaning that it will collapse levels of a factor variable with similar outcomes.
forward()
: Forward Selection
data(sex2)
fit<-logistf(data=sex2, case~1, pl=FALSE)
fitf<-forward(fit, scope=c("dia", "age"), data=sex2)
#> Step 0 : starting model
#> Step 1 : added dia (P= 0.01167743 )
#> Step 2 : added age (P= 0.01048724 )
#>
fit2<-logistf(data=sex2, case~age+oc+vic+vicl+vis+dia)
fitb<-backward(fit2, data=sex2)
#> Step 0 : starting model
#> Step 1 : removed oc (P= 0.8751911 )
#> Step 2 : removed vis (P= 0.05158225 )
#>