annennenne / geeasy

R package with tools for fitting generalized linear models with clustered observations using generalized estimating equations.
3 stars 0 forks source link

Standard errors for predictions #5

Open annennenne opened 2 weeks ago

annennenne commented 2 weeks ago

We have not implemented a predict() method for geeglm objects. Since the class inherits from glm, it calls predict.glm(). This works for point estimates, but trying to compute standard errors results in an error. Here is a toy example that invokes the error:

diab <- c("none", "mat", "pat")

d <- data.frame(diab = rep(diab, 50),
                lga = sample(c(0,1), 1500, replace = TRUE, prob = c(0.8, 0.2)),
                mpnr <- rep(1:750, each = 2))
library(geeasy)
m <- geelm(lga ~ diab, data = d, family = "binomial", id = mpnr,
            corstr = "exchangeable")

# Runs with no problems
predict(m, newdata = data.frame(diab = diab)) 

# Error in scale^2 : non-numeric argument to binary operator
predict(m, newdata = data.frame(diab = diab), se.fit = TRUE) 
annennenne commented 2 weeks ago

While we are at it, I think it would be ideal to also implement an option to add (Wald?) confidence intervals to the predictions, similar to predict.lm().