ddsjoberg / gtsummary

Presentation-Ready Data Summary and Analytic Result Tables
http://www.danieldsjoberg.com/gtsummary
Other
1.06k stars 128 forks source link

tbl_regression does not work with geeglm if using rcspline.eval in formula #338

Closed emilyvertosick closed 4 years ago

emilyvertosick commented 4 years ago

tbl_regression will work for a geeglm model if the splines are manually created, but if the function rcspline.eval is included in the formula, tbl_regression gives an error

library(tidyverse)
library(gtsummary)

# Creating model with manually-calculated splines
gee_manualsplines <-
  geepack::geeglm(
    #we are interested in the relationship between weight and time
    as.formula("weight ~ Time + sp2Time + sp3Time"),
    data = ChickWeight %>% 
      #we need to add spline terms for Time
      left_join(
        Hmisc::rcspline.eval(ChickWeight$Time, nk = 4, inclx = TRUE, norm = 0) %>%
          as_tibble(.name_repair = "unique") %>%
          set_names("Time", "sp2Time", "sp3Time") %>%
          unique(),
        by = c("Time") 
      ),
    family = gaussian,
    #we have multiple of weight over time for each chick
    id = Chick,
    corstr = "exchangeable"
  )
#> New names:
#> * `` -> ...2
#> * `` -> ...3
#> New names:
#> * `` -> ...2
#> * `` -> ...3
#> New names:
#> * `` -> ...2
#> * `` -> ...3
#> New names:
#> * `` -> ...2
#> * `` -> ...3

gee_manualsplines %>%
  tbl_regression()

image


# Creating model with rcspline.eval in formula
gee_with_splines <-
  geepack::geeglm(
    #we are interested in the relationship between weight and time
    as.formula("weight ~ Diet + rcspline.eval(Time, nk = 4, inclx = TRUE, norm = 0)"),
    data = ChickWeight,
    family = gaussian,
    #we have multiple of weight over time for each chick
    id = Chick,
    corstr = "exchangeable"
  )

gee_with_splines %>%
  tbl_regression()
#> Warning: non-unique value when setting 'row.names': 'rcspline.eval(Time, nk = 4,
#> inclx = TRUE, norm = 0)'
#> Error in `.rowNamesDF<-`(x, value = value): duplicate 'row.names' are not allowed

Created on 2020-01-09 by the reprex package (v0.3.0)

ddsjoberg commented 4 years ago

related to #337. This error occurs because of a failure in tidy(). When the name are not unique, the geepack() summary function also errors causing the tidy() error.

Thoughts @emilyvertosick @margarethannum @karissawhiting