Description Usage Arguments Details Value References See Also
Fit Bayesian nonparametric adaptive temporal smoothing models with the shrinkage-prior Markov random fields (SPMRF) method via Hamiltonian Monte Carlo with the stan
engine from the rstan package.
1 2 3 4 5 |
prior |
A character string specifying which prior to use on order-k differences. Choices are "horseshoe", "laplace", and "normal". Note that "laplace" priors are currently not available for coalescent likelihoods. |
likelihood |
A character string specifying the probability distribution of the observation variable. Current choices are "normal", "poisson","binomial", and "coalescent". |
order |
Numeric value specifying order of differencing (1, 2, or 3). Note that order 3 is currently not available for coalescent likelihoods. |
zeta |
The hyperparameter for the global smoothing parameter gamma. This is the scale parameter of a half-Cauchy distribution. Smaller values will result in more smoothing depending on the prior specification and the strength of the data. Values must be > 0. |
fit |
An instance of S4 class |
data |
A named list providing the data for the model. See details below. |
pars |
A vector of character strings specifying parameters of interest; defaults to NA indicating all parameters in the model. If |
chains |
A positive integer specifying number of chains; defaults to 4. |
iter |
A positive integer specifying how many iterations for each chain (including warmup). The default is 2000. |
warmup |
A positive integer specifying number of warmup (aka burnin) iterations. This also specifies the number of iterations used for stepsize adaptation, so warmup samples should not be used for inference. The number of warmup should not be larger than |
thin |
A positive integer specifying the period for saving sample; defaults to 1. |
save.loglik |
Logical flag for whether to calculate the individual components of the log-likelihood for use in calculating WAIC or LOOIC with the |
... |
Additional arguments passed to |
This function first internally creates stan
model code and a function to generate initial parameter seeds using the information specified in the prior
, likelihood
, order
, and zeta
arguments. It then passes these to the stan
function. The spmrf
function will take additional arguments passed to stan
except for the arguments file
, model_code
, and init
. These arguments are not accepted because they may conflict with model forms expected by spmrf
. See the stan
function documentation for more details.
stan
does all of the work of fitting a Stan model and returning the results as an instance of stanfit
. First, it translates the Stan model to C++ code. Second, the C++ code is compiled into a binary shared object, which is loaded into the current R
session (an object of S4 class stanmodel
is created). Finally, samples are drawn and wrapped in an object of S4 class stanfit
, which provides functions such as print
, summary
, and plot
to inspect and retrieve the results of the fitted model.
spmrf
can also be used to sample again from a fitted model under different settings (e.g., different iter
) by providing argument fit
. In this case, the compiled C++ code for the model is reused.
For any data that is not coalescent data, the list specified by the data
argument must contain an element named y
, which is the vector of the response or observation variable. If the observation variable is binary or binomial, a vector of counts representing the number of 'trials' per observation must also be present and named sizeN
and of the same length as y
. If the observations are on an equally spaced grid with a single observation per grid location, then the xvar1
element can be left unspecified. However, if there are more than one observation per grid location, or if the grid locations are unequally spaced, or if the response is being modeled as a function of a continuous covariate, then an a vector of grid locations or covariate values for each observation must be specified with element name xvar1
and must be of the same length as y
.
For coalescent data, there are several critical elements that must be included in the the list specified by the data
argument. These elements are automatically included when the function make_coalescent_data
is used to generate the data list. See the description of the make_coalescent_data
function for details.
An object of class stanfit
. See stanfit
and stan
for more details.
Faulkner, J. R., and V. N. Minin. 2018. Locally adaptive smoothing with Markov random fields and shrinkage priors. Bayesian Analysis 13(1):225–252.
stan
, stanfit
, get_model
, get_init
, set_zeta
, and make_coalescent_data
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.