Plotting adjusted KM curve

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Plotting adjusted KM curve

Sorkin, John
Colleagues,
I am using the coxph to model survival time. How do I plot an adjusted Kaplan Meir plot resulting from coxph? The code I would like to run would start with:

# run cox model
fit1Cox <- coxph(surv_object ~age+sex,data=mydata)

I have no idea what would follow.

I would like to plot adjusted KM curves for men vs. women at age 65.

Thank you,
John


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Plotting adjusted KM curve

John Fox
Dear John,

I think that what you're looking for is

plot(survfit(fit1Cox, newdata=data.frame(age=rep(65, 2),
sex=factor("female", "male"))))

assuming, of course, that sex is a factor with levels "female" and "male".

I hope this helps,
  John

John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/

On 2021-04-04 9:34 p.m., Sorkin, John wrote:

> Colleagues,
> I am using the coxph to model survival time. How do I plot an adjusted Kaplan Meir plot resulting from coxph? The code I would like to run would start with:
>
> # run cox model
> fit1Cox <- coxph(surv_object ~age+sex,data=mydata)
>
> I have no idea what would follow.
>
> I would like to plot adjusted KM curves for men vs. women at age 65.
>
> Thank you,
> John
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Plotting adjusted KM curve

John Fox
In reply to this post by Sorkin, John
On 2021-04-04 10:45 p.m., John Fox wrote:
> Dear John,
>
> I think that what you're looking for is
>
> plot(survfit(fit1Cox, newdata=data.frame(age=rep(65, 2),
> sex=factor("female", "male"))))

Whoops, that should be

plot(survfit(fit1Cox, newdata=data.frame(age=rep(65, 2),
sex=factor(c("female", "male")))))

John


>
> assuming, of course, that sex is a factor with levels "female" and "male".
>
> I hope this helps,
> John
>
> John Fox, Professor Emeritus
> McMaster University
> Hamilton, Ontario, Canada
> web: https://socialsciences.mcmaster.ca/jfox/
>
> On 2021-04-04 9:34 p.m., Sorkin, John wrote:
>> Colleagues,
>> I am using the coxph to model survival time. How do I plot an adjusted
>> Kaplan Meir plot resulting from coxph? The code I would like to run
>> would start with:
>>
>> # run cox model
>> fit1Cox <- coxph(surv_object ~age+sex,data=mydata)
>>
>> I have no idea what would follow.
>>
>> I would like to plot adjusted KM curves for men vs. women at age 65.
>>
>> Thank you,
>> John
>>
>>
>>     [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Plotting adjusted KM curve

PIKAL Petr
In reply to this post by Sorkin, John
Hi

Google answered

https://rdrr.io/bioc/survcomp/man/km.coxph.plot.html

Is it what do you want?

Cheers
Petr

> -----Original Message-----
> From: R-help <[hidden email]> On Behalf Of Sorkin, John
> Sent: Monday, April 5, 2021 3:35 AM
> To: [hidden email] ([hidden email]) <[hidden email]>
> Subject: [R] Plotting adjusted KM curve
>
> Colleagues,
> I am using the coxph to model survival time. How do I plot an adjusted
Kaplan
> Meir plot resulting from coxph? The code I would like to run would start
with:

>
> # run cox model
> fit1Cox <- coxph(surv_object ~age+sex,data=mydata)
>
> I have no idea what would follow.
>
> I would like to plot adjusted KM curves for men vs. women at age 65.
>
> Thank you,
> John
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Plotting adjusted KM curve

Göran Broström-3
In reply to this post by Sorkin, John


On 2021-04-05 03:34, Sorkin, John wrote:
> Colleagues,
> I am using the coxph to model survival time. How do I plot an adjusted Kaplan Meir plot resulting from coxph? The code I would like to run would start with:
>
> # run cox model
> fit1Cox <- coxph(surv_object ~age+sex,data=mydata)
>
> I have no idea what would follow.

You should look at

?survfit.coxph

in the survival package, especially the 'newdata' argument.
>
> I would like to plot adjusted KM curves for men vs. women at age 65.

Then I guess that you should stratify on sex:

fit <- coxph(surv_object ~ age + strata(sex), data = mydata)

sfit <- survfit(fit, newdata = data.frame(age = 65))
plot(sfit)

HTW, Göran

>
> Thank you,
> John
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.