sambrilleman / rstanarm

rstanarm R package for Bayesian applied regression modeling
http://mc-stan.org/interfaces/rstanarm.html
GNU General Public License v3.0
0 stars 1 forks source link

Bug when running posterior_survfit using NULL assoc #69

Closed jburos closed 7 years ago

jburos commented 7 years ago

Summary:

Seeing the following error when running posterior_survfit on a model where assoc = NULL.

Error in e_eta[s, ] <- e_eta[s, ] + linear_predictor.default(abeta_s,  : 
  replacement has length zero

Seems likely this is an edge case not accommodated by the posterior_survfit function.

Description:

Here is the traceback.

7: ll_event(object, data = dat, pars = pars, survprob = TRUE)
6: FUN(X[[i]], ...)
5: lapply(time_seq, function(t) {
       if (!identical(length(t), length(id_list))) 
           stop("Bug found: the vector of prediction times is not the same length ", 
               "as the number of individuals.")
       dat <- jm_data(object, newdataLong = ndL, newdataEvent = ndE, 
           ids = id_list, etimes = t, long_parts = FALSE)
       surv_t <- ll_event(object, data = dat, pars = pars, survprob = TRUE)
       if (is.vector(surv_t) == 1L) 
           surv_t <- t(surv_t)
       surv_t[, (t == 0)] <- 1
       if (standardise) {
           surv_t <- matrix(rowMeans(surv_t), ncol = 1)
           dimnames(surv_t) <- list(iterations = NULL, "standardised_survprob")
       }
       else {
           dimnames(surv_t) <- list(iterations = NULL, ids = id_list)
       }
       surv_t
   })
4: rstanarm::posterior_survfit(mj4null, standardise = TRUE, times = 0, 
       extrapolate = TRUE, control = list(condition = FALSE))

Reproducible Steps:

  1. Fit any stan_jm model with assoc = NULL.
  2. Run either posterior_survfit or ps_check on said model.

e.g.:

> ps_check(mj4null)
Error in e_eta[s, ] <- e_eta[s, ] + linear_predictor.default(abeta_s,  : 
  replacement has length zero

RStanARM Version:

'master' branch of sambrilleman/rstanarm

R Version:

3.3.3

Operating System:

Linux (ubuntu)