Skip to content

Commit cc2c0c0

Browse files
committed
A few more doc edits to the jacobian sections
1 parent 9b062c2 commit cc2c0c0

8 files changed

Lines changed: 44 additions & 37 deletions

File tree

R/fit.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,8 @@ CmdStanFit$set("public", name = "constrain_variables", value = constrain_variabl
787787
#' fit_mcmc <- cmdstanr_example("logistic")
788788
#' head(fit_mcmc$lp())
789789
#'
790-
#' fit_mle <- cmdstanr_example("logistic", method = "optimize")
791-
#' fit_mle$lp()
790+
#' fit_optim <- cmdstanr_example("logistic", method = "optimize")
791+
#' fit_optim$lp()
792792
#'
793793
#' fit_vb <- cmdstanr_example("logistic", method = "variational")
794794
#' plot(fit_vb$lp(), fit_vb$lp_approx())
@@ -1176,13 +1176,13 @@ CmdStanFit$set("public", name = "metric_files", value = metric_files)
11761176
#' fit_vb <- cmdstanr_example("logistic", method = "variational")
11771177
#' fit_vb$time()
11781178
#'
1179-
#' fit_mle <- cmdstanr_example("logistic", method = "optimize", jacobian = TRUE)
1180-
#' fit_mle$time()
1179+
#' fit_optim <- cmdstanr_example("logistic", method = "optimize", jacobian = TRUE)
1180+
#' fit_optim$time()
11811181
#'
1182-
#' # use fit_mle to draw samples from laplace approximation
1183-
#' fit_laplace <- cmdstanr_example("logistic", method = "laplace", mode = fit_mle)
1182+
#' # use fit_optim to draw samples from laplace approximation
1183+
#' fit_laplace <- cmdstanr_example("logistic", method = "laplace", mode = fit_optim)
11841184
#' fit_laplace$time() # just time for drawing sample not for running optimize
1185-
#' fit_laplace$time()$total + fit_mle$time()$total # total time
1185+
#' fit_laplace$time()$total + fit_optim$time()$total # total time
11861186
#' }
11871187
#'
11881188
time <- function() {
@@ -1216,8 +1216,8 @@ CmdStanFit$set("public", name = "time", value = time)
12161216
#' out <- fit_mcmc$output()
12171217
#' str(out)
12181218
#'
1219-
#' fit_mle <- cmdstanr_example("logistic", method = "optimize")
1220-
#' fit_mle$output()
1219+
#' fit_optim <- cmdstanr_example("logistic", method = "optimize")
1220+
#' fit_optim$output()
12211221
#'
12221222
#' fit_vb <- cmdstanr_example("logistic", method = "variational")
12231223
#' fit_vb$output()
@@ -1245,8 +1245,8 @@ CmdStanFit$set("public", name = "output", value = output)
12451245
#' fit_mcmc <- cmdstanr_example("logistic", method = "sample")
12461246
#' str(fit_mcmc$metadata())
12471247
#'
1248-
#' fit_mle <- cmdstanr_example("logistic", method = "optimize")
1249-
#' str(fit_mle$metadata())
1248+
#' fit_optim <- cmdstanr_example("logistic", method = "optimize")
1249+
#' str(fit_optim$metadata())
12501250
#'
12511251
#' fit_vb <- cmdstanr_example("logistic", method = "variational")
12521252
#' str(fit_vb$metadata())

R/model.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,11 +1597,12 @@ CmdStanModel$set("public", name = "optimize", value = optimize)
15971597
#'
15981598
#' @description The `$laplace()` method of a [`CmdStanModel`] object produces a
15991599
#' sample from a normal approximation centered at the mode of a distribution
1600-
#' in the unconstrained space. The `jacobian` setting must match the value used
1601-
#' when running optimization so that both use the same target density. This
1602-
#' setting controls the parameterization of the density, while the Stan
1603-
#' program determines the contents of the target. See the [CmdStan User’s
1604-
#' Guide](https://mc-stan.org/docs/cmdstan-guide/) for more details.
1600+
#' in the unconstrained space. When the mode was found with the Jacobian
1601+
#' adjustment, the draws provide an estimate of the mean and standard
1602+
#' deviation of the posterior distribution. See the `jacobian` argument below
1603+
#' for how this setting relates to the value used when running optimization,
1604+
#' and the [CmdStan User’s Guide](https://mc-stan.org/docs/cmdstan-guide/)
1605+
#' for more details.
16051606
#'
16061607
#' Any argument left as `NULL` will default to the default value used by the
16071608
#' installed version of CmdStan. See the [CmdStan User’s
@@ -1626,7 +1627,7 @@ CmdStanModel$set("public", name = "optimize", value = optimize)
16261627
#' @param draws (positive integer) The number of draws to take.
16271628
#' @param jacobian (logical) Whether or not to enable the Jacobian adjustment
16281629
#' for constrained parameters. The default is `TRUE`. See the
1629-
#' [Laplace Sampling](https://mc-stan.org/docs/cmdstan-guide/laplace-sampling.html)
1630+
#' [Laplace Sampling](https://mc-stan.org/docs/cmdstan-guide/laplace_sample_config.html)
16301631
#' section of the CmdStan User's Guide for more details. If `mode` is not
16311632
#' `NULL` then the value of `jacobian` must match the value used when
16321633
#' optimization was originally run so the mode and the Laplace approximation

man/fit-method-lp.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fit-method-metadata.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fit-method-output.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fit-method-time.Rd

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/model-method-laplace.Rd

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/cmdstanr.Rmd

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ are called in a similar way to the `$sample()` method demonstrated above.
326326

327327
We can find a mode of the target using
328328
[`$optimize()`](https://mc-stan.org/cmdstanr/reference/model-method-optimize.html).
329+
The point estimate is extracted with the `$mle()` method (the method name is
330+
retained for historical reasons).
329331

330332
```{r optimize}
331333
fit_optim <- mod$optimize(data = data_list, seed = 123)
@@ -342,8 +344,8 @@ mcmc_hist(fit$draws("theta")) +
342344
```
343345

344346
For optimization, by default the mode is calculated without the Jacobian
345-
adjustment for constrained variables. The default finds a mode of the target in
346-
the constrained parameter space, whereas `jacobian = TRUE` finds a mode of the
347+
adjustment for constrained variables, which finds a mode of the target in the
348+
constrained parameter space, whereas `jacobian = TRUE` finds a mode of the
347349
corresponding density in the unconstrained space. See the
348350
[Jacobian adjustments](https://mc-stan.org/docs/cmdstan-guide/optimize_config.html#jacobian-adjustments)
349351
section of the CmdStan User's Guide for more details.
@@ -360,10 +362,12 @@ fit_optim_jacobian <- mod$optimize(
360362

361363
The [`$laplace()`](https://mc-stan.org/cmdstanr/reference/model-method-laplace.html)
362364
method produces a sample from a normal approximation centered at the mode of a
363-
distribution in the unconstrained space. The Laplace `jacobian` setting must
365+
distribution in the unconstrained space. When the mode was found with the
366+
Jacobian adjustment, the draws provide an estimate of the mean and standard
367+
deviation of the posterior distribution. The Laplace `jacobian` setting must
364368
match the setting used for optimization so that both use the same target
365369
density. See the
366-
[Laplace Sampling](https://mc-stan.org/docs/cmdstan-guide/laplace-sampling.html)
370+
[Laplace Sampling](https://mc-stan.org/docs/cmdstan-guide/laplace_sample_config.html)
367371
chapter of the CmdStan User's Guide for more details.
368372

369373
Here we pass in the `fit_optim_jacobian` object from above as the `mode`

0 commit comments

Comments
 (0)