stan-dev / stan-dev/rstan

Cannot create summary object with null values in generated quantities

Open
#671 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
1.1k
Forks
266
Avg merge
2h 56m
Merged PRs (30d)
1

Description

Summary:

If there are null values in an object from the generated quantities, stan cannot create a summary.

Description:

When attempted, you see an error like this

Error in quantile.default(chain, probs = probs) :
  missing values and NaN's not allowed if 'na.rm' is FALSE
Reproducible Steps:

R script

library(rstan)
outcome <- c(1,1,1,1,1,1,1,1,0,1,1,1,1,0,0,1,0,1,1,1,0,1,0,1,0,1,0,0,1,1,1,1,1,1,1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,1,0,1,0,0,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,1,1,1)
treat <- c(rep(0,50),rep(1,50))
fake_chai_data <- data.frame(outcome, treat)

chai_dat <- list(N = length(fake_chai_data$outcome), 
                    y = fake_chai_data$outcome,
                    treat = fake_chai_data$treat) 

mod <- stan_model("model.stan")
fit <- sampling(mod, data = chai_dat, iter = 10, chains = 2)
summary(fit)$summary

Stan model:

data {
    int<lower=0> N;  
    int<lower=0,upper=1> y[N]; 
    vector[N] treat;  
}
parameters {
    real alpha;
    real beta;
}
model {
    alpha ~ normal(0,10);  
    beta ~ normal(0,10); 
    y ~ bernoulli_logit(alpha + beta*treat);
}
generated quantities {
    real effect;
    vector[N] y_with_nulls = treat;
    effect = inv_logit(alpha+beta)-inv_logit(alpha);
    y_with_nulls = treat /0;
}
Current Output:
Error in quantile.default(chain, probs = probs) :
  missing values and NaN's not allowed if 'na.rm' is FALSE
RStan Version:
R> packageVersion("rstan")
[1] ‘2.18.2’
R Version:
R> R.version.string
[1] "R version 3.5.2 (2018-12-20)"
Operating System:

OS X 10.12.6

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 with the summary(fit)$summary entry point, using the reproducible R script and model.stan as the first test case. Trace how generated-quantity values reach quantile.default; done means summary(fit)$summary completes for the shown model with missing generated-quantity values while existing summaries remain valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.