user3129392
user3129392

Reputation: 11

What is the difference between the coxph and cph functions for calculating Cox's proportional hazards model?

I am trying to analyse a dataset (veteran, in package survival in R) with survival analysis. I found the function cph in package rms, which seems like different to coxph. What is the difference between these two functions?

Also, in this example,

model1<-cph(with(data=veteran,Surv(time,status)~rcs(age,4)+trt),x=TRUE,y=TRUE)

what's does rcs(age,4) mean?

Thanks for your help.

Upvotes: 1

Views: 7042

Answers (1)

alex keil
alex keil

Reputation: 1031

RCS = restricted cubic spline. You can find the function's help file by looking at help(package="rms")

Here's an excerpt of the source code, so you can see where the cph function calls the coxph.fit function (the guts of coxph in the survival package)


>cph

[...]
    if (nullmod) 
        f = NULL
    else {
        ytype = attr(Y, "type")
        fitter = if (method == "breslow" || method == "efron") {
            if (ytype == "right") 
                coxph.fit
            else if (ytype == "counting") 
                survival:::agreg.fit
            else stop(paste("Cox model doesn't support \"", ytype, 
                "\" survival data", sep = ""))
        }
        else if (method == "exact") 
            survival:::agexact.fit

[...]

    class(f) = c("cph", "rms", "coxph")
    f
}


Both cph and coxph give the same results as far as coefficients:


>library("survival")
>library("rms")
>
>x = rbinom(100, 1,.5)
>t = rweibull(100, 1, 1)
>
>m1 = coxph(Surv(t)~x)
>m2 = cph(Surv(t)~x)
>m1$coefficients
        x 
0.2226732 
>m2$coefficients
        x 
0.2226732 

But you can see that the authors of the cph function have added some extra components to the results to fit their needs. Thus cph will be useful if you need one of those extra features, but otherwise, coxph will do just fine.


>attributes(m1)
$names
 [1] "coefficients"      "var"               "loglik"            "score"            
 [5] "iter"              "linear.predictors" "residuals"         "means"            
 [9] "concordance"       "method"            "n"                 "nevent"           
[13] "terms"             "assign"            "wald.test"         "y"                
[17] "formula"           "call"             

$class
[1] "coxph"

>attributes(m2)
$names
 [1] "coefficients"      "var"               "loglik"            "score"            
 [5] "iter"              "linear.predictors" "residuals"         "means"            
 [9] "concordance"       "terms"             "n"                 "call"             
[13] "Design"            "assign"            "na.action"         "fail"             
[17] "non.slopes"        "stats"             "method"            "maxtime"          
[21] "time.inc"          "units"             "center"            "scale.pred"       

$class
[1] "cph"   "rms"   "coxph"

Upvotes: 4

Related Questions