[R] How to use predict() so that one retains the rows that they're associated with?

Michael Dewey lists at dewey.myzen.co.uk
Thu Oct 20 14:44:03 CEST 2016

Some more context would help here but here goes anyway.

You should have a vector of predictions with length equal to the number 
of rows in your original data-set so you can just use cbind. If that is 
not true check the documentation for the correct setting of na.action. 
If you used newdata = in your call to predict then your predictions 
apply to the new data, not the old, so amend my statement as appropriate.

If that does not answer then make a small example data-set, run glm on 
it, run predict, and then show us the data-set, the output from glm, the 
output from predict, and what went wrong when you tried to cbind them.

On 20/10/2016 12:40, mviljamaa wrote:
> I'm using predict() for my glm() logistic model, but I'm having trouble
> relating the predicted results to the rows that produced them.
> I want to be able to plot predictions along some categorical variables.
> So what can I do in order to get predicted values but also know what
> variable values produced them?
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


More information about the R-help mailing list