0

I am looking to compare two survival curves using the restricted mean survival time in R. As such, I am using the survRM2 package and following this R vignette.

I am able to obtain the unadjusted analysis, as in section 3.1, by executing:

dataset_analise <- as.data.frame(dataset_analise_coxph)
time   <- dataset_analise$time
status <- dataset_analise$status
All_episodes_RC_var <- dataset_analise$All_episodes_RC
All_episodes_RC_analysis <- rmst2(time, status, All_episodes_RC_var)

and obtaining:

The truncation time, tau, was not specified. Thus, the default tau (the minimum of the largest observed time on each of the two groups) 9.342  is used. 

Restricted Mean Survival Time (RMST) by arm 
              Est.    se lower .95 upper .95
RMST (arm=1) 3.998 0.051     3.898     4.099
RMST (arm=0) 1.084 0.013     1.059     1.109


Restricted Mean Time Lost (RMTL) by arm 
              Est.    se lower .95 upper .95
RMTL (arm=1) 5.343 0.051     5.243     5.444
RMTL (arm=0) 8.257 0.013     8.232     8.282


Between-group contrast 
                      Est. lower .95 upper .95 p
RMST (arm=1)-(arm=0) 2.914     2.810     3.017 0
RMST (arm=1)/(arm=0) 3.687     3.564     3.815 0
RMTL (arm=1)/(arm=0) 0.647     0.635     0.660 0

After the succesful execution for the unadjusted analysis, I wanted to obtain the results for an adjusted analysis, as in section 3.2. To achieve such, I set the covariates with the following code:

> x <- dataset_analise[,c(4,6,7)]
> head(x)
  Age_at_diagnosis Length_of_stay Number_infections
1               59             83                 2
2               34             12                 0
3               65             18                 0
4               86             17                 0
5               78              6                 0
6               77              0                 0

However, when I try to obtain the adjusted analysis, I get the following error:

> All_episodes_RC_analysis_ajustado <- rmst2(time, status, All_episodes_RC_var, tau=8,  covariates=x)
Error in `[[<-.data.frame`(`*tmp*`, i, value = c(112L, 112L, 112L, 112L,  : 
  replacement has 465330 rows, data has 93066

Checking the nrow and length of variables seems to be fine (all with the same length):

> nrow(x)
[1] 93066
> length(time)
[1] 93066
> length(status)
[1] 93066
> length(All_episodes_RC_var)
[1] 93066

thus I don't have any clue where the 465330 rows mentioned in the error before come from. Any idea why this error is popping up? Thank you.

Mateus
  • 47
  • 2
  • 8
  • I am trying to debug and have just found that the error is occuring in the rmst2reg function, on the line " fitt=lm(c(y10,y00)~rbind(x1, x0)-1, weights=weights ". Anyone have any idea why this error is happening? Rmstreg2 function can be seen in https://github.com/cran/survRM2/blob/master/R/rmst2-ver002.R – Mateus Apr 29 '20 at 23:02
  • Apparently I have just found the solution: my All_episodes_RC_var variable was a factor, while it should be coded as double. Calling the function as rmst2(time, status, as.double(as.character(All_episodes_RC_var)), tau=8, covariates=x) solved the issue. – Mateus Apr 29 '20 at 23:51

0 Answers0