Skip to content

loss function of cox model #43

Answered by pbreheny
EQUIWDH asked this question in Q&A
Apr 19, 2023 · 3 comments · 2 replies
Discussion options

You must be logged in to vote

fit$loss returns the loss only (negative of cox partial likelihood), not the penalty.

The internal function ncvreg:::loss.ncvsurv(), as well as the modified version of it that you show above, assumes that the data has been ordered by survival time. In addition, loss.ncvsurv() returns the deviance (2*loss).

So:

library(ncvreg)
data(Lung)
X <- Lung$X
y <- Lung$y
fit <- ncvsurv(X, y)
l1 <- 2*fit$loss
l2 <- ncvreg:::loss.ncvsurv(cbind(fit$time, fit$fail), fit$linear.predictors)
cbind(l1, drop(l2)) |> head()
#>                l1          
#> 0.44806 1010.6732 1010.6732
#> 0.41786 1000.5671 1000.5555
#> 0.38970  992.8519  992.8484
#> 0.36344  986.8651  986.8599
#> 0.33894  982.1560  982.1534
#>…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@pbreheny
Comment options

Answer selected by pbreheny
@EQUIWDH
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #42 on April 20, 2023 15:10.