0

Does gtsummary work for glmer models? How can I modify the code commented on here? : regression models in r output table to word I would like to have a long table. Thanks!

dat3_long <- structure(list(
  ID = c("1", "1", "1", "1", "2", "2", "2", "2", "3", "3", "3", "3", "4", "4", "4", "4"),
  visit = c("0", "1", "3", "4", "0", "1", "3", "4", "0", "1", "3", "4", "0", "1", "3","4"),
  x1 = c("5.6", "1.5", "0.5", NA, "6", NA, NA, NA, "3.4","2.4", "2.5", "1", NA, 0, NA, "3.3"),
  x2 = c("0", "0", "0", "0", "1", "1", "1", "1", "2","2", "2", "2", "1", "1", "1", "1"),
  yone = c("0", NA, NA, NA, "1", "0", "0", "0", "0", "0", "0", "1", 1, NA, NA, "0"),
  yone0 = c("0", 1, NA, NA, "1", "0", "0", "0", "0", "0", "0", "1", NA, NA, 0, "0"),
  ytwo = c("0", NA, 1, NA, "1", "0", "0", "0", "0", "0", "0", "1", NA, 0, NA, "0"),
  ytwo0 = c("0", NA, NA, 1, "1", "0", "0", "0", "0", "0", "0", "1", NA, NA, NA, "0"),
  ythree = c("0", NA, 1, NA, "1", "0", "0", "0", "0", "0", "0", "1", NA, 0, NA, "0"),
  ythree0 = c("0", 1, NA, NA, "1", "0", "0", "0", "0", "0", "0", "1", NA, NA, NA, "0"),
  zone = c("0", NA, NA, 1, "1", "0", "0", "0", "0", "0", "0", "1", NA, 1, NA, "0"),
  zone0 = c("0", NA, NA, NA, "1", "0", "0", "0", "0", "0", "0", "1", NA, NA, 1, "0"),
  ztwo = c("0", NA, 1, NA, "1", "0", "0", "0", "0", "0", "0", "1", NA, NA, NA, "0"),
  ztwo0 = c("0", NA, NA, 1, "1", "0", "0", "0", "0", "0", "0", "1", NA, 1, NA, "0")),
row.names = 2:17, class = "data.frame")

#
#character to factor
names <- c(4:14)
dat3_long[,names] <- lapply(dat3_long[,names] , factor)
str(dat3_long)

#subset by x2 strata
strat_x0 <- subset(dat3_long,x2==0) 
strat_x1 <- subset(dat3_long,x2==1)
strat_x2 <- subset(dat3_long,x2==2)

#stratified model
strat_a <- glmer(yone ~ yone0 + visit + x1 +(1 | ID), data= strat_x0, family = binomial, control=glmerControl(optimizer="bobyqa", optCtrl=list(maxfun=100000)))
summary(strat_a)
strat_y <- glmer(yone ~ yone0 + visit + x1 +(1 | ID), data= strat_x1, family = binomial, control=glmerControl(optimizer="bobyqa", optCtrl=list(maxfun=100000)))
summary(strat_y)
strat_w <- glmer(yone ~ yone0 + visit + x1 +(1 | ID), data= strat_2, family = binomial, control=glmerControl(optimizer="bobyqa", optCtrl=list(maxfun=100000)))

#I want: OR and 95%CI of several models like above for different variables, like long format table in gtsummary

tab_model(strat_a, strat_y, strat_w)

I tried following:

# build models
tbl_uvregression(
  data = strat_x0,
  x = visit,
  method = glmer(yone ~ yone0 + visit + x1 +(1 | ID), data= strat_x0, family = binomial, control=glmerControl(optimizer="bobyqa", optCtrl=list(maxfun=100000))),
  method.args = list(family = binomial),
  exponentiate = TRUE
) %>%
  modify_header(label = "**Model Outcome**") %>%
  # add the number of evenets
  add_nevent() %>%
  # export as flextable instead of gt table
  as_flex_table()

#Error: grouping factors must have > 1 sampled level

table like enter image description here

OR best desired output: enter image description here

nnet
  • 39
  • 4

0 Answers0