Skip to content

Commit 184390f

Browse files
authored
Merge pull request #122 from stan-dev/bugfix/for-bugs-users
Corrections to the for-bugs-users chapter
2 parents 7c2cccc + 0819167 commit 184390f

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/stan-users-guide/for-bugs-users.Rmd

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,36 @@ In BUGS, statements are executed according to the directed graphical
5858
model so that variables are always defined when needed. A side effect
5959
of the direct execution of Stan's modeling language is that statements
6060
execute in the order in which they are written. For instance, the
61-
following Stan program, which sets `mu` before using it to sample `y`.
61+
following Stan program, which sets `mu` before using it to sample `y`:
6262

6363
```
6464
mu = a + b * x;
65-
y ~ normal(mu,sigma);
65+
y ~ normal(mu, sigma);
6666
```
67-
68-
It translates to the following C++ code.
67+
translates to the following C++ code:
6968

7069
```
7170
mu = a + b * x;
72-
lp += normal_log(mu,sigma);
71+
target += normal_lpdf(y | mu, sigma);
7372
```
7473

75-
Contrast this with the Stan program
74+
Contrast this with the following Stan program:
7675

7776
```
78-
y ~ normal(mu,sigma)
79-
mu = a + b * x
77+
y ~ normal(mu, sigma);
78+
mu = a + b * x;
8079
```
8180

8281
This program is well formed, but is almost certainly
8382
a coding error, because it attempts to use `mu` before
84-
it is set. It translates to the following C++ code.
83+
it is set. The direct translation to C++ code
84+
highlights the potential error of using `mu` in the first
85+
statement:
8586
```
86-
lp += normal_log(mu,sigma);
87+
target += normal_lpdf(y | mu, sigma);
8788
mu = a + b * x;
8889
```
8990

90-
The direct translation to the imperative language of C++ code
91-
highlights the potential error of using `mu` in the first
92-
statement.
93-
9491
To trap these kinds of errors, variables are initialized to the
9592
special not-a-number (`NaN`) value. If `NaN` is passed to a
9693
log probability function, it will raise a domain exception, which will

0 commit comments

Comments
 (0)