R/coxphutils.R

Defines functions .as.survival.coxph.summary .as.survival.coxph.model

#' @importFrom stats as.formula
.as.survival.coxph.model <- function(model) {
    coefs <- model$coefficients_table
    df <- length(coefs$names)
    list(coefficients = structure(coefs$coefficients, names = coefs$names),
         var          = model$var_coef,
         loglik       = c(model$null_loglik, model$loglik),
         score        = model$score_test,
         iter         = model$iter,
         method       = model$ties,
         n            = model$n,
         nevent       = model$total_event,
         wald.test    = structure(model$wald_test,
                                  names = if (df == 1L) coefs$names else NULL),
         call         = as.formula(model$formula))
}

#' @importFrom stats as.formula pchisq
.as.survival.coxph.summary <- function(model) {
    coefs <- model$coefficients_table
    df <- length(coefs$names)
    summary <- list(
             call         = as.formula(model$formula),
             n            = model$n,
             loglik       = model$loglik,
             nevent       = model$total_event,
             concordance  = model$concordance,
             coefficients = structure(cbind(coefs$coefficients,
                                            coefs$exp_coef,
                                            coefs$se_coef,
                                            coefs$z_coef,
                                            1 - pchisq(coefs$z_coef^2, 1)),
                                      dimnames = list(coefs$names,
                                                      c("coef", "exp(coef)", "se(coef)", "z", "Pr(>|z|)"))),
             conf.int     = NULL,
             logtest      = c(test   = model$loglik_test,
                              df     = df,
                              pvalue = 1 - pchisq(model$loglik_test, df)),
             sctest       = c(test   = model$score_test,
                              df     = df,
                              pvalue = 1 - pchisq(model$score_test, df)),
             rsq          = c(rsq    = model$rsq,
                              maxrsq = model$maxrsq),
             waldtest     = c(test   = model$wald_test,
                              df     = df,
                              pvalue = 1 - pchisq(model$wald_test, df)),
             used.robust  = FALSE)
    new("H2OCoxPHModelSummary", summary = summary)
}

Try the h2o package in your browser

Any scripts or data that you put into this service are public.

h2o documentation built on Aug. 9, 2023, 9:06 a.m.