Predict() data in R from a gaussian glm model with inverse link

161 views Asked by At

I made a glm with the following formula

glm(lone_total ~ class + age + basic_needs_covered_id,
    data = mod_data_lone,
    family = gaussian(link = "inverse") ) 

The coefficients are interpreted with this equation:

Y=1/(β2X2+β1X1+β0)

Now to visualize my model, I need to predict a data set. With Gamma-models, I did this before using

pred_data <- predict(final_model, 
                    newdata = newdata_income,
                    se.fit = TRUE, 
                    type = "response")

and than run exp() on the vlaues

#log to exp
pred_data$lwr <- exp(pred_data$fit - 1.96 * pred_data$se.fit)
pred_data$upr <- exp(pred_data$fit + 1.96 * pred_data$se.fit)
pred_data$fit <- exp(pred_data$fit)

But this doesn't work on my current model, the slopes (or values) remain inverse. how can I predict the values based on the equation given above? Y=1/(β2X2+β1X1+β0)

1

There are 1 answers

0
gili On

I got it. Just 1/ instead of exp() in the last step:

pred_data$lwr <- 1/(pred_data$fit - 1.96 * pred_data$se.fit)
pred_data$upr <- 1/(pred_data$fit + 1.96 * pred_data$se.fit)
pred_data$fit <- 1/(pred_data$fit)