survplot invert number at risk labels

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

survplot invert number at risk labels

Marco Barbàra-2
deaR user,

I found an unexpected behaviour of the rms::survplot.survfit function, that
is giving me inverted labels for the patient-at-risk rows. The problem is
that, for some reason, the survival::summary.survfit function changes the
order of two of the suvfit object's strata when called (on my dataset) with
the times= option (is this another unexpected behaviour?).  survplot takes
the labels from the fit passed as argument and the numbers at risk from a
summary(fit, time=stime) object, thus inverting the two labels.

I suppose the problem is caused by some feature of my dataset but I didn't
manage to reproduce the problem on simulated data (although I didn't try
hard) I'm thinking of debugging also summary.survfit to understand why this
is happening. Before doing doing that, however, I'd like to know if some of
you have some hints that could help me either to solve the problem or to
understand it.

Thank you
Marco.

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: survplot invert number at risk labels

Frank Harrell
Please try hard to create a simple reproducible example, then I'll work
on it.



        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Frank Harrell
Department of Biostatistics, Vanderbilt University
Reply | Threaded
Open this post in threaded view
|

Re: survplot invert number at risk labels

Marco Barbàra-2
Hi all,

and thank you for your interested answers. The problem could be
already solved. It is present on my old R 2.15.1
(x86_64-pc-linux-gnu), but after reproducing the error I got the
expected result on a R 3.0.2 through a web interface. However, since I
spent a considerable amount of time to understand what was happening,
I nevertheless decided to submit to your attention what i found.

The following code reproduces the problem on my system (and probably
on every Debian 7 "Wheezy" system with no cran repositories added)

library(survival)
library(rms)
Hazards <- rep(c(1/3, 1/10), each=50)
FupTimes <- rexp(100, rate=Hazards)
CensTimes <- rexp(100, rate=Hazards) # just for fun, we don't need
censoring here
Status <- ifelse(FupTimes <= CensTimes, 1, 0)
FupTimes <- ifelse(Status==1, FupTimes, CensTimes)
SurvObj <- Surv(FupTimes, Status)

# let's manually order the levels:
Covariate <- factor(rep(c("A","B"), each=50), labels=c("B", "A"))
SurvfitObj <- survfit(SurvObj ~ Covariate)
survplot(SurvfitObj, conf="none", n.risk=TRUE, levels.only=TRUE, time.inc=1)

(Resulting plot has nrisk labels inverted)

The error was much simpler than I initially thought, and it is
actually unrelated to survfit. I think that
survplot relies (on my R) on the factor's levels being alphabetically
ordered with the underlying numerical code appropriately arranged
(which I believe is the default behavior of factor() ). There is no
problem if the covariate is a character vector, since in that case the
survfit$strata names have the expected order.

Incidentally, debugging this little problem, I also found that if the
internal nrisk vector has length 1 the survplot function gives error
(line 244 in my version), and this is why I put time.inc=1 in the
previous call (This other issue is still present in 3.0.2)

I'm going to upgrade my R and check that this little error is actually gone.

Thank you
Marco

2014-07-03 0:17 GMT+02:00 Frank Harrell <[hidden email]>:

> Please try hard to create a simple reproducible example, then I'll work
> on it.
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.