PeriodCPT.bern | R Documentation |
Evaluation of within period changepoint events for Bernoulli distributed observations.
PeriodCPT.bern(data, periodlength = NULL, minseglen = 1, Mprior = c("pois", "unif"),
Mhyp = 1, spread = 1, param.a = 1, param.b = 1,
inits = NULL, n.iter = 1e6, n.chains = 1, n.burn = 0,
cachesize = 50, quiet = FALSE, ...)
data |
A vector or ts object containing the data within which you which to find within period changepoint events. |
periodlength |
Positive integer specifying the period length. If NULL, then information is obtained from ts object specified by data. |
minseglen |
Positive integer giving the minumum segment length (no. of observations between within-period changes), set at 1 for default. |
Mprior |
Option specifying the prior for the number of within period changepoint events. |
Mhyp |
Numeric vector giving the hyper-parameters for the number of within period chagepoint prior, see details. |
spread |
Positive number specifying the prior degree of spread around the period for the changepoint positions. By default, 1 indicates random uniform spread. |
param.a , param.b |
Positive numbers giving the shape hyper-parameters for the beta prior distribution on the within period segment parameter. Both set to 1 by default, giving sepecifying a uniform distribution. |
inits |
Initial values for the chains. See details |
n.iter |
Positive integer giving the number of iterations for the MCMC. |
n.chains |
Positive integer giving the number of chains to evaluate. |
n.burn |
Positive integer giving the initial number iterations to discard as the burn-in period. |
cachesize |
Positive integer giving the cache size to minimise re-evaluation of repeated scenarios within the MCMC algorithm. Set to 50 by default. |
quiet |
Logical flag indicating whether a progress bar should be printed |
... |
Additional inputs, see details. |
This function is used to find with period changepoint events for selected sampling distribution and statistic. A changepoint is denoted as the (!)LAST OBSERVATION OF THE CURRENT SEGMENT/REGIME(!)
Segment parameters: This model assumes that, for a given segment, data~Bern(theta) with prior distribution theta~beta(prior.a, prior.b).
Within period changepoint parameters: The prior for the number of within period changepoint events is either:
Poisson distribution truncated to be between 1 and the maximum number permitted within the period given the minimum segment length constraint. In this case, Mhyp
should contain a single positive number that denotes the lambda hyper-parameter.
Discrete uniform distribution on the integers from 1 to the maximum number permitted within the period given the minimum segment length constraint. The argument Mhyp
is ignored.
Note: the scenario where the number of within period changepoints is equal to 1 defines the case where there are no within-period changepoint events and so model reduces to just the sampling distribution.
Given the total number of changepoint events, the prior for their positions is given in terms of their excess segment length beyond the minimum condition: delta[i] = pcpt[i] - pcpt[i-1] - minseglen. The prior on the vector of excess segment lengths is a Dirichlet-multinomial distribution with shape vector given by spread
(same size for all components). If spread
<1 then there is a prior preference that the changepoints cluster, spread
>1 indicates a prior preference for repellent events, else spread
=1 specifies a uniform distribution. The excess segment lengths are mapped back to the within period changepoint positions with the aid of a anchoring event that follows a uniform distribution over the within peroid positions. If necessary, events are permuted such that all are defined within the interval [1, periodlength].
The chain inital values, init
, can be specified in one of the following ways:
Default, positions are generated from the prior for each chain.
This option specifies inital values for two chains (adjusts n.chains()
accordingly) where the first denotes the trivial case of no within period changepoint events, and the other denots a packed case by fitting in as many events as possible with respect to the minimum segment length.
A vector of integers giving the inital value for one (and only one) requested chain.
A list where each item specifies the vector of initial values for each chain.
The initalisation of a given chain is determined/generated by a provided function. Input arguments for this function can be specified via ...
of the main PeriodCPT funciton. The input names pcpt.object
and chain.index
can be specified to respectively obtain information held within the internally generated pcpt
class object or to specify a function that depends on a specific chain via an integer index.
Note: For codeing ease, the trivial case of no changepoint events is specified by c(1)
.
An object of S4 class "pcpt" is returned.
Simon Taylor
pcpt
, PeriodCPT
set.seed(1)
data = ts( rbinom(120, size = 1, prob = rep(c(0.2, 0.8), each=6)), freq = 12)
ans = PeriodCPT.bern(data, niter = 1e3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.