stan-dev / stan-dev/rstanarm

`rstanarm::loo` and `rstanarm::posterior_predict` return errors

Open
#309 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
401
Forks
136
PR merge metrics
No merged PRs in 30d

Description

Summary:

Problems with rstanarm:::loo.stanreg / rstanarm::loo from stan_betareg model fit

Description / reproducibility
> fit1 <- fit1 <- rstanarm::stan_betareg(
  formula= <formula>, 
  data= train, link = "logit", link.phi = "log", 
  prior= normal(), prior_intercept= normal(), prior_phi= exponential(),
  iter= iter, warmup= warmup, chains= chains, cores= chains)

> class(fit1)
[1] "stanreg" "betareg"
> loo(fit1, cores= 20)
Error in names(object[[n]])[1L:2L] <- c("mu", "phi") : 
  attempt to set an attribute on NULL
> rstanarm::loo(fit1, cores= 20)
Error in names(object[[n]]) <- `*vtmp*` : 
  attempt to set an attribute on NULL
> rstanarm:::loo.stanreg(fit1, cores= 20)
Error in names(object[[n]]) <- `*vtmp*` : 
  attempt to set an attribute on NULL
> loo(fit1)
Error in names(object[[n]]) <- `*vtmp*` : 
  attempt to set an attribute on NULL
> tt <- rstanarm::posterior_predict(fit1, draws= 1000, re.form= NULL, allow.new.levels= TRUE)
Error in names(object[[n]]) <- `*vtmp*` : 
  attempt to set an attribute on NULL
using example data:

see: https://cran.r-project.org/web/packages/rstanarm/vignettes/betareg.html

SEED <- 1234
set.seed(SEED)
eta <- c(1, -0.2)
gamma <- c(1.8, 0.4)
N <- 200
x <- rnorm(N, 2, 2)
z <- rnorm(N, 0, 2)
mu <- binomial(link = logit)$linkinv(eta[1] + eta[2]*x)
phi <- binomial(link = log)$linkinv(gamma[1] + gamma[2]*z)
y <- rbeta(N, mu * phi, (1 - mu) * phi)
dat <- data.frame(cbind(y, x, z))

fit1 <- stan_betareg(y ~ x | z, data = dat, link = "logit", link.phi = "log",
                     chains = 1L, cores = 1L, seed = 1L, iter = 100L)
loo(fit1)
Error in names(object[[n]]) <- `*vtmp*` : 
  attempt to set an attribute on NULL
tt <- rstanarm::posterior_predict(fit1, draws= 1000, re.form= NULL, allow.new.levels= TRUE)
Error in names(object[[n]]) <- `*vtmp*` : 
  attempt to set an attribute on NULL
session info
> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /usr/local/lib/libtatlas.so

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

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

other attached packages:
[1] loo_1.1.0         rstanarm_2.17.2   Rcpp_0.12.13      betareg_3.2-0     fbmodels_0.1.3    ggplot2_2.2.1    
[7] data.table_1.11.0

loaded via a namespace (and not attached):
 [1] lattice_0.20-35    zoo_1.8-3          gtools_3.5.0       lmtest_0.9-36      assertthat_0.2.0   digest_0.6.12     
 [7] mime_0.5           R6_2.2.2           plyr_1.8.4         stats4_3.4.1       colourpicker_1.0   rlang_0.1.2       
[13] lazyeval_0.2.1     minqa_1.2.4        miniUI_0.1.1       nloptr_1.0.4       Matrix_1.2-10      DT_0.2            
[19] shinythemes_1.1.1  splines_3.4.1      shinyjs_1.0        lme4_1.1-14        stringr_1.2.0      htmlwidgets_0.9   
[25] igraph_1.1.2       munsell_0.4.3      shiny_1.0.5        compiler_3.4.1     httpuv_1.3.5       rstan_2.17.3      
[31] pkgconfig_2.0.1    base64enc_0.1-3    rstantools_1.4.0   htmltools_0.3.6    nnet_7.3-12        tibble_1.3.4      
[37] gridExtra_2.3      codetools_0.2-15   threejs_0.3.1      matrixStats_0.52.2 dplyr_0.7.4        MASS_7.3-47       
[43] grid_3.4.1         nlme_3.1-131       xtable_1.8-2       gtable_0.2.0       magrittr_1.5       StanHeaders_2.17.2
[49] scales_0.5.0       stringi_1.1.6      reshape2_1.4.2     flexmix_2.3-14     bindrcpp_0.2       dygraphs_1.1.1.4  
[55] xts_0.10-0         sandwich_2.4-0     Formula_1.2-3      tools_3.4.1        glue_1.2.0         shinystan_2.4.0   
[61] markdown_0.8       crosstalk_1.0.0    rsconnect_0.8.5    parallel_3.4.1     survival_2.41-3    yaml_2.1.19       
[67] inline_0.3.14      colorspace_1.3-2   bayesplot_1.4.0    bindr_0.1          modeltools_0.2-22 

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the linked beta-regression example and inspect the rstanarm:::loo.stanreg, loo, and posterior_predict entry points for stan_betareg objects. Trace the NULL value behind the reported naming error and verify that both loo(fit1) and posterior_predict(fit1, ...) complete successfully without the error.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.