Hi, I'm going crazy trying to plot a quite simple graph. i need to plot estimated hazard rate from a cox model. supposing the model i like this: coxPhMod=coxph(Surv(TIME, EV) ~ AGE+A+B+strata(C) data=data) with 4 level for C. how can i obtain a graph with 4 estimated (better smoothed) hazard curve (base-line hazard + 3 proportional) to highlight the effect of C. thanks!! laudan [[alternative HTML version deleted]]
lau pel wrote> Hi, > I'm going crazy trying to plot a quite simple graph. > i need to plot estimated hazard rate from a cox model. > supposing the model i like this: > coxPhMod=coxph(Surv(TIME, EV) ~ AGE+A+B+strata(C) data=data) > with 4 level for C. > how can i obtain a graph with 4 estimated (better smoothed) hazard curve > (base-line hazard + 3 proportional) to highlight the effect of C. > thanks!! > laudan > > (1) The curves won't be proportional if you stratify on C. The curves are > proportional for AGE, A, and B in your model. > (2) If you want to deal with an individual stratum, you can extract them > individually from survfit > > dataset <- > data.frame(Time = rexp(100, 1), > A = rnorm(100), > B = rnorm(100), > C = factor(rep(letters[1:4],25))) > mod <- coxph(Surv(Time) ~ A + B + strata(C), data=dataset) > > # first stratum fit > survfit(mod, newdata=data.frame(A=rep(0,4), B=rep(0,4), > C=factor(letters[1:4])))[1] > > > > ______________________________________________> R-help@> mailing list > 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.-- View this message in context: http://r.789695.n4.nabble.com/Question-on-survival-tp4645926p4645986.html Sent from the R help mailing list archive at Nabble.com.
It is easy to get a cumulative hazard curve.
First, decide what values of "age", "a", and "b"
you want curves for
tdata<- data.frame(age=55, a=2, b=6)
Get the curves, there will be one for each strata in the output
sfit<- survfit(coxPhMod, newdata= tdata)
Plot them
plot(sfit, fun='cumhaz', col=1:4, xlab= etc etc)
Hazard functions are something else again, estimating these rigorously is
akin to density estimation. A quick and dirty method is to use smooth.spline.
temp<- sfit[1] #grab the first curve
tfit<- smooth.spline(temp$time, -log(temp$surv), df= 5) #smooth the cum
haz
plot(predict(tfit, deriv=1))
That value of "df=5" is made up -- you need to decide for yourself how
much smoothing to do.
I make no claims that this is statistically well grounded, it's just a good
way to get
a quick idea.
PS; There is no such thing as "THE" baseline hazard function;
predictions are always for some particular value of the covariates. In a book
it is sometimes useful to pick a particular set of x values as a default in
order to simplify notation, often x=0, and label that as a baseline. But in
actual computation all zeros is usually crazy (age=0, weight=0, blood
pressure=0, etc).
Terry Therneau
Hi,
I'm going crazy trying to plot a quite simple graph.
i need to plot estimated hazard rate from a cox model.
supposing the model i like this:
coxPhMod=coxph(Surv(TIME, EV) ~ AGE+A+B+strata(C) data=data)
with 4 level for C.
how can i obtain a graph with 4 estimated (better smoothed) hazard curve
(base-line hazard + 3 proportional) to highlight the effect of C.
thanks!!
laudan