CmdStanGQ | R Documentation |
A CmdStanGQ
object is the fitted model object returned by the
$generate_quantities()
method of a
CmdStanModel
object.
CmdStanGQ
objects have the following associated methods,
all of which have their own (linked) documentation pages.
Method | Description |
$draws() | Return the generated quantities as a draws_array . |
$metadata() | Return a list of metadata gathered from the CmdStan CSV files. |
$code() | Return Stan code as a character vector. |
Method | Description |
$summary() | Run posterior::summarise_draws() . |
Method | Description |
$save_object() | Save fitted model object to a file. |
$save_output_files() | Save output CSV files to a specified location. |
$save_data_file() | Save JSON data file to a specified location. |
Method | Description |
$time() | Report the total run time. |
$output() | Return the stdout and stderr of all chains or pretty print the output for a single chain. |
$return_codes() | Return the return codes from the CmdStan runs. |
The CmdStanR website (mc-stan.org/cmdstanr) for online documentation and tutorials.
The Stan and CmdStan documentation:
Stan documentation: mc-stan.org/users/documentation
CmdStan User’s Guide: mc-stan.org/docs/cmdstan-guide
Other fitted model objects:
CmdStanDiagnose
,
CmdStanLaplace
,
CmdStanMCMC
,
CmdStanMLE
,
CmdStanPathfinder
,
CmdStanVB
## Not run:
# first fit a model using MCMC
mcmc_program <- write_stan_file(
"data {
int<lower=0> N;
array[N] int<lower=0,upper=1> y;
}
parameters {
real<lower=0,upper=1> theta;
}
model {
y ~ bernoulli(theta);
}"
)
mod_mcmc <- cmdstan_model(mcmc_program)
data <- list(N = 10, y = c(1,1,0,0,0,1,0,1,0,0))
fit_mcmc <- mod_mcmc$sample(data = data, seed = 123, refresh = 0)
# stan program for standalone generated quantities
# (could keep model block, but not necessary so removing it)
gq_program <- write_stan_file(
"data {
int<lower=0> N;
array[N] int<lower=0,upper=1> y;
}
parameters {
real<lower=0,upper=1> theta;
}
generated quantities {
array[N] int y_rep = bernoulli_rng(rep_vector(theta, N));
}"
)
mod_gq <- cmdstan_model(gq_program)
fit_gq <- mod_gq$generate_quantities(fit_mcmc, data = data, seed = 123)
str(fit_gq$draws())
library(posterior)
as_draws_df(fit_gq$draws())
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.