function predict but with a warning message object not found

Hi guys, I'm trying to do a logistic regression. But I ran into a problem, when I use predict, I got a warning message that "object not found". And I don't understand why. Can anyone please help me solve this problem? Thank you very much.

Here is the data set.
https://drive.google.com/file/d/1iHxy3lbAh8AkmBaIr6hwi8tbtRxVvmtD/view?usp=sharing

Its description.
https://archive.ics.uci.edu/ml/datasets/statlog+(german+credit+data)

Here is my code.

noms_variables <- c("status_account","duration","history","purpose",
                  "amount","savings","employment","installement_rate",
                  "status_personnal","other_debtors","residence_since",
                  "property","age","other_installment","housing",
                  "nb_credits","job","liable","telephone","foreign","class")
credit0 <- read.table("GermanCredit.txt", col.names = noms_variables)
credit0$class <- as.factor(credit0$class-1)
credit <- subset(credit0, select=-c(foreign))

fit.logit <- glm(class~., data = credit, family = binomial(link = 'logit'))
summary(fit.logit)

selection <- step(fit.logit, direction = "backward")

summary(selection)

mod1 <- update(selection, ~. - purpose)
summary(mod1)

anova(selection, mod1, test="Chisq")

mod2 <- update(mod1, ~. - nb_credits)
summary(mod2)

anova(mod1, mod2, test="Chisq")

mod3 <- update(mod2, ~. - employment)
summary(mod3)

anova(mod2, mod3, test="Chisq")

mod4 <- update(mod3, ~. - age)
summary(mod4)

anova(mod3, mod4, test="Chisq")

newdata <- data.frame(class = 0)
predict(mod4, type = "response", newdata)

Warning message I got.
"Error in eval(predvars, data, env) : object 'status_account' not found"

Hi,

Maybe this link could be helpful.

anova(selection, mod1,  test = "Rao")   
anova(selection, mod1, test = "LRT")   
anova(selection, mod1, test = "Chisq") 

Hope it helps.

Greetings.

1 Like

Thank you, I solved this problem. But I have another problem.

I use function 'predict' to predict the probability that a client's class is 0, but I got a warning message "Error in eval(predvars, data, env) : object 'status_account' not found" like this

Could you please tell me how to fix it? Thank you.

I update my code about the model.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.