[R] Error in using coxph()
Göran Broström
gb at stat.umu.se
Sun May 16 16:05:57 CEST 2004
On Sun, May 16, 2004 at 02:25:07PM +0200, Peter Dalgaard wrote:
> Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
>
> > Note you said you used 1-F but the output said you used F. You also say
> > `1-F is a vector of '0's' so I think you may have declared that all
> > observations are right-censored. (NB if you give Surv an event vector of
> > all 1's it is ambiguous, so don't do this.)
>
> Actually, it *is* documented that this is interpreted as "all-died"
> and the advice in ?Surv is just to avoid 1/2 coding if all data are
> censored. It's a bit puzzling that we don't allow explicit
> disambiguation (e.g., by passing the event as a two-level factor),
> though.
But note the following:
> library(survival)
> enter <- c(0,0,0)
> exit <- c(1,2,3)
> event <- c(0,0,0)
> x <- c(1,0,1)
> coxph(Surv(exit, event) ~ x)
Call:
coxph(formula = Surv(exit, event) ~ x)
coef exp(coef) se(coef) z p
x 0 1 0 NaN NaN
Likelihood ratio test=0 on 1 df, p=1 n= 3
Warning message:
Ran out of iterations and did not converge in:
fitter(X, Y, strats, offset, init, control, weights = weights,
But:
> coxph(Surv(enter, exit, event) ~ x)
Error in fitter(X, Y, strats, offset, init, control, weights = weights, :
Can't fit a Cox model with zero failures
This is the kind of message we want (before this check was introduced,
coxph crashed (segfault) if there were no events).
Recommendation 1: Give 'Surv' three arguments! (time, time2, event)
Recommendation 2: 'event' should be a logical, with 'FALSE' = 'censored'.
Meaning that if event is numeric, '0' = 'censored', anything else is an
event. This is advantageous when you have data with several types of
events. For instance, event = 0: censored, event = 1: death of cause 1,
event = 2: death of cause 2. Then you can (i) use event as is for total
mortality, (event == x) for for cause-specific mortality, x = 1, 2.
You can get this behaviour now by using (event != 0) for total mortality,
of course.
Göran
> --
> O__ ---- Peter Dalgaard Blegdamsvej 3
> c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
> (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
--
Göran Broström tel: +46 90 786 5223
Department of Statistics fax: +46 90 786 6614
Umeå University http://www.stat.umu.se/egna/gb/
SE-90187 Umeå, Sweden e-mail: gb at stat.umu.se
More information about the R-help
mailing list