Using predict function in R


I fit a model based on 150 some observations. I am having trouble with the syntax of the predict function. I've spent a few hours with this silly thing and I have a headache.


I have 4 explanatory variables call them x1,x2,x3,x4
I have 10 different combinations of the variables for which I want to predict the response.
So, a 10 x 4 data_frame
I would ideally like to have 10 predicted values for the response

but when i try to do this....
predict(model, data_frame, type=c("response"))

I get a warning message about the row numbers not matching up. And R spits 150 values at me.
Look at the note in the help page for the predict.glm function. I suspect that the predict function is using a predictor either from the original data frame or from your workspace. The question is, why? One reason is that you're missing a predictor in the newdata data frame, so the predict function is getting the variable from somewhere else.
Last edited:


Omega Contributor
Can you explain why you have 10 different combinations? I don't follow that part. So they aren't interaction terms, but you just want to get predicted probabilities for certain combinations of variables, say given they are binary IVs.


Ambassador to the humans
It's hard to help without seeing your actual code.

Can you try to make a minimal reproducible example? Try to fit a model using mtcars and predicting some new observations for that. If you can get that to work then maybe that'll help you with your original problem. If you run into the same issue then that's great too because then we'll actually be able to see what you're doing and help you fix it.