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

error running posterior_survfit with 'bs' hazard: non-conformable arguments #51

Closed jburos closed 7 years ago

jburos commented 7 years ago

Summary:

I get an error when running posterior_survfit with any basehaz other than Weibull. This happens whether or not I include newdata.

The message reads:

Error in beta %*% t(x) : non-conformable arguments

It appears to be due to the inclusion of an Intercept term in the x matrix, where there is not an intercept term in the betas. At least not for any hazard except the weibull model.

Description:

I had done a quick hack to address this issue earlier, but forgot to document the bug. Documenting it here so it can be tracked.

The fix, which worked to resolve the issue but is admittedly a hack, is to literally remove the intercept term in pp_data as described here:

if (is.stanjm(object) & object$basehaz$type_name != 'weibull' & m == 'Event') {
    # remove Intercept term, if present
    x <- x[ ,-1*grep(colnames(x), pattern='(Intercept)')]
 }

In the original model fit, the x matrix is prepared by coxph and so does not include the intercept term by default. In this function, however, the x matrix is prepared by evaluating the RHS of the formula using standard tools & so it includes the intercept term as specified in the formula.

Reproducible Steps:

  1. Install develop2 branch of 'sambrilleman/rstanarm':

    # latest commit of `develop2` branch, at the time of identification
    devtools::install_github('sambrilleman/rstanarm', ref = '0176bc3',  args = '--preclean', local = TRUE)
  2. Fit example model with basehaz = 'bs'

    data(pbcSurv)
    data(pbcLong)
    f1 <- stan_jm(formulaLong = logBili ~ year + (1 | id), 
                              dataLong = pbcLong,
                              formulaEvent = Surv(futimeYears, death) ~ sex + trt, 
                              dataEvent = pbcSurv,
                              time_var = "year",
                              basehaz = 'bs')
  3. Run ps_check or posterior_survfit on this fitted object

    survfit <- posterior_survfit(f1)

RStanARM Version:

See above

R Version:

3.3.3

Operating System:

Ubuntu