Jeff Newmiller jdnewmil at dcn.davis.ca.us
Sat Oct 7 18:18:13 CEST 2017

```Change the columns into factors before you give them to the coxph function, e.g.

df\$treatment <- factor( df\$treatment )

--
Sent from my phone. Please excuse my brevity.

On October 7, 2017 5:01:19 PM GMT+01:00, "Ted Beginner (RStudio) via R-help" <r-help at r-project.org> wrote:
>
>For adjusted survival curves I took the sample code from here:
>https://rpubs.com/daspringate/survival
>and adapted for my date, but ... have a QUESTION.
>
>library(survival)
>library(survminer)
>ID start stop censor sex age stage treatment
>1 1 0 66 0 2 1 3 1
>2 2 0 18 0 1 2 4 2
>3 3 0 43 1 2 3 3 1
>4 4 0 47 1 2 3 NA 2
>5 5 0 26 0 1 4 3 NA
>
># THANKS, DAVID WINSEMIUS for remark!!! ("R regression functions allow
>you to use column names.")
>model <- coxph( Surv(time = start,
>time2 = stop,
>event = censor) ~ treatment + age + sex + stage, data = df)
>
>plot(survfit(model),
>las=1,
>xscale = 1.00,
>xlab = "Months after diagnosis",
>ylab = "Proportion survived",
>main = "Baseline Hazard Curve")
>
>#HOW TO EXPLAIN TO R, THAT treatment, age, sex and stage ARE FACTORS,
>AND NOT CONTINUOUS VAR?
>treat <- with (df,
>data.frame (
>treatment = levels(treatment),
>age = rep(levels(age)[1], 2),
>sex = rep(levels(sex)[1], 2),
>stage = rep(levels(stage)[1], 2)))
>
>str(treat)
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help