【问题标题】:Using mgcv gam() and gtsummary tbl_uvregression()使用 mgcv gam() 和 gtsummary tbl_uvregression()
【发布时间】:2021-05-20 17:16:25
【问题描述】:

我们如何为tbl_uvregression()method = gam 中的某些变量指定平滑样条曲线?

data %>% 
 select(outcome, predictors) %>% 
 tbl_uvregression(
   method = gam,
   y = outcome,
   method.args = list(family = binomial),
   exponentiate = T) 

例如,如果我想在变量 x1 的 gam 模型公式中表示 s(x1),我们如何在上面的代码中添加它?

【问题讨论】:

    标签: gtsummary


    【解决方案1】:

    您不能将变量包装在函数中,例如 s() 中的 tbl_uvregression()。您需要使用tbl_regression() 构建单独的表,然后将它们堆叠在一起。下面的代码示例!但是,这有点奇怪,因为平滑项没有单一的优势比......所以你只是得到一个 p 值表......

    library(gtsummary)
    packageVersion("gtsummary")
    #> [1] '1.4.1'
    library(tidyverse)
    library(mgcv)
    #> Loading required package: nlme
    #> 
    #> Attaching package: 'nlme'
    #> The following object is masked from 'package:dplyr':
    #> 
    #>     collapse
    #> This is mgcv 1.8-35. For overview type 'help("mgcv-package")'.
    
    
    tbl_uv <-
      tibble(variable = c("age", "marker")) %>%
      rowwise() %>%
      mutate(
        # build reg models
        tbl = 
          glue::glue("response ~ s({variable})") %>%
          as.formula() %>%
          gam(data =  trial, family = binomial) %>%
          tbl_regression() %>%
          list()
      ) %>%
      # stack the regression tables
      pull() %>%
      tbl_stack()
    

    reprex package (v2.0.0) 于 2021-05-20 创建

    【讨论】:

      猜你喜欢
      • 2016-01-07
      • 2020-03-21
      • 2020-12-25
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多