Open bertozzivill opened 4 years ago
Same issue here. stanc(mystanfile.stan)
says my Stan file is syntactically correct, but when fitting it with stan()
I get no results/output and/or error messages. @bertozzivill you got any workaround in the meanwhile?
@Achab94 Nope, I'm just sticking with the JAGS version of my code for now :/
Sorry for all the hassles with Catalina. When I run the above on my High Sierra Mac OS X machine with rstan 2.19.2, I get this:
TRANSLATING MODEL 'dabf8abd0c0011e93f78bc1b1c0419d1' FROM Stan CODE TO C++ CODE NOW.
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Cannot assign to variable outside of declaration block; left-hand-side variable origin=parameter
Illegal statement beginning with non-void expression parsed as
llin_count[i]
Not a legal assignment, sampling, or function statement. Note that
* Assignment statements only allow variables (with optional indexes) on the left;
* Sampling statements allow arbitrary value-denoting expressions on the left.
* Functions used as statements must be declared to have void returns
error in 'model14a676f79e28c_dabf8abd0c0011e93f78bc1b1c0419d1' at line 20, column 8
-------------------------------------------------
18:
19: for(i in 1:N){
20: llin_count[i] = avg_llin[i]*population[i]/hh[i];
^
21: }
-------------------------------------------------
This correctly diagnoses the problem as trying to assign to llin_count
in the model block when it was declared in the parameters block. You can't assign to parameters at all in Stan. Because the quantity llin_count
isn't used in the log density, you can declare and define it in the generated quantities block, which is much more efficient and clearly indicates it's a transfrom from the fitted parameters:
generated quantities {
real<lower = 0> llin_count[N];
for(i in 1:N)
llin_count[i] = avg_llin[i] * population[i] / hh[i];
}
You can do it with a one-liner if you redeclare avg_llin
, population
, and hh
as vectors and use the elementwise multiplication and division operators,
generated quantities {
vector<lower = 0>[N] llin_count = avg_llin .* population ./ hh;
}
Hi @bob-carpenter,
Thank you for helping me diagnose the problem with this code, and for the vectorizing tips. Unfortunately to use Stan I need a fix for the underlying issue of error displays-- this code is just part of a much larger model I'm trying to translate, and I need to be able to actively debug.
Have there been reports of these types of issues on Windows? It's relatively painless for me to gain access to a Windows VM if I'm likely to have better luck there.
Usually we have more problems on Windows than elsewhere. Can you try running RStan in an R terminal rather than RStudio with the suggested parallelization options turned off? I think this turns off the parallelization:
options(mc.cores = 1)
On Dec 1, 2019, at 8:05 PM, Amelia Bertozzi-Villa notifications@github.com wrote:
Hi @bob-carpenter,
Thank you for helping me diagnose the problem with this code, and for the vectorizing tips. Unfortunately to use Stan I need a fix for the underlying issue of error displays-- this code is just part of a much larger model I'm trying to translate, and I need to be able to actively debug.
Have there been reports of these types of issues on Windows? It's relatively painless for me to gain access to a Windows VM if I'm likely to have better luck there.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
Same issue, including suppression of errors after running stan
:
You're restoring history here, which can confound matters. Could you (a) start in a clean R session, and (b) set options(mc.cores = 1).
If that doesn't work, you're going to need help from a real rstan dev---I'm just a user.
The options
line was already in the example_stan.r
script I ran. Starting in a clean R session gets the same result sadly, but thank you for your help!
I am having the same issue. Has there been any fix?
Hi @jsilve24 ,
I just tried the solution identified in issue #735 , and it worked for me:
install.packages("rstan", type="source")
Let me know if it works for you as well and I'll close this issue?
Hi @jsilve24 , I can confirm i solved it with the same procedure @bertozzivill suggested.
Summary:
Upon running a misspecified model in stan, I get no output and my RStudio no longer prints any error messages.
Description and Reproducible Steps:
I'm new to Stan (pivoting from JAGS), and trying to learn how get my syntax right. For a toy example, let's look at the code below:
I'm sure there's something wrong with my Stan code. What I would expect, upon running the
stan()
function, is to see an error message with some description of where things are going wrong.Instead, my call to
stan()
prints the following, and no more:Even though the
stan
call does not throw an error, nosurvey_prep_model
object is saved to my environment. Strangely, all RStudio error messages are suppressed as well. Executing commands such asprint(nonexistent_object)
ornonexistent_function(4995)
prints no error to the console. I have to quit and restart RStudio in order to see error messages again.Running e.g.
print("example_string")
orpackageVersion("rstan")
works as expected, so it is only errors that are suppressed.This bug may be related to this issue, but this model is very small so I wouldn't expect any memory issues.
RStan Version:
2.19.2
R Version:
3.6.0
Operating System:
10.15.1 As described here, I've already worked through the fixes associated with having Catalina installed.
Thanks for your help.