R/print.liferegr.R

Defines functions print.liferegr

Documented in print.liferegr

#' @title Print liferegr Object
#' @description Prints the concise information of liferegr fit.
#'
#' @param x The liferegr object to print.
#' @param ... Ensures that all arguments starting from "..." are named.
#'
#' @return A printout from the fit of an accelerated failue time model.
#'
#' @keywords internal
#'
#' @author Kaifeng Lu, \email{kaifenglu@@gmail.com}
#'
#' @export
print.liferegr <- function(x, ...) {
  lrchisq <- -2*(x$sumstat$loglik0 - x$sumstat$loglik1)
  degrees <- x$sumstat$nvar
  pvalue <- sapply(1:nrow(x$sumstat), function(i) {
    ifelse(degrees[i] > 0, 
           pchisq(lrchisq[i], degrees[i], 0, lower.tail = FALSE), 
           NA)
  })
  df1 <- cbind(x$sumstat[, c("n", "nevents", "loglik0", "loglik1")],
               lrchisq = lrchisq, df = degrees, pvalue = pvalue,
               x$sumstat[, c("niter", "dist")])
  
  p <- x$p
  if (p > 0) {
    if (!x$settings$robust) {
      if (x$settings$plci) {
        df <- data.frame(param = x$param,
                         coef = x$parest$beta,
                         expcoef = x$parest$expbeta,
                         se = x$parest$sebeta,
                         z = x$parest$z,
                         lower = x$parest$lower,
                         upper = x$parest$upper,
                         p = x$parest$p,
                         method = x$parest$method)
        
        colnames(df) <- c("param", "coef", "exp(coef)", "se(coef)", "z",
                          paste("lower", 1-x$settings$alpha),
                          paste("upper", 1-x$settings$alpha), 
                          "p", "method")
      } else {
        df <- data.frame(param = x$param,
                         coef = x$parest$beta,
                         expcoef = x$parest$expbeta,
                         se = x$parest$sebeta,
                         z = x$parest$z,
                         p = x$parest$p)
        
        colnames(df) <- c("param", "coef", "exp(coef)", "se(coef)", "z", "p")
      }
    } else {
      if (x$settings$plci) {
        df <- data.frame(param = x$param,
                         coef = x$parest$beta,
                         expcoef = x$parest$expbeta,
                         nse = x$parest$sebeta_naive,
                         se = x$parest$sebeta,
                         z = x$parest$z,
                         lower = x$parest$lower,
                         upper = x$parest$upper,
                         p = x$parest$p,
                         method = x$parest$method)
        
        colnames(df) <- c("param", "coef", "exp(coef)", "se(coef)",
                          "robust se", "z", 
                          paste("lower", 1-x$settings$alpha),
                          paste("upper", 1-x$settings$alpha), 
                          "p", "method")
      } else {
        df <- data.frame(param = x$param,
                         coef = x$parest$beta,
                         expcoef = x$parest$expbeta,
                         nse = x$parest$sebeta_naive,
                         se = x$parest$sebeta,
                         z = x$parest$z,
                         p = x$parest$p)
        
        colnames(df) <- c("param", "coef", "exp(coef)", "se(coef)",
                          "robust se", "z", "p")
      }
    }
  }
  
  print(df1, ..., na.print = "" , quote = FALSE )
  cat("\n")
  print(df, ..., na.print = "" , quote = FALSE )
  invisible(x)
}

Try the trtswitch package in your browser

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

trtswitch documentation built on Jan. 10, 2026, 5:08 p.m.