mclements/rstpm2

Error in predict with new data

Closed this issue · 2 comments

Dear Mark,

I was following the 'rstpm2: a simple guide' and ran into the following problem (which seems to have worked in your vignette):

> rm(list = ls())
> 
> library(ggplot2)
> library(survival)
> library(rstpm2)
> 
> brcancer <- transform(brcancer, recyear= rectime/365.24)
> 
> fit <- stpm2(Surv(recyear, censrec == 1) ~ hormon, data = brcancer, df = 4)
> 
> pred <- predict(fit, newdata = data.frame(hormon = 0:1),
+                 type = 'hazard', gird = TRUE, full = TRUE, se.fit = TRUE)
Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : 
  variable lengths differ (found for 'nsx(log(recyear), df = 4)')
In addition: Warning message:
'newdata' had 2 rows but variables found have 686 rows 
> 

R session on Ubuntu 19.04:

> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 19.04

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.8.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.8.0

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] rstpm2_1.5.1    survival_2.43-3 ggplot2_3.1.1  

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1          magrittr_1.5        tidyselect_0.2.5   
 [4] munsell_0.5.0       colorspace_1.4-1    lattice_0.20-38    
 [7] R6_2.4.0            rlang_0.4.0         plyr_1.8.4         
[10] dplyr_0.8.1         tools_3.5.2         grid_3.5.2         
[13] gtable_0.3.0        nlme_3.1-137        mgcv_1.8-27        
[16] withr_2.1.2         lazyeval_0.2.2      assertthat_0.2.1   
[19] tibble_2.1.2        numDeriv_2016.8-1.1 crayon_1.3.4       
[22] Matrix_1.2-15       purrr_0.3.2         glue_1.3.1         
[25] deSolve_1.25        bbmle_1.0.20        compiler_3.5.2     
[28] pillar_1.4.1        scales_1.0.0        stats4_3.5.2       
[31] pkgconfig_2.0.2    
> 


Thanks, sorry troubling for such a trivial matter! It was late in the night.