hydradon
hydradon

Reputation: 1446

R: error when doing backward feature selection with rms::fastbw on caret model

I want to perform backward feature selection using the function fastbw from the rms package. I use a sample dataset PimaIndiansDiabetes as below:

library(mlbench)
data(PimaIndiansDiabetes)

library(caret)
trControl <- trainControl(method = "repeatedcv",
                          repeats = 3,
                          classProbs = TRUE,
                          number = 10, 
                          savePredictions = TRUE,
                          summaryFunction = twoClassSummary)

caret_model <- train(diabetes~., 
                     data=PimaIndiansDiabetes, 
                     method="glm", 
                     trControl=trControl)

library(rms)
reduced_model <- fastbw(caret_model$finalModel)

This gives me an error:

Error in fastbw(caret_model$finalModel) : fit does not have design information

May I know what this means and how to resolve it?

Upvotes: 0

Views: 983

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226961

You're probably stuck. fastbw() works only with models from rms, i.e. ?fastbw says:

fit: fit object with ‘Varcov(fit)’ defined (e.g., from ‘ols’, ‘lrm’, ‘cph’, ‘psm’, ‘glmD’)

I tried your fit with method="lrm" (lrm is rms's logistic regression tool), but got

Error: Model lrm is not in caret's built-in library

I think you're going to have to find another way to do stepwise regression, e.g. see this question: i.e. using library(MASS) and then method="glmStepAIC" (within caret), or stepAIC (from scratch).

It's not obvious to me why you're training a model and then doing stepwise regression ...

Upvotes: 2

Related Questions