Using glmulti with GEE models

24 views Asked by At

I can use glmulti with lmer models, but am struggling to make it work for a GEE. Here is an example showing an lmer version which works, and a GEE version I'm stuck on.

library(tidyverse)
library(lme4)
library(geepack)
library(glmulti)


data <- mtcars %>% as_tibble() %>% 
  mutate(cyl = factor(cyl))

# lmer version
basic_lmm <- lmer(mpg ~ hp + disp + wt + (1|cyl), data)

# use glmulti to find the best parameters

# custom fit function
lmer.glmulti <- function (formula, data, random = "", ...) {
  lmer(paste(deparse(formula), random), data = data, REML=F, ...)
}

res_glmulti <- glmulti(
  mpg ~ hp  + disp + wt, data =  data, fitfunc = lmer.glmulti, random = "+(1|cyl)", 
  crit="aicc", method = "h", confsetsize = 20, level = 1)

print(res_glmulti)


# gee version
basic_gee <- geeglm(mpg ~ hp  + disp + wt, id = cyl, data = data, family = gaussian, corstr = "independence")

gee.glmulti <- function (formula, data, id, ...) {
  geeglm(paste(deparse(formula)), data = data, family = gaussian, corstr = "independence", id = "cyl", ...)
}

res_gee <- glmulti(
  mpg ~ hp  + disp + wt, data =  data, fitfunc = gee.glmulti, id = "cyl",
  crit="aicc", method = "h", confsetsize = 20, level = 1)

print(res_gee)


1

There are 1 answers

0
Jeff On

I think this may have worked - It runs without error, but doesn't exactly give a result that makes sense.

gee.glmulti <- function (formula, data, ...) {
  geeglm(formula, data = data, family = gaussian, corstr = "independence", id = data$cyl, ...)
}


res_gee <- glmulti(
  mpg ~ hp  + disp + wt + qsec, data =  data, fitfunc = gee.glmulti,
  crit="aicc", method = "h", confsetsize = 20, level = 1)



print(res_gee)