Re: [R] Overall p-value from a factor in a coxph fit

From: Frank E Harrell Jr <>
Date: Fri, 18 Apr 2008 11:03:36 -0500

Paul Johnson wrote:
> On Fri, Apr 18, 2008 at 3:06 AM, Kåre Edvardsen <> wrote:

>> Hi all.
>>  If I run the simple regression when x is a categorical variable ( x <-
>>  factor(x) ):
>>  > MyFit <-coxph( Surv(start, stop, event) ~ x )
>>  How can I get the overall p-value on x other than for each dummy
>>  variable?
>>  > anova(MyFit)
>>  does NOT provide that information as previously suggested on the list.

> It "should" work... Here's a self contained example showing that
> anova does give the desired significance test for an lm model.
>> y <- rnorm(100)
>> x <- gl(5,20)
>> mod <- lm(y~x)
>> anova(mod)

> Analysis of Variance Table
> Response: y
> Df Sum Sq Mean Sq F value Pr(>F)
> x 4 6.575 1.644 1.5125 0.2047
> Residuals 95 103.237 1.087
> If you provide a similar self contained example leading up to a coxph,
> I would be glad to investigate your question. You don't give enough
> information for me to tell which version of coxph you are running, and

> from what package.

> Suppose I "guess" that you are using the coxph from the package
> "survival". If so, it appears to me there is a bug in that package at
> the moment. The methods anova.coxph and drop1.coxph did exist at one
> time, until very recently. There is a thread in r-help (which I found
> by typing "RSiteSearch("anova.coxph")" ) discussing recent troubles

> with anova.coxph.
> As you see from the discussion in that thread, there used to be an
> anova method for coxph, and in the version of survival I have now,
> there is no such method. The version I have is 2.34-1, Date:
> 2008-03-31.
> Here's what I see after I run "example(coxph)" in order to create some
> coxph objects, on which I can test the diagnostics:
>> drop1(test2)

> Error in terms.default(terms1) : no terms component
>> anova(test2)

> Error in UseMethod("anova") : no applicable method for "anova"
> In that survival package, I do find anova.survreg, but not
> anova.coxph. If you are using the survival package, I'd suggest you
> contact Thomas Lumley directly, since he maintains it.
> I think if you had reported the exact error you saw, it would have
> been easier for me to diagnose the trouble.
> pj

In the meantime you can do

f <- cph( . . . )
anova(f) # multiple d.f. Wald statistics including tests of nonlinearity

cph uses coxph but anova.Design is separate from the survival package.


Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 18 Apr 2008 - 17:26:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 21 Apr 2008 - 09:30:29 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive