0
$\begingroup$

I am doing a negative binomial regression:

m1 <- glm.nb(Trip ~ Origin + Destination + Distance, data)

I then wanted to get the predicted values to compare with the actual values

PredictTrip <- predict(m1)

My question is, I read on several websites that the predicted values need to be exponentiated because it is in log form. However, if I exponentiate the predicted values, it becomes ridiculously large (i.e. E+20, or even Infinity). If I did not exponentiate it, the values are close and comparable to the actual values. Which one is right? Thanks.

$\endgroup$
1
$\begingroup$

You don't necessarily need to exponentiate.

When you execute predict(m1), what is called is the predict.glm() function. Here is its help page:

Usage:

     ## S3 method for class 'glm'
     predict(object, newdata = NULL,
                 type = c("link", "response", "terms"),
                 se.fit = FALSE, dispersion = NULL, terms = NULL,
                 na.action = na.pass, ...)

Note in particular the type parameter, which governs what type of predictions or fits you will get. By default (type="link"), you get a prediction on the level of the link function. What you want is a mean response prediction, so do

predict(m1, type="response")

You may be interested in Regression predictions show far less variance than expected.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.