fit-method-summary | R Documentation |
The $summary()
method runs
summarise_draws()
from the posterior
package and returns the output. For MCMC, only post-warmup draws are
included in the summary.
There is also a $print()
method that prints the same summary stats but
removes the extra formatting used for printing tibbles and returns the
fitted model object itself. The $print()
method may also be faster than
$summary()
because it is designed to only compute the summary statistics
for the variables that will actually fit in the printed output whereas
$summary()
will compute them for all of the specified variables in order
to be able to return them to the user. See Examples.
summary(variables = NULL, ...)
variables |
(character vector) The variables to include. |
... |
Optional arguments to pass to |
The $summary()
method returns the tibble data frame created by
posterior::summarise_draws()
.
The $print()
method returns the fitted model object itself (invisibly),
which is the standard behavior for print methods in R.
CmdStanMCMC
, CmdStanMLE
, CmdStanLaplace
, CmdStanVB
, CmdStanGQ
## Not run:
fit <- cmdstanr_example("logistic")
fit$summary()
fit$print()
fit$print(max_rows = 2) # same as print(fit, max_rows = 2)
# include only certain variables
fit$summary("beta")
fit$print(c("alpha", "beta[2]"))
# include all variables but only certain summaries
fit$summary(NULL, c("mean", "sd"))
# can use functions created from formulas
# for example, calculate Pr(beta > 0)
fit$summary("beta", prob_gt_0 = ~ mean(. > 0))
# can combine user-specified functions with
# the default summary functions
fit$summary(variables = c("alpha", "beta"),
posterior::default_summary_measures()[1:4],
quantiles = ~ quantile2(., probs = c(0.025, 0.975)),
posterior::default_convergence_measures()
)
# the functions need to calculate the appropriate
# value for a matrix input
fit$summary(variables = "alpha", dim)
# the usual [stats::var()] is therefore not directly suitable as it
# will produce a covariance matrix unless the data is converted to a vector
fit$print(c("alpha", "beta"), var2 = ~var(as.vector(.x)))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.