Compiles (if necessary) and samples a Stan program with rstan,
extracts the draws for one parameter, and passes them to curve_stan().
The Stan program may be one of the models bundled with concurve
(see concurve_stan_file()), a path to a .stan file, or an
already compiled stanmodel object.
curve_stan_fit(model, data, parameter, ..., steps = 1000, table = TRUE)A stanmodel object, a path to a .stan file,
or the name of a bundled model accepted by concurve_stan_file().
A named list of data for the Stan program.
The name of the (scalar) parameter whose confidence distribution is wanted.
Further arguments passed to rstan::sampling(), such as
chains, iter, warmup, seed, and
cores.
Indicates how many consonance intervals are to be calculated at various levels. By default, it is set to 1000.
Indicates whether or not a table output with some relevant statistics should be generated. The default is TRUE and generates a table which is included in the list object.
As curve_stan(). The stanfit object is attached as the
attribute "stanfit" for diagnostics.
rstan is not a hard dependency of concurve; the package
installs and works without it, and this function stops with an
informative message if it is unavailable. Models are compiled with the
C++ toolchain at first use, which takes on the order of a minute, and
the compiled object is cached for the rest of the session (and on disk
if rstan::rstan_options(auto_write = TRUE) is set).
The draws are taken as a Monte Carlo approximation to a confidence
distribution. That is justified when the Stan program's target density
is a generalized fiducial density (Hannig et al., 2016), as in the
bundled "normal_gfd" model, or a posterior under a probability
matching prior. It is not justified for arbitrary Bayesian models; see
curve_stan().
if (FALSE) { # \dontrun{
# Requires rstan and a working C++ toolchain; compiles on first use.
set.seed(4821)
y <- rnorm(12, 3.2, 1.4)
gfd <- curve_stan_fit(
"normal_gfd",
data = list(N = length(y), y = y), parameter = "mu",
chains = 4, iter = 22000, warmup = 2000, seed = 1859
)
ggcurve(gfd[[1]], type = "c")
# The GFD marginal for mu is exactly Student-t, so this should match:
an <- curve_analytic(mean(y), se = sd(y) / sqrt(12), df = 11, dist = "t")
plot_compare(gfd[[1]], an[[1]], type = "c")
} # }