View source: R/tar_stan_summary.R
tar_stan_summary | R Documentation |
CmdStanFit
objectCreate a target to run the $summary()
method of a CmdStanFit
object.
tar_stan_summary(
name,
fit,
data = NULL,
variables = NULL,
summaries = NULL,
summary_args = NULL,
format = "fst_tbl",
repository = targets::tar_option_get("repository"),
error = targets::tar_option_get("error"),
memory = targets::tar_option_get("memory"),
garbage_collection = targets::tar_option_get("garbage_collection"),
deployment = targets::tar_option_get("deployment"),
priority = targets::tar_option_get("priority"),
resources = targets::tar_option_get("resources"),
storage = targets::tar_option_get("storage"),
retrieval = targets::tar_option_get("retrieval"),
cue = targets::tar_option_get("cue"),
description = targets::tar_option_get("description")
)
name |
Symbol, base name for the collection of targets. Serves as a prefix for target names. |
fit |
Symbol, name of a |
data |
Code to generate the |
variables |
(character vector) The variables to include. |
summaries |
Optional list of summary functions passed to |
summary_args |
Optional list of summary function arguments passed to
|
format |
Character of length 1, storage format of the data frame
of posterior summaries. We recommend efficient data frame formats
such as |
repository |
Character of length 1, remote repository for target storage. Choices:
Note: if |
error |
Character of length 1, what to do if the target stops and throws an error. Options:
|
memory |
Character of length 1, memory strategy. Possible values:
For cloud-based dynamic files
(e.g. |
garbage_collection |
Logical: |
deployment |
Character of length 1. If |
priority |
Numeric of length 1 between 0 and 1. Controls which
targets get deployed first when multiple competing targets are ready
simultaneously. Targets with priorities closer to 1 get dispatched earlier
(and polled earlier in |
resources |
Object returned by |
storage |
Character string to control when the output of the target
is saved to storage. Only relevant when using
|
retrieval |
Character string to control when the current target
loads its dependencies into memory before running.
(Here, a "dependency" is another target upstream that the current one
depends on.) Only relevant when using
|
cue |
An optional object from |
description |
Character of length 1, a custom free-form human-readable
text description of the target. Descriptions appear as target labels
in functions like |
tar_stan_mcmc()
etc. with summary = TRUE
already gives you a
target with output from the $summary()
method.
Use tar_stan_summary()
to create additional specialized summaries.
tar_stan_summary()
returns target object to
summarize a CmdStanFit
object. The return value of the target
is a tidy data frame of summaries returned by the $summary()
method of the CmdStanFit
object.
See the "Target objects" section for background.
Most stantargets
functions are target factories,
which means they return target objects
or lists of target objects.
Target objects represent skippable steps of the analysis pipeline
as described at https://books.ropensci.org/targets/.
Please read the walkthrough at
https://books.ropensci.org/targets/walkthrough.html
to understand the role of target objects in analysis pipelines.
For developers, https://wlandau.github.io/targetopia/contributing.html#target-factories explains target factories (functions like this one which generate targets) and the design specification at https://books.ropensci.org/targets-design/ details the structure and composition of target objects.
# First, write your Stan model file, e.g. model.stan.
# Then in _targets.R, write a pipeline like this:
if (Sys.getenv("TAR_LONG_EXAMPLES") == "true") {
targets::tar_dir({ # tar_dir() runs code from a temporary directory.
# Running inside a temporary directory to avoid
# modifying the user's file space. The file "model.stan"
# created below lives in a temporary directory.
# This satisfies CRAN policies.
tar_stan_example_file("model.stan")
targets::tar_script({
library(stantargets)
list(
# Run a model and produce default summaries.
tar_stan_mcmc(
your_model,
stan_files = "model.stan",
data = tar_stan_example_data()
),
# Produce a more specialized summary
tar_stan_summary(
your_summary,
fit = your_model_mcmc_model,
data = your_model_data_model,
variables = "beta",
summaries = list(~quantile(.x, probs = c(0.25, 0.75)))
)
)}, ask = FALSE)
targets::tar_make()
})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.