Skip to content

tidy.survreg function fails when robust = T in survreg model #728

@poppymiller

Description

@poppymiller

Error when using robust regression in survreg. I think the issue is that robust regression gives a summary table with an extra column (called "(Naive SE)").

fmla <- as.formula(paste("Surv(time, status) ~ ","karno + age" ))
fit <- survreg(formula = fmla, data = veteran, dist = "lognormal", robust = T)
broom::tidy(fit)

summary(fit)$table

I propose changing the tidy.survreg function as follows to fix this error

  tidy.survreg <- function(x, conf.level = .95, conf.int = FALSE, ...) {
  s <- summary(x)
  # add extra column name here
  nn <- c("estimate", "std.error", "(Naive SE)", "statistic", "p.value")
  ret <- fix_data_frame(s$table, newnames = nn)
  
  if(conf.int){
    # add confidence interval
    ci <- stats::confint(x, level = conf.level)
    colnames(ci) <- c("conf.low", "conf.high")
    ci <- fix_data_frame(ci)
    ret <- as_tibble(merge(ret, ci, all.x = TRUE, sort = FALSE))
  }
  
  ret
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions