# [R] Extracting approximate Wald test (Chisq) from coxph(..frailty)

Mohammad Ehsanul Karim wildscop at yahoo.com
Tue Apr 17 23:55:10 CEST 2007

```Dear list,

I need to extract the approximate Wald test (Chisq) so
that I can put it in a loop. str seemed like a great
idea, but I cannot seem to find the approximate Wald
test for frailty (in the example data below: 17.89 and
its p-value 0.12000) there. I cannot seem to find it
in capture.output either as numeric form. Do I need to
modify some given values? If yes, please give me a
clue for the example:

library(survival)
kfitm1<-coxph(formula = Surv(time, status) ~ age +
sex +disease + frailty(id, dist = "gauss"),
data = kidney)
str(kfitm1)
capture.output( print(kfitm1) )

Mohammad Ehsanul Karim (R - 2.3.1 on windows)
wildscop at yahoo dot com
Institute of Statistical Research and Training
University of Dhaka

________________________________
On Tue, 17 Apr 2007, Mohammad Ehsanul Karim wrote:
You _can_ use  	tmp <- capture.output( print( <your
example> ) ) and then further process tmp. A _better_
solution for most purposes is to look at the object
produced by coxph() and figure out how to calculate
the Wald statistic from that
object. See  	?coxph.object and  	?str
Another tactic is to look at how print.coxph() does
its work and use the code in it to produce just the
output you desire. Look at page(
survival:::print.coxph, "print" )

Assign the output of coxph to some object, and use the
\$ extractor function to obtain what you need. ie:
rtfm <- coxph(formula = Surv(time, status) ~ age + sex
+  disease + frailty(id, dist = "gauss"), data =
kidney)
Age <- coef(rtfm)["age"]
OR
Sex <- rtfm\$coef["sex"]

> Dear List,
> How do I extract the approximate Wald test for the
> frailty (in the following example 17.89 value)?
> What about the P-values, other Chisq, DF, se(coef)
and > se2? How can they be extracted?
######################################################>
kfitm1
> Call:
> coxph(formula = Surv(time, status) ~ age + sex +
> disease + frailty(id, dist = "gauss"), data =
kidney)
>
>                           coef     se(coef)
> age                        0.00489 0.0150
> sex                       -1.69703 0.4609
> diseaseGN                  0.17980 0.5447
> diseaseAN                  0.39283 0.5447
> diseasePKD                -1.13630 0.8250
> frailty(id, dist = "gauss
>                           se2    Chisq DF
> age                       0.0106  0.11  1.0
> sex                       0.3617 13.56  1.0
> diseaseGN                 0.3927  0.11  1.0
> diseaseAN                 0.3982  0.52  1.0
> diseasePKD                0.6173  1.90  1.0
> frailty(id, dist = "gauss        17.89 12.1
>                           p
> age                       0.74000
> sex                       0.00023
> diseaseGN                 0.74000
> diseaseAN                 0.47000
> diseasePKD                0.17000
> frailty(id, dist = "gauss 0.12000
>
> Iterations: 6 outer, 30 Newton-Raphson
>      Variance of random effect= 0.493
> Degrees of freedom for terms=  0.5  0.6  1.7 12.1
> Likelihood ratio test=47.5  on 14.9 df, p=2.82e-05
n=
> 76

```