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 |

`prior` |
A character string specifying which prior to use on order- |

`likelihood` |
A character string specifying the probability distribution of the observation variable. Current choices are "normal", "poisson", and "binomial". |

`order` |
Numeric value specifying order of differencing (1, 2, or 3). |

`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. |

`...` |
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.

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`

.

An object of class `stanfit`

. See `stanfit`

and `stan`

for more details.

Faulkner, J. R., and V. N. Minin. 2017. Locally adaptive smoothing with Markov random fields and shrinkage priors. *Bayesian Analysis* advance publication online.

`stan`

, `stanfit`

, `get_model`

, and `get_init`

faulknerjam/bnps documentation built on Dec. 4, 2017, 5:28 p.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.