How to get verdiff returned p value

I am using the R Survival Pack, the muddiff function. I wonder how to get the p value from the return value.

> diff = survdiff(Surv(Time, Censored) ~ Treatment+Gender, data = dat)
> diff
Call:
survdiff(formula = Surv(Time, Censored) ~ Treatment + Gender, 
    data = dat)

                            N Observed Expected (O-E)^2/E (O-E)^2/V
Treatment=Control, Gender=M 2        1     1.65  0.255876  0.360905
Treatment=Control, Gender=F 7        3     2.72  0.027970  0.046119
Treatment=IND, Gender=M     5        2     2.03  0.000365  0.000519
Treatment=IND, Gender=F     6        2     1.60  0.100494  0.139041

 Chisq= 0.5  on 3 degrees of freedom, p= 0.924 

I want to get pp value 0.924 using some function. Thank.

+4
source share
2 answers

The p value is not stored in the survdiff class, so it must be calculated on the fly during output. To reproduce the p value, you can use the chisq distribution function: "pchisq"

diff = survdiff(Surv(Time, Censored) ~ Treatment+Gender, data = dat)
pchisq(diff$chisq, length(diff$n)-1, lower.tail = FALSE)
+2
source

The code in the function print.survdiffthat displays these values ​​is:

cat("\n Chisq=", format(round(x$chisq, 1)), " on", df, 
            "degrees of freedom, p=", format(signif(1 - pchisq(x$chisq, 
                df), digits)), "\n")

Code leading to it:

if (is.matrix(x$obs)) {
            otmp <- apply(x$obs, 1, sum)
            etmp <- apply(x$exp, 1, sum)
        }         else {
            otmp <- x$obs
            etmp <- x$exp
        }
        df <- (sum(1 * (etmp > 0))) - 1

And the “digits” are set in argument list 3, therefore, using the example on the help page surv.diff:

x <- survdiff(Surv(time, status) ~ pat.karno + strata(inst), data=lung) 
cat( "p=", format(signif(1 - pchisq(x$chisq, 
                 df), digits)) )
#p= 0.00326 

: :

 df <- with(x,    (sum(1 * (apply(x$exp, 1, sum) > 0))) - 1 )
> df
[1] 7
+4

All Articles