mclements / rstpm2

An R package for generalised survival models
28 stars 11 forks source link

Error in predict(type = "hdiff") when using option full = TRUE #19

Closed entjos closed 3 years ago

entjos commented 3 years ago

Problem

Dear Marc,

while trying to create a data frame with predicted hazard differences, I, unfortunately, run into an error. When I used the full = TRUE option for the predict(type = "hdiff") call, R returned the following error:

Error in dim(rvec) <- dim(x) : 
  dims [product 897] do not match the length of object [3]

It looked like predict returned a data frame within a data frame when I looked at the structure of the returned object. I printed the structure below.

'data.frame':   299 obs. of  3 variables:
 $ hormon : num  1 1 1 1 1 1 1 1 1 1 ...
 $ rectime: num  80 87.9 95.9 103.9 111.9 ...
 $ out    :Classes ‘AsIs’ and 'data.frame': 299 obs. of  3 variables:
  ..$ Estimate: num  -3.45e-05 -4.17e-05 -4.92e-05 -5.70e-05 -6.51e-05 ...
  ..$ lower   : num  -0.000101 -0.000119 -0.000136 -0.000153 -0.00017 ...
  ..$ upper   : num  3.22e-05 3.52e-05 3.76e-05 3.91e-05 3.99e-05 ...

Unfortunately, I couldn't find a solution to this problem. Do you maybe know how to best deal with this issue?

Reproducible example

# Loading rstpm2 package
library(rstpm2)

# Fit stmp2 model using breastcancer data set
fpm_model <- stpm2(Surv(rectime, censrec) ~ hormon,
                   data = brcancer,
                   df = 3,
                   tvc = list("hormon" = 3))

# Predict hazard difference comparing hormon users and non-users
# using full=TRUE option for obtaining a full data set for ggplot()
predict(
  fpm_model,
  type = "hdiff",
  newdata = data.frame(hormon = 0),
  var = "hormon",
  grid = TRUE,
  se.fit = TRUE,
  full = TRUE)

Session info

> sessionInfo()
R version 4.0.0 RC (2020-04-22 r78282)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.1252    

attached base packages:
[1] splines   stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rstpm2_1.5.1    survival_3.1-12

loaded via a namespace (and not attached):
 [1] bdsmatrix_1.3-4     Rcpp_1.0.4.6        lattice_0.20-41     mvtnorm_1.1-0      
 [5] packrat_0.5.0       MASS_7.3-51.5       grid_4.0.0          nlme_3.1-147       
 [9] stats4_4.0.0        Matrix_1.2-18       bbmle_1.0.23.1      deSolve_1.28       
[13] tools_4.0.0         numDeriv_2016.8-1.1 compiler_4.0.0      mgcv_1.8-31   

Thank you for your time!

Kindly, Joshua

mclements commented 3 years ago

Joshua,

Apologies for the late reply. This bug should now be fixed.

Sincerely, Mark.

entjos commented 3 years ago

Dear Marc,

thank you so much for fixing the bug! I just installed the latest development version and everything works fine now.

Kindly, Joshua