R/coxFormula.R

Defines functions coxFormula.GLMnet coxFormula.prodlim coxFormula.glm coxFormula.phreg coxFormula.coxph coxFormula.cph coxFormula

Documented in coxFormula coxFormula.coxph coxFormula.cph coxFormula.glm coxFormula.GLMnet coxFormula.phreg coxFormula.prodlim

### coxFormula.R --- 
#----------------------------------------------------------------------
## Author: Thomas Alexander Gerds
## Created: Apr 27 2025 (07:31) 
## Version: 
## Last-Updated: May  8 2025 (13:59) 
##           By: Thomas Alexander Gerds
##     Update #: 6
#----------------------------------------------------------------------
## 
### Commentary: 
## 
### Change Log:
#----------------------------------------------------------------------
## 
### Code:

## * coxFormula
#' @title Extract the formula from a Cox model
#' @description Extract the formula from a Cox model
#' @name coxFormula 
#' @param object The fitted Cox regression model object either
#'     obtained with \code{coxph} (survival package), \code{cph}
#'     (rms package), or \code{phreg} (mets package).
#' 
#' @author Brice Ozenne broz@@sund.ku.dk

#' @rdname coxFormula
#' @export
coxFormula <- function(object){
  UseMethod("coxFormula") 
} 

## ** coxFormula.cph
#' @rdname coxFormula
#' @method coxFormula cph
#' @export
coxFormula.cph <- function(object){
  return(object$sformula)
}

## ** coxFormula.coxph
#' @rdname coxFormula
#' @method coxFormula coxph
#' @export
coxFormula.coxph <- function(object){
    if(object$nevent>0){
        return(object$formula)
    }else{
        out <- object$terms
        extra.attr <- names(attributes(out))
        for(iAttr in extra.attr){
            attr(out, iAttr) <- NULL
        }
        return(as.formula(out))
    }
}

## ** coxFormula.phreg
#' @rdname coxFormula
#' @method coxFormula phreg
#' @export
coxFormula.phreg <- function(object){
  return(object$formula)
}
## ** coxFormula.glm
#' @rdname coxFormula
#' @method coxFormula glm
#' @export
coxFormula.glm <- function(object){
  return(stats::formula(object))
}

## ** coxFormula.prodlim
#' @rdname coxFormula
#' @method coxFormula prodlim
#' @export
coxFormula.prodlim <- function(object){
    return(stats::formula(object))
}

## ** coxFormula.GLMnet
#' @rdname coxFormula
#' @method coxFormula GLMnet
#' @export
coxFormula.GLMnet <- function(object){
    return(stats::formula(object$terms))
}

######################################################################
### coxFormula.R ends here

Try the riskRegression package in your browser

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

riskRegression documentation built on June 8, 2025, 11:33 a.m.