Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rstan throwing inappropriate error message #1072

Open
northNomad opened this issue Jun 12, 2023 · 0 comments
Open

Rstan throwing inappropriate error message #1072

northNomad opened this issue Jun 12, 2023 · 0 comments

Comments

@northNomad
Copy link

Summary:

Rstan throws the error Error in if (any(efbmi_per_chain < threshold)) { : missing value where TRUE/FALSE needed, which apparently, should not be the case (ref).

Description:

It happens when I try to fit the model with some data, but not others.
I am trying to model count C with two covariates: Treatment and Mice.

Reproducible Steps:

Code to get the data from dput

structure(list(Treatment = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 5, 
5, 5, 5, 5, 6, 6, 6, 6, 6, 4, 4, 4, 4, 4, 3, 3, 3), C_error = c(6227605.5, 
5844779.25, 1338474, 10365561.75, 6349542.75, 9831545.25, 10968084, 
15513791.25, 2564861.25, 6725652.75, 1609213.5, 716698.5, 991467.75, 
822666, 521778, 11940, 345215.25, 42237.75, 7611.75, 10746, 447.75, 
447.75, 149.25, 597, 149.25, 14477.25, 1492.5, 7910.25), C_good = c(1008.15, 
216.45, 8583.9, 5557.5, 3956.55, 2195.7, 16155.75, 9490.65, 8712.6, 
3281.85, 290.55, 651.3, 146.25, 165.75, 347.1, 144.3, 95.55, 
42.9, 50.7, 72.15, 152.1, 87.75, 95.55, 101.4, 101.4, 183.3, 
95.55, 801.45), Mice = 1:28), row.names = c(NA, -28L), class = c("tbl_df", 
"tbl", "data.frame"))

My stan model

data{
    int C[28];
    int Mice[28];
    int Treatment[28];
}
parameters{
    vector[6] bT;
    vector[28] bA;
}
model{
    vector[28] lambda;
    bA ~ normal( 0 , 5 );
    bT ~ normal( 5 , 10 );
    for ( i in 1:28 ) {
        lambda[i] = bT[Treatment[i]] + bA[Mice[i]];
        lambda[i] = exp(lambda[i]);
    }
    C ~ poisson( lambda );
}

Current Output:

The model runs when I use data = list(C = d$C_good, ....)
But when I change the count to data = list(C = d$C_error, ....), the model samples and throws the error

Running MCMC with 1 chain, with 1 thread(s) per chain...

Chain 1 Iteration:   1 / 1000 [  0%]  (Warmup) 
Chain 1 Iteration: 100 / 1000 [ 10%]  (Warmup) 
Chain 1 Iteration: 200 / 1000 [ 20%]  (Warmup) 
Chain 1 Iteration: 300 / 1000 [ 30%]  (Warmup) 
Chain 1 Iteration: 400 / 1000 [ 40%]  (Warmup) 
Chain 1 Iteration: 500 / 1000 [ 50%]  (Warmup) 
Chain 1 Iteration: 501 / 1000 [ 50%]  (Sampling) 
Chain 1 Iteration: 600 / 1000 [ 60%]  (Sampling) 
Chain 1 Iteration: 700 / 1000 [ 70%]  (Sampling) 
Chain 1 Iteration: 800 / 1000 [ 80%]  (Sampling) 
Chain 1 Iteration: 900 / 1000 [ 90%]  (Sampling) 
Chain 1 Iteration: 1000 / 1000 [100%]  (Sampling) 
Chain 1 finished in 6.2 seconds.
Warning: 444 of 500 (89.0%) transitions hit the maximum treedepth limit of 10.
See https://mc-stan.org/misc/warnings for details.

Error in if (any(efbmi_per_chain < threshold)) { : 
  missing value where TRUE/FALSE needed

RStan Version:

‘2.26.13’

R Version:

"R version 4.1.3 (2022-03-10)"

Operating System:

Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant