dynamite | R Documentation |
Fit a Bayesian dynamic multivariate panel model (DMPM) using Stan for
Bayesian inference. The dynamite package supports a wide range of
distributions and allows the user to flexibly customize the priors for the
model parameters. The dynamite model is specified using standard R formula
syntax via dynamiteformula()
. For more information and examples,
see 'Details' and the package vignettes.
The formula
method returns the model definition as a quoted expression.
Information on the estimated dynamite
model can be obtained via
print()
including the following: The model formula, the data,
the smallest effective sample sizes, largest Rhat and summary statistics of
the time-invariant and group-invariant model parameters.
The summary()
method provides statistics of the posterior samples of the
model; this is an alias of as.data.frame.dynamitefit()
with
summary = TRUE
.
dynamite(
dformula,
data,
time,
group = NULL,
priors = NULL,
backend = "rstan",
verbose = TRUE,
verbose_stan = FALSE,
stanc_options = list("O0"),
threads_per_chain = 1L,
grainsize = NULL,
custom_stan_model = NULL,
debug = NULL,
...
)
## S3 method for class 'dynamitefit'
formula(x, ...)
## S3 method for class 'dynamitefit'
print(x, full_diagnostics = FALSE, ...)
## S3 method for class 'dynamitefit'
summary(object, ...)
dformula |
[ |
data |
[ |
time |
[ |
group |
[ |
priors |
[ |
backend |
[ |
verbose |
[ |
verbose_stan |
[ |
stanc_options |
[ |
threads_per_chain |
[ |
grainsize |
[ |
custom_stan_model |
[ |
debug |
[ |
... |
For |
x |
[ |
full_diagnostics |
By default, the effective sample size (ESS) and Rhat
are computed only for the time- and group-invariant parameters
( |
object |
[ |
The best-case scalability of dynamite
in terms of data size should be
approximately linear in terms of number of time points and and number of
groups, but as wall-clock time of the MCMC algorithms provided by Stan can
depend on the discrepancy of the data and the model (and the subsequent
shape of the posterior), this can vary greatly.
dynamite
returns a dynamitefit
object which is a list containing
the following components:
stanfit
A stanfit
object, see rstan::sampling()
for details.
dformulas
A list of dynamiteformula
objects for internal use.
data
A processed version of the input data
.
data_name
Name of the input data object.
stan
A list
containing various elements related to Stan model
construction and sampling.
group_var
Name of the variable defining the groups.
time_var
Name of the variable defining the time index.
priors
Data frame containing the used priors.
backend
Either "rstan"
or "cmdstanr"
indicating which
package was used in sampling.
permutation
Randomized permutation of the posterior draws.
call
Original function call as an object of class call
.
formula
returns a quoted expression.
print
returns x
invisibly.
summary
returns a data.frame
.
Santtu Tikka and Jouni Helske (2024). dynamite: An R Package for Dynamic Multivariate Panel Models. arXiv preprint, doi:10.48550/arXiv.2302.01607.
Jouni Helske and Santtu Tikka (2022). Estimating Causal Effects from Panel Data with Dynamic Multivariate Panel Models. Advances in Life Course Research, 60, 100617. doi:10.1016/j.alcr.2024.100617.
Model fitting
dynamice()
,
get_priors()
,
update.dynamitefit()
Model formula construction
dynamiteformula()
,
lags()
,
lfactor()
,
random_spec()
,
splines()
Model outputs
as.data.frame.dynamitefit()
,
as.data.table.dynamitefit()
,
as_draws_df.dynamitefit()
,
coef.dynamitefit()
,
confint.dynamitefit()
,
get_code()
,
get_data()
,
get_parameter_dims()
,
get_parameter_names()
,
get_parameter_types()
,
ndraws.dynamitefit()
,
nobs.dynamitefit()
data.table::setDTthreads(1) # For CRAN
# Please update your rstan and StanHeaders installation before running
# on Windows
if (!identical(.Platform$OS.type, "windows")) {
fit <- dynamite(
dformula = obs(y ~ -1 + varying(~x), family = "gaussian") +
lags(type = "varying") +
splines(df = 20),
gaussian_example,
"time",
"id",
chains = 1,
refresh = 0
)
}
data.table::setDTthreads(1) # For CRAN
formula(gaussian_example_fit)
data.table::setDTthreads(1) # For CRAN
print(gaussian_example_fit)
data.table::setDTthreads(1) # For CRAN
summary(gaussian_example_fit,
types = "beta",
probs = c(0.05, 0.1, 0.9, 0.95)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.