I have a logistic stored model. I want to remove a variable from the formula, without running the model again (I want to keep the rest of the coefficients).
My model:
> class(lr)
[1] "glm" "lm"
And the formula is:
> lr$formula
target ~ grupoAntig + nu_seguros_1TRUNC + cd_sexo + grupoEdad +
vl_limite_aeQU + vl_ltd_6QU + Revolv3 + nu_servicios_1TRUNC +
fl_cliente_hit + nu_resumen_6 + fl_rv
I want to remove fl_cliente_hit.
I did:
a<-strsplit(as.character(lr$formula)[3], "+ ")
a<-a[[1]][a[[1]]!=a[[1]][17]]
a<-a[a!=a[16]]
a0<-paste(a, collapse = ' + ')
lr$formula<-as.formula(paste0("target ~ ",a0))
And I get the desired formula:
> lr$formula
target ~ grupoAntig + nu_seguros_1TRUNC + cd_sexo + grupoEdad +
vl_limite_aeQU + vl_ltd_6QU + Revolv3 + nu_servicios_1TRUNC +
nu_resumen_6 + fl_rv
But I'm not sure if I run a predict function if the model uses the new formula or the previous one. In this case:
predict(lr, train, type=c("response"))
If it keeps the original model, there must be a way to exclude one variable keeping the rest equal. How can I do this?