5

This question follows on from the question here in that we want to plot a multi-variate model.

Lets say we want to plot the Survival function from the example in survreg from the package release notes

Where the model is

survreg(Surv(time, status) ~ ph.ecog + age + strata(sex), lung)

From what I understand the following problem seems to address the problem, but does not provide a data set and only uses one variable. Where in this example, we have two continuous variables and one factor

Community
  • 1
  • 1
user08041991
  • 617
  • 8
  • 20

1 Answers1

4

Plot for the predicted survival curve for hypothetical individual with mean of lung$age and the mode of lung$ph.ecog (following the example in the help page):

?predict.survreg
pct <- 1:98/100
ptime <- predict(res, newdata=data.frame(ph.ecog=1, age=62.44737, sex=1),  type='quantile',
                  p=pct, se=TRUE)
 matplot(cbind(ptime$fit, ptime$fit + 2*ptime$se.fit,
                          ptime$fit - 2*ptime$se.fit)/30.5, 1-pct,
         xlab="Months", ylab="Survival", type='l', lty=c(1,2,2), col=1)

enter image description here

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • and then if we were to want to create a second curve on the same plot. Lets say someone with of the opposing sex. Would we just use the `lines`function or the same `predict` with `add=TRUE`? – user08041991 Sep 29 '15 at 07:43
  • I would re-run `predict.survreg` with new values and then use `matlines`, perhaps with a different `col`-argument. – IRTFM Sep 29 '15 at 16:46
  • @42 is there a way to adjust this result to allow x and y to have different number of rows? Apparently matplot only works if x and y are vectors of the same length. – jvalenti Mar 24 '16 at 17:38
  • I would need a more complete problem description since in the current use case what I would see as the "Y values" are generated from "X-values", but I'm speculating that you are looking for `expand.grid` to be applied to your X values before generating Y's. If its title has the string "surv" in it or a tag of `[survival-analysis]`, I'll see it. – IRTFM Mar 24 '16 at 17:42