stan-dev / stan-dev/rstanarm

`stan_mvmer` fails when two random intercepts are specified

Open
#438 0 comments 0 reactions 1 assignee View on GitHub

@sambrilleman is already working on this.

Since Jun 1, 2020.

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

Description

Summary:

stan_mvmer fails when two grouping factors are specified both with just a random intercept.

Reproducible Steps:

The following model fails:


dat$herd2[dat$herd %in% 1:5] = 1
dat$herd2[dat$herd %in% 6:10] = 2
dat$herd2[dat$herd %in% 11:15] = 3

mod <- 
  stan_mvmer(incidence ~ size + period + (1|herd) + (1|herd2),
             data = dat, 
             chains = 1,
             seed = 12345,
             refresh = 0,
             prior_covariance = lkj())

with an error about dimensions in the priors

Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) : 
  Exception: mismatch in number dimensions declared and found in context; processing stage=data initialization; variable name=b2_prior_regularization; dims declared=(); dims found=(0)  (in '/data/hyperparameters_mvmer.stan' at line 42; included from 'model_mvmer' at line 29)

So does a model with the decov() prior (interestingly, with a different error, but still about prior dimensions):

mod <- 
  stan_mvmer(incidence ~ size + period + (1|herd) + (1|herd2),
             data = dat, 
             chains = 1,
             seed = 12345,
             refresh = 0,
             prior_covariance = decov())

with error

Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) : 
  Exception: mismatch in dimension declared and found in context; processing stage=data initialization; variable name=b_prior_shape; position=0; dims declared=(2); dims found=(1)  (in '/data/hyperparameters_mvmer.stan' at line 31; included from 'model_mvmer' at line 29)

The automated tests use additional random effects (two random intercepts + one random slope) which seems to work ok, hence why the tests didn't fail. It is only when it is two random intercepts and no additional random effects that it fails. For example, the following seems to work:

mod <- 
  stan_mvmer(incidence ~ size + period + (1|herd) + (period|herd2),
             data = dat, 
             chains = 1,
             seed = 12345,
             refresh = 0)
RStanARM Version:

2.19.3

R Version:

3.6.2

Operating System:

Windows 10

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.