stan-dev / stan-dev/rstanarm

offsets do not work correctly in stan_gamm4

Open
#253 2 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:

The offsets don't work right in stan_gamm4. The example here is for a gaussian family, but it is particularly harmful in poisson regression.

Description:

Specifying an offset inside the formula or as argument to the function does not work if the offset referred to is a column inside the data frame. This is also problematic when predicting.

Reproducible Steps:
## example from gamm
library(rstanarm)

dat <- mgcv::gamSim(1, n = 400, scale = 2) ## simulate 4 term additive truth
#> Gu & Wahba 4 term additive model
## Now add 20 level random effect `fac'...
dat$fac <- fac <- as.factor(sample(1:20, 400, replace = TRUE))
dat$y <- dat$y + model.matrix(~ fac - 1) %*% rnorm(20) * .5

br <- stan_gamm4(y ~ s(x0) + x1 + s(x2) + offset(f2), data = dat, random = ~ (1 | fac),
                 chains = 1, iter = 200) # for example speed
RStanARM Version:

2.17.2

R Version:

3.4.3

> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.3

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] de_CH.UTF-8/de_CH.UTF-8/de_CH.UTF-8/C/de_CH.UTF-8/de_CH.UTF-8

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

other attached packages:
[1] rstanarm_2.17.2 Rcpp_0.12.14   

loaded via a namespace (and not attached):
 [1] lattice_0.20-35    zoo_1.8-0          gtools_3.5.0       assertthat_0.2.0  
 [5] digest_0.6.12      mime_0.5           R6_2.2.2           plyr_1.8.4        
 [9] stats4_3.4.3       ggplot2_2.2.1      colourpicker_0.3   rlang_0.1.2       
[13] lazyeval_0.2.0     minqa_1.2.4        miniUI_0.1.1       nloptr_1.0.4      
[17] Matrix_1.2-12      DT_0.2             shinythemes_1.1.1  splines_3.4.3     
[21] shinyjs_0.9.1      lme4_1.1-13        stringr_1.2.0      htmlwidgets_0.9   
[25] loo_1.1.0          igraph_1.1.2       munsell_0.4.3      shiny_1.0.5       
[29] compiler_3.4.3     httpuv_1.3.5       rstan_2.17.3       pkgconfig_2.0.1   
[33] base64enc_0.1-3    mgcv_1.8-22        rstantools_1.3.0   htmltools_0.3.6   
[37] tibble_1.3.4       gridExtra_2.3      codetools_0.2-15   threejs_0.3.1     
[41] matrixStats_0.52.2 dplyr_0.7.3        MASS_7.3-47        grid_3.4.3        
[45] nlme_3.1-131       xtable_1.8-2       gtable_0.2.0       magrittr_1.5      
[49] StanHeaders_2.17.2 scales_0.5.0       stringi_1.1.5      reshape2_1.4.2    
[53] bindrcpp_0.2       dygraphs_1.1.1.4   xts_0.10-0         tools_3.4.3       
[57] glue_1.1.1         shinystan_2.4.0    markdown_0.8       crosstalk_1.0.0   
[61] rsconnect_0.8.5    parallel_3.4.3     survival_2.41-3    inline_0.3.14     
[65] colorspace_1.3-2   bayesplot_1.4.0    bindr_0.1         
Operating System:

Your operating system (e.g., OS X 10.11.3)

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

Start at the stan_gamm4 entry point and run the reproducible example from the issue. Compare offsets supplied inside the formula or as a function argument when the offset is a data-frame column, including prediction behavior. Done means column-based offsets work correctly for fitting and prediction, particularly for poisson regression.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.