Kaplan Meyer site for Cox regression

I have a Cox proportional risk model created using the following code in R, which predicts mortality. Covariate A, B, and C are added simply to avoid confusion (i.e. age, gender, race), but we are really interested in the predictor X. X is a continuous variable.

cox.model <- coxph(Surv(time, dead) ~ A + B + C + X, data = df) 

Now I am having problems with the graphics of the Kaplan-Meyer curve. I was looking for how to create this figure, but I was out of luck. I'm not sure if Kaplan-Meyer is possible for the Cox model? Does Kaplan Meyer correct my covariates or doesn’t need them?

What I tried is below, but I was told that this is wrong.

 plot(survfit(cox.model), xlab = 'Time (years)', ylab = 'Survival Probabilities') 

I also tried to build a figure that shows the cumulative danger of mortality. I don’t know if I am doing it right, since I tried several different ways and got different results. Ideally, I would like to build two lines that show the mortality risk for the 75th percentile X and one that shows the 25th percentile X. How can I do this?

I could list everything that I tried, but I do not want to confuse anyone!

Many thanks.

+7
r plot survival-analysis cox-regression
source share
2 answers

Here is an example taken from this article .

 url <- "http://socserv.mcmaster.ca/jfox/Books/Companion/data/Rossi.txt" Rossi <- read.table(url, header=TRUE) Rossi[1:5, 1:10] # week arrest fin age race wexp mar paro prio educ # 1 20 1 no 27 black no not married yes 3 3 # 2 17 1 no 18 black no not married yes 8 4 # 3 25 1 no 19 other yes not married yes 13 3 # 4 52 0 yes 23 black yes married yes 1 5 # 5 52 0 no 19 other yes not married yes 3 3 mod.allison <- coxph(Surv(week, arrest) ~ fin + age + race + wexp + mar + paro + prio, data=Rossi) mod.allison # Call: # coxph(formula = Surv(week, arrest) ~ fin + age + race + wexp + # mar + paro + prio, data = Rossi) # # # coef exp(coef) se(coef) zp # finyes -0.3794 0.684 0.1914 -1.983 0.0470 # age -0.0574 0.944 0.0220 -2.611 0.0090 # raceother -0.3139 0.731 0.3080 -1.019 0.3100 # wexpyes -0.1498 0.861 0.2122 -0.706 0.4800 # marnot married 0.4337 1.543 0.3819 1.136 0.2600 # paroyes -0.0849 0.919 0.1958 -0.434 0.6600 # prio 0.0915 1.096 0.0286 3.194 0.0014 # # Likelihood ratio test=33.3 on 7 df, p=2.36e-05 n= 432, number of events= 114 

Note that the model uses fin, age, race, wexp, mar, paro, prio to predict arrest . As mentioned in this document , the survfit() function uses the Kaplan-Meyer score for survival.

 plot(survfit(mod.allison), ylim=c(0.7, 1), xlab="Weeks", ylab="Proportion Not Rearrested") 

survival graph

We get a graph (with a 95% confidence interval) for survival. For the cumulative risk norm, you can do

 # plot(survfit(mod.allison)$cumhaz) 

but this does not give confidence intervals. However, do not worry! We know that H (t) = -ln (S (t)), and we have confidence intervals for S (t). All we need to do is

 sfit <- survfit(mod.allison) cumhaz.upper <- -log(sfit$upper) cumhaz.lower <- -log(sfit$lower) cumhaz <- sfit$cumhaz # same as -log(sfit$surv) 

Then just sketch these

 plot(cumhaz, xlab="weeks ahead", ylab="cumulative hazard", ylim=c(min(cumhaz.lower), max(cumhaz.upper))) lines(cumhaz.lower) lines(cumhaz.upper) 

cumhaz

You want to use survfit(..., conf.int=0.50) to get bands at 75% and 25% instead of 97.5% and 2.5%.

+5
source share

Querying the estimated survival curve at the 25th and 75th percentiles for X first requires defining these percentiles and determining the values ​​for all other covariates in the data frame, which will be used as the newdata argument to continue:

You can use the data provided by other users of the Fox site, although it was required to build a url object on my machine:

  url <- url("http://socserv.mcmaster.ca/jfox/Books/Companion/data/Rossi.txt") Rossi <- read.table(url, header=TRUE) 

This is probably not the best example for this wquestion, but it has a numerical variable that we can calculate quartiles:

 > summary(Rossi$prio) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.000 1.000 2.000 2.984 4.000 18.000 

Thus, it will be a suitable model and challenges for protection:

  mod.allison <- coxph(Surv(week, arrest) ~ fin + age + race + prio , data=Rossi) prio.fit <- survfit(mod.allison, newdata= data.frame(fin="yes", age=30, race="black", prio=c(1,4) )) plot(prio.fit, col=c("red","blue")) 

enter image description here

+2
source share

All Articles