Skip to content

Commit a443f4f

Browse files
committed
sampling statement -> distribution statement in stan-users-guide
1 parent 0e17907 commit a443f4f

13 files changed

+51
-50
lines changed

src/stan-users-guide/custom-probability.qmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,23 @@ be parameters, data, or one of each, or even local variables.
9393

9494
The assignment statement in the previous paragraph generates
9595
C++ code that is similar to that generated by the following
96-
sampling statement.
96+
distribution statement.
9797

9898
```stan
9999
y ~ exponential(lambda);
100100
```
101101

102-
There are two notable differences. First, the sampling statement will
102+
There are two notable differences. First, the distribution statement will
103103
check the inputs to make sure both `lambda` is positive and
104104
`y` is non-negative (which includes checking that neither is the
105105
special not-a-number value).
106106

107107
The second difference is that if `lambda` is not a parameter,
108-
transformed parameter, or local model variable, the sampling statement
108+
transformed parameter, or local model variable, the distribution statement
109109
is clever enough to drop the `log(lambda)` term. This results in
110110
the same posterior because Stan only needs the log probability up to
111111
an additive constant. If `lambda` and `y` are both
112-
constants, the sampling statement will drop both terms (but still
112+
constants, the distribution statement will drop both terms (but still
113113
check for out-of-domain errors on the inputs).
114114

115115
### Bivariate normal cumulative distribution function {-}

src/stan-users-guide/finite-mixtures.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ y_n \sim
476476
\end{cases}
477477
$$
478478

479-
Stan does not support conditional sampling statements (with `~`) conditional on some parameter, and we need to consider the corresponding likelihood
479+
Stan does not support conditional distribution statements (with `~`) conditional on some parameter, and we need to consider the corresponding likelihood
480480
$$
481481
p(y_n \mid \theta,\lambda)
482482
=
@@ -485,7 +485,7 @@ p(y_n \mid \theta,\lambda)
485485
(1-\theta) \times \textsf{Poisson}(y_n \mid \lambda) &\quad\text{if } y_n > 0.
486486
\end{cases}
487487
$$
488-
The log likelihood can be implemented directly in Stan (with `target +=`) as follows.
488+
The log likelihood can be coded directly in Stan (with `target +=`) as follows.
489489

490490

491491
```stan

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,15 @@ you have a parameter `p` declared as
342342
```stan
343343
real<lower=0, upper=1> p;
344344
```
345-
and then have no sampling statement for `p` in the `model`
345+
and then have no distribution statement for `p` in the `model`
346346
block, then you are implicitly assigning a uniform $[0,1]$ prior on
347347
`p`.
348348

349349
On the other hand, if you have a parameter `theta` declared with
350350
```stan
351351
real theta;
352352
```
353-
and have no sampling statement for `theta` in the `model` block, then
353+
and have no distribution statement for `theta` in the `model` block, then
354354
you are implicitly assigning an improper uniform prior on
355355
$(-\infty,\infty)$ to `theta`.
356356

src/stan-users-guide/gaussian-processes.qmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,11 @@ vector `f`, which consists of the concatenation of the conditional mean
802802
for known outputs `y1` and unknown outputs `y2`. Thus the
803803
combined output vector `f` is aligned with the combined
804804
input vector `x`. All that is left is to define the univariate
805-
normal sampling statement for `y`.
805+
normal distribution statement for `y`.
806806

807807
The generated quantities block defines the quantity `y2`. We generate
808-
`y2` by sampling `N2` univariate normals with each mean corresponding
809-
to the appropriate element in `f`.
808+
`y2` by randomly generating `N2` values from univariate normals with
809+
each mean corresponding to the appropriate element in `f`.
810810

811811

812812
#### Predictive inference in non-Gaussian GPs {-}

src/stan-users-guide/measurement-error.qmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ model {
319319
}
320320
```
321321

322-
The sampling statement for `y` is vectorized; it has the same
322+
The distribution statement for `y` is vectorized; it has the same
323323
effect as the following.
324324
```stan
325325
for (j in 1:J) {
@@ -354,8 +354,8 @@ model {
354354
}
355355
```
356356

357-
Although the vectorized sampling statement for `y` appears
358-
unchanged, the parameter `theta` is now a vector. The sampling
357+
Although the vectorized distribution statement for `y` appears
358+
unchanged, the parameter `theta` is now a vector. The distribution
359359
statement for `theta` is also vectorized, with the
360360
hyperparameters `mu` and `tau` themselves being given wide
361361
priors compared to the scale of the data.

src/stan-users-guide/missing-data.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ for (n in 1:N) {
255255
```
256256

257257
It's a bit more work, but much more efficient to vectorize these
258-
sampling statements. In transformed data, build up three vectors of
258+
distribution statements. In transformed data, build up three vectors of
259259
indices, for the three cases above:
260260

261261
```stan
@@ -267,7 +267,7 @@ transformed data {
267267
```
268268

269269
You will need to write functions that pull out the count of
270-
observations in each of the three sampling situations. This must be
270+
observations in each of the three situations. This must be
271271
done with functions because the result needs to go in top-level block
272272
variable size declaration. Then the rest of transformed data just
273273
fills in the values using three counters.

src/stan-users-guide/multi-indexing.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ in speed to the clunky assignment to a local variable.
4242
```
4343

4444
The boost in speed compared to the original version is because the
45-
single call to the normal log density in the sampling statement will
45+
single call to the normal log density in the distribution statement will
4646
be much more memory efficient than the original version.
4747

4848

src/stan-users-guide/regression.qmd

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ improper priors for the two regression coefficients.
5555

5656
### Matrix notation and vectorization {- #vectorization.section}
5757

58-
The sampling statement in the previous model is vectorized, with
58+
The distribution statement in the previous model is vectorized, with
5959

6060
```stan
6161
y ~ normal(alpha + beta * x, sigma);
@@ -114,7 +114,7 @@ the entire model may be written using matrix arithmetic as shown. It
114114
would be possible to include a column of ones in the data matrix `x` to
115115
remove the `alpha` parameter.
116116

117-
The sampling statement in the model above is just a more efficient,
117+
The distribution statement in the model above is just a more efficient,
118118
vector-based approach to coding the model with a loop, as in the
119119
following statistically equivalent model.
120120

@@ -259,7 +259,7 @@ term $\epsilon$ as having a normal distribution. From Stan's
259259
perspective, there is nothing special about normally distributed
260260
noise. For instance, robust regression can be accommodated by giving
261261
the noise term a Student-$t$ distribution. To code this in Stan, the
262-
sampling distribution is changed to the following.
262+
distribution distribution is changed to the following.
263263

264264

265265
```stan
@@ -357,7 +357,7 @@ $$
357357

358358
The cumulative standard normal distribution function $\Phi$ is implemented
359359
in Stan as the function `Phi`. The probit regression model
360-
may be coded in Stan by replacing the logistic model's sampling
360+
may be coded in Stan by replacing the logistic model's distribution
361361
statement with the following.
362362

363363

@@ -806,7 +806,7 @@ recommendations on priors for regression coefficients and scales.
806806

807807
#### Optimizing the model {-}
808808

809-
Where possible, vectorizing sampling statements leads to faster log
809+
Where possible, vectorizing distribution statements leads to faster log
810810
probability and derivative evaluations. The speed boost is not
811811
because loops are eliminated, but because vectorization allows sharing
812812
subcomputations in the log probability and gradient calculations and
@@ -847,7 +847,7 @@ Stan because they are translated directly to C++. In most cases, the
847847
cost of allocating and assigning to a container is more than made up
848848
for by the increased efficiency due to vectorizing the log probability
849849
and gradient calculations. Thus the following version is faster than
850-
the original formulation as a loop over a sampling statement.
850+
the original formulation as a loop over a distribution statement.
851851

852852

853853
```stan
@@ -1062,7 +1062,7 @@ $$
10621062
\textsf{normal}\left(y \mid 0, 1\right).
10631063
$$
10641064

1065-
The sampling statement is also vectorized using elementwise
1065+
The distribution statement is also vectorized using elementwise
10661066
multiplication; it is equivalent to
10671067

10681068
```stan
@@ -1409,13 +1409,13 @@ with the vectorized form:
14091409

14101410
The outer brackets create a local scope in which to define the
14111411
variable `x_beta_jj`, which is then filled in a loop and used
1412-
to define a vectorized sampling statement. The reason this is such a
1412+
to define a vectorized distribution statement. The reason this is such a
14131413
big win is that it allows us to take the log of sigma only once and it
14141414
greatly reduces the size of the resulting expression graph by packing
14151415
all of the work into a single density function.
14161416

14171417
Although it is tempting to redeclare `beta` and include a revised
1418-
model block sampling statement,
1418+
model block distribution statement,
14191419

14201420
```stan
14211421
parameters {
@@ -1428,7 +1428,7 @@ model {
14281428
}
14291429
```
14301430

1431-
this fails because it breaks the vectorization of sampling for
1431+
this fails because it breaks the vectorization for
14321432
`beta`,^[Thanks to Mike Lawrence for pointing this out in the GitHub issue for the manual.]
14331433

14341434
```stan

src/stan-users-guide/reparameterization.qmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ transforms a parameter, then samples it. Only the latter requires a
396396
Jacobian adjustment.
397397

398398
It does not matter whether the probability function is
399-
expressed using a sampling statement, such as
399+
expressed using a distribution statement, such as
400400

401401
```stan
402402
log(y) ~ normal(mu, sigma);
@@ -415,7 +415,7 @@ of variables whose inverse has a gamma distribution. This section
415415
contrasts two approaches, first with a transform, then with a change
416416
of variables.
417417

418-
The transform based approach to sampling `y_inv` with an inverse
418+
The transform based approach to defining `y_inv` to have an inverse
419419
gamma distribution can be coded as follows.
420420

421421
```stan
@@ -431,7 +431,7 @@ model {
431431
}
432432
```
433433

434-
The change-of-variables approach to sampling `y_inv` with an
434+
The change-of-variables approach to defining `y_inv` to have an
435435
inverse gamma distribution can be coded as follows.
436436

437437
```stan

src/stan-users-guide/time-series.qmd

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ scale squared. Finally, the whole regression is inside the
256256
variance parameters) for the normal distribution.
257257

258258
With the regression in the transformed parameters block, the model
259-
reduces a single vectorized sampling statement. Because `r` and
259+
reduces a single vectorized distribution statement. Because `r` and
260260
`sigma` are of length `T`, all of the data are modeled
261261
directly.
262262

@@ -319,20 +319,21 @@ model {
319319

320320
The error terms $\epsilon_t$ are defined as transformed parameters in
321321
terms of the observations and parameters. The definition of the
322-
sampling statement (defining the likelihood) follows the definition,
322+
distribution statement (which also defines the likelihood) follows the
323+
definition,
323324
which can only be applied to $y_n$ for $n > Q$. In this example, the
324325
parameters are all given Cauchy (half-Cauchy for $\sigma$) priors,
325326
although other priors can be used just as easily.
326327

327328
This model could be improved in terms of speed by vectorizing the
328-
sampling statement in the model block. Vectorizing the calculation of
329+
distribution statement in the model block. Vectorizing the calculation of
329330
the $\epsilon_t$ could also be sped up by using a dot product instead
330331
of a loop.
331332

332333

333334
### Vectorized MA(Q) model {-}
334335

335-
A general $\mbox{MA}(Q)$ model with a vectorized sampling probability
336+
A general $\mbox{MA}(Q)$ model with a vectorized distribution statement
336337
may be defined as follows.
337338

338339
```stan
@@ -510,12 +511,12 @@ h_1 &\sim \textsf{normal}\left( \mu, \frac{\sigma}{\sqrt{1 - \phi^2}} \ri
510511
\end{align*}
511512

512513
Rearranging the first line, $\epsilon_t = y_t \exp(-h_t / 2)$,
513-
allowing the sampling distribution for $y_t$ to be written as
514+
allowing the distribution for $y_t$ to be written as
514515
$$
515516
y_t \sim \textsf{normal}(0,\exp(h_t/2)).
516517
$$
517518
The recurrence equation for $h_{t+1}$ may be combined with the
518-
scaling and sampling of $\delta_t$ to yield the sampling distribution
519+
scaling of $\delta_t$ to yield the distribution
519520
$$
520521
h_t \sim \mathsf{normal}(\mu + \phi(h_{t-1} - \mu), \sigma).
521522
$$
@@ -569,7 +570,7 @@ diagonal mass matrix, but will not scale to large values of $T$.
569570

570571
It is relatively straightforward to speed up the effective samples per
571572
second generated by this model by one or more orders of magnitude.
572-
First, the sampling statements for return $y$ is easily vectorized to
573+
First, the distribution statements for return $y$ is easily vectorized to
573574

574575
```stan
575576
y ~ normal(0, exp(h / 2));
@@ -613,9 +614,9 @@ final loop adds in the moving average so that `h[2]` through
613614
`h[T]` are appropriately modeled relative to `phi` and
614615
`mu`.
615616

616-
As a final improvement, the sampling statement for `h[1]` and
617-
loop for sampling `h[2]` to `h[T]` are replaced with a
618-
single vectorized standard normal sampling statement.
617+
As a final improvement, the distribution statements for `h[1]` to
618+
`h[T]` are replaced with a
619+
single vectorized standard normal distribution statement.
619620

620621
```stan
621622
model {

0 commit comments

Comments
 (0)