0

I am trying to fit a set of univariate logistic regression models with tbl_uvregression() based on a complex survey design object. I have tried several approaches based on online resources but still not able to get through. Below is the example code from my last attempt:

 test_fit <-
    survey::svydesign(id=~psu, strata=~strata, weights=~iweight, data=mm2, nest=T) %>% 
    tbl_uvregression(
      method = glm,
      y = medcare_recvd_notrecvd,
      method.args = list(family = binomial),
      include = c(age_yr_grp,educ,placeres),
      exponentiate = TRUE,    
      pvalue_fun = ~style_pvalue(.x, digits = 2),
      label = list(age_yr_grp ~ "Age", educ ~ "Education", placeres ~ "Area of residence")) %>%
    add_glance_source_note()
    
    
 test_fit

Any solution to this will be much appreciated.

  • I can look more closely when I'm at a computer. But at first glance, I think the issue it the method argument. glm cannot handle a survey object. Try replacing it with survey::svyglm – Daniel D. Sjoberg Apr 16 '21 at 12:01
  • Thanks for your response. I edited the code as suggested but got this error message: `Error in is_string(pattern) : object 'x' not found 5. is_string(pattern) 4. add_significance_stars(., x, hide_ci = F, hide_p = T, hide_se = F) 3. .prep_glance_statistics(x = x, include = { { include } ... 2. add_glance_source_note(.) 1. survey::svydesign(id = ~psu, strata = ~strata, weights = ~iweight, data = mm2, nest = T) %>% tbl_uvregression(method = survey::svyglm, y = medcare_recvd_notrecvd, include = c(age_yr_grp, educ, placeres), method.args = list(family = binomial), exponentiate = TRUE, ` – user14896383 Apr 16 '21 at 12:08
  • Can you please create a reprex, including code and data I can run on my machine? – Daniel D. Sjoberg Apr 16 '21 at 12:13
  • Another thing is that `add_glance_source_note()` cannot be used with `tbl_uvregression()`. Also, `tbl_uvregression()` added support for survey objects in v1.4.0. Are you on the most recent version? – Daniel D. Sjoberg Apr 16 '21 at 16:21
  • Thanks very much @DanielD.Sjoberg. I have been struggling to create the repex you requested. Meanwhile, I would not mind sharing with you via email if that is ok? And yes, I just updated all packages in my working environment. I apologize for making this process difficult; I must note that I am an **` Rmertuer `** trying to learn R as fast as possible. – user14896383 Apr 17 '21 at 13:56
  • Here is a post with details on how to create a reprex https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example . if after reviewing the post, the reprex can't be created, feel free to email me . my email is listed here https://cran.r-project.org/package=gtsummary – Daniel D. Sjoberg Apr 17 '21 at 14:01

1 Answers1

1

The below works perfectly after incorporating @Daniel D. Sjoberg's suggestions. Thanks for your help.

 test_fit <-
    survey::svydesign(id=~psu, strata=~strata, 
                      weights=~iweight, data=mm2, nest=T) %>% 
    tbl_uvregression(
      method = survey::svyglm,
      y = medcare_recvd_notrecvd,
      method.args = list(family = binomial),
      include = c(age_yr_grp,educ,placeres),
      exponentiate = TRUE,    
      pvalue_fun = ~style_pvalue(.x, digits = 2),
      label = list(age_yr_grp ~ "Age", 
                   educ ~ "Education", 
                   placeres ~ "Area of residence")) %>%
    add_significance_stars(hide_ci = F, hide_p = T, hide_se = T)     
    
 test_fit