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

2008-04-18 Thread Kåre Edvardsen
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.

All the best,
Kare

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


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

2008-04-18 Thread Paul Johnson
On Fri, Apr 18, 2008 at 3:06 AM, Kåre Edvardsen <[EMAIL PROTECTED]> 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.

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/118481.html

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.

HTH
pj

-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

__
R-help@r-project.org 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.


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

2008-04-18 Thread Frank E Harrell Jr
Paul Johnson wrote:
> On Fri, Apr 18, 2008 at 3:06 AM, Kåre Edvardsen <[EMAIL PROTECTED]> 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.
> 
> http://finzi.psych.upenn.edu/R/Rhelp02a/archive/118481.html
> 
> 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.
> 
> HTH
> pj
> 

In the meantime you can do

library(Design)
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

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

__
R-help@r-project.org 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.


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

2008-04-21 Thread Kåre Edvardsen
Prof. Paul,  Prof. Frank.

Thank you very much for helping me out. The Design package did the
trick.

Here is how the anova table looks like without using the Design package:

> anova(Fit1)
Analysis of Deviance Table
Cox model: response is Surv(Time, cancer)
Terms added sequentially (first to last)

Df Deviance Resid. Df Resid. Dev
NULL  16783 5341.8
relativ10.0 1678214995.0
hormone3939.4 1677914055.6
.
.
.


As you see, no p-values reported

Here is how it looks with after implementing Design:

> anova(Fit1)
 Wald Statistics  Response: Surv(Time, cancer) 
 Factor Chi-Square d.f. P
 relativ 6.08   1   0.0137
 hormone 8.68   3   0.0339
.
.
.


Regards,
Kare


On Fri, 2008-04-18 at 11:03 -0500, Frank E Harrell Jr wrote:

> Paul Johnson wrote:
> > On Fri, Apr 18, 2008 at 3:06 AM, Kåre Edvardsen <[EMAIL PROTECTED]> 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.
> > 
> > http://finzi.psych.upenn.edu/R/Rhelp02a/archive/118481.html
> > 
> > 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.
> > 
> > HTH
> > pj
> > 
> 
> In the meantime you can do
> 
> library(Design)
> 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
> 

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


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

2008-04-23 Thread David Winsemius
Kåre Edvardsen <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]: 

> Prof. Paul,  Prof. Frank.
> 
> Thank you very much for helping me out. The Design package did the
> trick.
> 
> Here is how the anova table looks like without using the Design
> package: 
> 
>> anova(Fit1)
> Analysis of Deviance Table
> Cox model: response is Surv(Time, cancer)
> Terms added sequentially (first to last)
> 
> Df Deviance Resid. Df Resid. Dev
> NULL   16783 5341.8
> relativ  1  0.01678214995.0
> hormone  3939.41677914055.6

> 
> As you see, no p-values reported
> 
> Here is how it looks with after implementing Design:
> 
>> anova(Fit1)
>  Wald Statistics   Response: Surv(Time, cancer) 
>  Factor Chi-Square d.f.P
>  relativ 6.08   1   0.0137
>  hormone 8.68   3   0.0339

(spacing added to hopefully look correct in monospaced font)

I was a puzzled looking at those two outputs. In the first the change 
in deviance with addition of "hormone" was 939.4 with 3 df. In the 
second the Wald chi-square, which I presume should be similar to the 
difference in deviance, is only 8.68. Were these outputs from 
completely different models or data? Or are there pitfalls in applying 
Design functions to Surv objects created with other packages?

-- 
David Winsemius



> Regards,
> Kare
> 
> 
> On Fri, 2008-04-18 at 11:03 -0500, Frank E Harrell Jr wrote:
> 
>> Paul Johnson wrote:
>> > On Fri, Apr 18, 2008 at 3:06 AM, Kåre Edvardsen <[EMAIL PROTECTED]>
>> > 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 li 
> st.
>> >>
>> > 
>> > 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, an 
> d
>> > 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 foun 
> d
>> > by typing "RSiteSearch("anova.coxph")" ) discussing recent
>> > troubles with anova.coxph.
>> > 
>> > http://finzi.psych.upenn.edu/R/Rhelp02a/archive/118481.html
>> > 
>> > 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
>> > som 
> e
>> > 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.
>> > 
>> > HTH
>> > pj
>> > 
>> 
>> In the meantime you can do
>> 
>> library(Design)
>> 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
>> 
> 
>  [[alternative HTML version deleted]]
> 
> 
> --===0807199787==
> __
> R-help@r-project.org 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. 
> 
> Attachment decoded: untitled-3.txt
> --===0807199787==--

__
R-help@r-project.org 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 co