Extract best model formula from bestglm Package in R

In R, you can use a package bestglm

to run all regressions in a subset and choose the "best" model based on the criteria you specify.

Reproducible example:

require(xlsx)
require(bestglm)
lbw <- read.xls("http://www.umass.edu/statdata/statdata/data/lowbwt.xls")
## Prepare data
lbw.for.best.logistic <- within(lbw, {
    id   <- NULL        # Delete
    bwt  <- NULL
    race <- NULL
    ptl  <- NULL
    ftv  <- NULL

    y    <- low         # bwt into y
    low  <- NULL        # Delete bwt
})

## Reorder variables
lbw.for.best.logistic <-
    lbw.for.best.logistic[, c("age","lwt","race.cat","smoke","preterm","ht","ui","ftv.cat","y")]

## Perform
res.best.logistic <-
    bestglm(Xy = lbw.for.best.logistic,
            family = binomial,          # binomial family for logit
            IC = "AIC",                 # AIC chosen to select models
            method = "exhaustive")

      

Now, what I want to do is extract the regression formula from the best result, so that I can pass it along with another statistical procedure in my function.

The best model is stored in res.best.logistic$BestModel

, however the formula stored in str()

this object is simply a call y~.

to the unselected best selected model.

Is there a way to determine the best model formula?

+3


source to share


1 answer


Try formula

:



formula(res.best.logistic$BestModel)

      

+6


source







All Articles