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)) )
: :
df <- with(x, (sum(1 * (apply(x$exp, 1, sum) > 0))) - 1 )
> df
[1] 7