jinseob2kim / jstable

Regression Tables from 'GLM', 'GEE', 'GLMM', 'Cox' and 'survey' Results.
https://jinseob2kim.github.io/jstable/
Apache License 2.0
22 stars 12 forks source link

"P for interaction" value when analyzing survey data using the TableSubgroupMultiCox function #34

Open Ink-Mo opened 3 months ago

Ink-Mo commented 3 months ago

Hi Prof. Jinseob Kim,

Thank you for your excellent work. I noticed that the TableSubgroupMultiCox function generates a "P for interaction" value when analyzing survey data. I would like to understand the calculation process for this "P for interaction" value when analyzing survey data. Could you please share the code? Thank you!

jinseob2kim commented 3 months ago
  1. 2 level: add interaction term to svycoxph
  2. 3 or more level: add interaction term to svycoxph & use survey::regTermTest

This is interaction code in forestcox.R(jstable)

      pv_int <- tryCatch(
        {
          pvs_int <- possible_svycoxph(as.formula(gsub(xlabel, paste0(xlabel, "*", var_subgroup), deparse(formula))), design = data) %>%
            summary() %>%
            coefficients()
          pv_int <- round(pvs_int[nrow(pvs_int), ncol(pvs_int)], decimal.pvalue)
          pv_int
        },
        error = function(e) {
          return(NA)
        }
      )

      ## interaction 여러개인 경우 pv_int 구하기
      model.int <- possible_svycoxph(as.formula(gsub(xlabel, paste0(xlabel, "*", var_subgroup), deparse(formula))), design = data)

      if (any(is.na(model.int))) {
      } else if (sum(grepl(":", names(coef(model.int)))) > 1) {
        model.int$call$formula <- as.formula(gsub(xlabel, paste0(xlabel, "*", var_subgroup), deparse(formula)))
        pv_anova <- survey::regTermTest(model.int, as.formula(paste0("~", xlabel, ":", var_subgroup)))
        pv_int <- round(pv_anova$p[1], decimal.pvalue)
      }