0

Data and libraries:

test <- tibble(start=c(1,2,5,2,1,7,3,4,8,8), 
              age=c(2,3,6,7,8,9,9,9,14,17), 
              event=c(1,1,0,1,1,1,1,0,0,0), 
              x=c(1,0,0,1,0,1,1,1,0,0),
              sex=c(0,0,0,0,0,1,1,1,1,1))

library(tidyverse)
library(broom)
library(survival)

I want to nest several grouped tibbles and create coxph objects and extract and nest data with tidy and glance (from broom package). In the tidy output I also want the data to be exponentiated and with confidence intervals. This works:

coxph_obj <- (coxph(Surv(start,  event) ~ x + sex + age, test)) 
tidy(coxph_obj, exponentiate = TRUE, conf.int = TRUE)

However, I dont know how to get exponentiate = TRUE, conf.int = TRUE to work in tidied = map(fit, tidy) below:

test %>%
  nest(data = -sex) %>% 
  mutate(
    fit = map(data, ~ coxph(Surv(start,  event) ~ x + sex + age, data = test)),
    tidied = map(fit, tidy),
    glanced = map(fit, glance)
  )

 unnest(c(tidied, glanced), names_repair = "universal" )
Droc
  • 257
  • 1
  • 2
  • 8
  • 1
    What does using `tidied = map(fit, tidy, exponentiate = TRUE, conf.int = TRUE)` give you in your `mutate`? – Ben Nov 03 '20 at 16:51
  • 1
    It worked like magic, thanx! – Droc Nov 03 '20 at 21:35
  • 1
    Glad to hear...you can provide additional arguments this way to get passed on to the mapped function... – Ben Nov 03 '20 at 21:40

1 Answers1

0

Answer provided by Ben in a comment:

"What does using tidied = map(fit, tidy, exponentiate = TRUE, conf.int = TRUE) give you in your mutate"

Droc
  • 257
  • 1
  • 2
  • 8