get_jagscode: Make JAGS code for Multiple Change Point model

View source: R/get_jagscode.R

get_jagscodeR Documentation

Make JAGS code for Multiple Change Point model

Description

Make JAGS code for Multiple Change Point model

Usage

get_jagscode(prior, ST, formula_str, arma_order, family, sample)

Arguments

prior

Named list. Names are parameter names (cp_i, int_i, xvar_i, 'sigma“) and the values are either

  • A JAGS distribution (e.g., int_1 = "dnorm(0, 1) T(0,)") indicating a conventional prior distribution. Uninformative priors based on data properties are used where priors are not specified. This ensures good parameter estimations, but it is a questionable for hypothesis testing. mcp uses SD (not precision) for dnorm, dt, dlogis, etc. See details. Change points are forced to be ordered through the priors using truncation, except for uniform priors where the lower bound should be greater than the previous change point, dunif(cp_1, MAXX).

  • A numerical value (e.g., int_1 = -2.1) indicating a fixed value.

  • A model parameter name (e.g., int_2 = "int_1"), indicating that this parameter is shared - typically between segments. If two varying effects are shared this way, they will need to have the same grouping variable.

  • A scaled Dirichlet prior is supported for change points if they are all set to ⁠cp_i = "dirichlet(N)⁠ where N is the alpha for this change point and N = 1 is most often used. This prior is less informative about the location of the change points than the default uniform prior, but it samples less efficiently, so you will often need to set iter higher. It is recommended for hypothesis testing and for the estimation of more than 5 change points. Read more.

ST

Segment table. Returned by get_segment_table().

formula_str

String. The formula string returned by build_formula_str.

arma_order

Positive integer. The autoregressive order.

family

One of gaussian(), binomial(), bernoulli(), or poission(). Only default link functions are currently supported.

sample

One of

  • "post": Sample the posterior.

  • "prior": Sample only the prior. Plots, summaries, etc. will use the prior. This is useful for prior predictive checks.

  • "both": Sample both prior and posterior. Plots, summaries, etc. will default to using the posterior. The prior only has effect when doing Savage-Dickey density ratios in hypothesis.

  • "none" or FALSE: Do not sample. Returns an mcpfit object without sample. This is useful if you only want to check prior strings (fit$prior), the JAGS model (fit$jags_code), etc.

Value

String. A JAGS model.

Author(s)

Jonas Kristoffer Lindeløv jonas@lindeloev.dk


mcp documentation built on May 29, 2024, 6:15 a.m.