0

I am running a survdiff using the survival package and the p-value is 0.02. I would like to see it have more precision(ie. 0.02xxxx). Is there an argument that I can pass to specify the length of the pvalue. I read the documentation for the survival package and did not find any mention on how to specify it.

survdiff(surv_object~access_sam2$Area_mTLSHL)
Andre
  • 123
  • 1
  • 13

2 Answers2

1

I am not sure about the survival package and you did not provide a reproducible code (please do so next time). But in general, if you want to see more digits what you need to do is

print(value, digits= n)
# n is the number of digits you want to see

In your case it is

 print(survdiff(surv_object~access_sam2$Area_mTLSHL), 6)
  • the problem was that the result of ` survdiff(surv_object~access_sam2$Area_mTLSHL) ` is not a single value its actually a list, where none of the values is a pvalue that can simply be extracted. – Andre Jul 26 '19 at 16:17
  • As I said, I am not familiar with the function you provided and your code was not reproducible, thus I couldn't know that `survdiff(surv_object~access_sam2$Area_mTLSHL)` doesn't give a single (p) value. See [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) –  Jul 26 '19 at 16:28
1

Credits.

The computation of the p-value for objects of class "survdiff" is not completely obvious. I had to see what is going on in the print method for objects of that class to understand the way the degrees of freedom are computed.

The code below is a simplification of the code of print.survdiff and therefore the credits go to

citation("survival")
#
#Therneau T (2015). _A Package for Survival Analysis
#in S_. version 2.38, <URL:
#https://CRAN.R-project.org/package=survival>.
#
#Terry M. Therneau, Patricia M. Grambsch (2000).
#_Modeling Survival Data: Extending the Cox Model_.
#Springer, New York. ISBN 0-387-98784-3.
#
#To see these entries in BibTeX format, use
#'print(<citation>, bibtex=TRUE)', 'toBibtex(.)', or
#set 'options(citation.bibtex.max=999)'.

The code itself can be seen in the sources or by running

getAnywhere("print.survdiff")

Now for the question's problem.

I have written a generic pvalue function to make it easier to call a method for objects of the class returned by function survdiff. The example is the taken from the help page of that function.
The return value is a named list with 3 members, the names are self explanatory. One of them, chisq is a repetition of a value returned by survdiff. I have included it for the sake of completeness.

pvalue <- function(x, ...) UseMethod("pvalue")
pvalue.survdiff <- function (x, ...) 
{
  if (length(x$n) == 1) {
    df <- 1
    pval <- pchisq(x$chisq, 1, lower.tail = FALSE)
  } else {
    if (is.matrix(x$obs)) {
      otmp <- rowSums(x$obs)
      etmp <- rowSums(x$exp)
    } else {
      otmp <- x$obs
      etmp <- x$exp
    }
    df <- sum(etmp > 0) - 1
    pval <- pchisq(x$chisq, df, lower.tail = FALSE)
  }
  list(chisq = x$chisq, p.value = pval, df = df)
}

srv <- survdiff(Surv(futime, fustat) ~ rx, data = ovarian)

pvalue(srv)
#$chisq
#[1] 1.06274
#
#$p.value
#[1] 0.3025911
#
#$df
#[1] 1
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66