Home > Blockchain >  R Survminer Pairwise Survival difference Variable length error
R Survminer Pairwise Survival difference Variable length error

Time:10-02

Hello I am using the survival package and the survminer package to do some analysis. I am having trouble with pairwise_survdiff from the survminer package.

Here is some simulated data that mimics my own.

set.seed(123)
library(survival)
library(survminer)
size <-  30
treatment <- c(rep(1, size),
               rep(2, size),
               rep(3, size))
deathtime <- c(rexp(size, rate = 1),
               rexp(size, rate = 2),
               rexp(size, rate = 3))
censor <- c(rbinom(size, 1, .1),
            rbinom(size, 1, .1),
            rbinom(size, 1, .1))


df <- data.frame(treatment, deathtime, censor)

Doing the survival analysis

surv.obj<- Surv(df$deathtime, abs(df$censor -1))

survdiff(surv.obj ~ treatment, data = df)

enter image description here

Now trying pairwise

pairwise_survdiff(surv.obj ~ treatment, data = df) # from survminer

enter image description here

length(df[,"treatment"]) == length(surv.obj)

enter image description here

I don't understand what the problem is.

CodePudding user response:

Try without using the df$

pairwise_survdiff(Surv(deathtime, abs(censor -1)) ~ treatment, data = df)

-output

Pairwise comparisons using Log-Rank test 

data:  df and treatment 

  1      2     
2 0.1389 -     
3 0.0022 0.0364

P value adjustment method: BH 
  • Related