Type: | Package |
Title: | Step-Wise Signal Extraction via Marginal Likelihood |
Version: | 2.6.0 |
Date: | 2018-05-04 |
Author: | Chao Du, Chu-Lan Michael Kao, Samuel Kou |
Maintainer: | Chu-Lan Michael Kao <chulankao@gmail.com> |
Description: | Provides function to estimate multiple change points using marginal likelihood method. See the Manual file in data folder for a detailed description of all functions, and a walk through tutorial. For more information of the method, please see Du, Kao and Kou (2016) <doi:10.1080/01621459.2015.1006365>. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
Imports: | Rcpp (≥ 0.11.3) |
LinkingTo: | Rcpp |
SystemRequirements: | C++11 |
NeedsCompilation: | yes |
Packaged: | 2018-05-04 06:21:04 UTC; USER |
Repository: | CRAN |
Date/Publication: | 2018-05-19 16:40:20 UTC |
Estimating Change Points Using Marginal Likelihood
Description
(See the Manual.pdf file in data folder for a detail description of all functions, and a walkthrough tutorial.)
This packages provides function to estimate multiple change points using marginal likelihood method proposed by Du, Kao and Kou (2015), which we would denoted as DKK2015 afterward. est.changepoints
estimates change-points. PlotChangePoints
plots. Other functions are for the normal and Poisson examples in DKK2015.
Details
Package: | StepSignalMargiLike |
Type: | Package |
Version: | 2.5.9 |
Date: | 2017-8-22 |
License: | GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 |
Author(s)
Chao Du, Chu-Lan Michael Kao, Samuel Kou
Maintainer: Chu-Lan Michael Kao <chulankao@gmail.com>
References
Chao Du, Chu-Lan Michael Kao and S. C. Kou (2016), "Stepwise Signal Extraction via Marginal Likelihood"
Examples
n <- 5
data.x <- rnorm(n, 1, 1)
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 2,1))
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 1,1))
data.t <- 1:(5*n)
prior <- prior.norm.A(data.x)
max.segs <- 10
index.ChPT <- est.changepoints(data.x, mode="normal", prior)
est.mean <- est.mean.norm(data.x, index.ChPT, prior)
PlotChangePoints(data.x, data.t, index.ChPT, est.mean)
PlotChangePoints(data.x, data.t, index.ChPT, est.mean, type.data="p",
col.data="green", col.est="black", main="Stepwise Signal Estimation",
sub="Using Marginal Likelihood", xlab="time", ylab="value")
ChangePointAnalyzeNorm
Description
Supported C++ function used in function est.changepoints
.
Usage
ChangePointAnalyzeNorm
Examples
n <- 5
max.segs <- 5
data.x <- rnorm(n, 1, 1)
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 2,1))
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 1,1))
data.t <- 1:(5*n)
prior <- prior.norm.A(data.x)
ChangePointAnalyzeNorm(data.x, n, max.segs, prior)
ChangePointAnalyzeNormUnRes
Description
Supported C++ function used in function est.changepoints
.
Usage
ChangePointAnalyzeNormUnRes
Examples
n <- 5
data.x <- rnorm(n, 1, 1)
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 2,1))
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 1,1))
data.t <- 1:(5*n)
prior <- prior.norm.A(data.x)
ChangePointAnalyzeNormUnRes(data.x, n, prior)
ChangePointAnalyzePoiss
Description
Supported C++ function used in function est.changepoints
.
Usage
ChangePointAnalyzePoiss
Examples
n <- 20
max.segs <- 5
data.x <- rpois(n, 1)
data.x <- c(data.x, rpois(n, 10))
data.x <- c(data.x, rpois(n, 50))
data.x <- c(data.x, rpois(n, 20))
data.x <- c(data.x, rpois(n, 80))
prior <- prior.pois(data.x)
ChangePointAnalyzePoiss(data.x, n, max.segs, prior)
ChangePointAnalyzePoissUnRes
Description
Supported C++ function used in function est.changepoints
.
Usage
ChangePointAnalyzePoissUnRes
Examples
n <- 20
data.x <- rpois(n, 1)
data.x <- c(data.x, rpois(n, 10))
data.x <- c(data.x, rpois(n, 50))
data.x <- c(data.x, rpois(n, 20))
data.x <- c(data.x, rpois(n, 80))
prior <- prior.pois(data.x)
ChangePointAnalyzePoissUnRes(data.x, n, prior)
PlotChangePoints
Description
This function plots the data and the estimated stepwise signal given the estimated change points and means. The function only applies to one dimensional data.
Usage
PlotChangePoints(data.x, data.t, index.ChPT, est.mean, type.data, col.data,
col.est, main.plot, sub.plot, xlab.plot, ylab.plot)
Arguments
data.x |
Observed data in vector form where each element represents a single observation. |
data.t |
The one-dimensional time or seqeuential labeling for the data. |
index.ChPT |
The set of the index of change points
in a vector. Must be in accending order. This could be
obtained by |
est.mean |
The estimated mean in each segments in a
vector. The length must be one plus the length of
|
type.data |
(Opt.) The line type for the data. Options are the same as in plot() argument. Default is "l". |
col.data |
(Opt.) The line color for the data. Options are the same as in plot() argument. Default is "red". |
col.est |
(Opt.) The line color for the estimated stepwise signal. Options are the same as in plot() arguent. Default is "blue". |
main.plot |
(Opt.) The overall title used in the plot, which is like the main in plot(). Default is NULL. |
sub.plot |
(Opt.) The sub title used in the plot, which is like the main in plot(). Default is NULL. |
xlab.plot |
(Opt.) The title for the x axis used in the plot, which is like the main in plot(). Default is "data.t". |
ylab.plot |
(Opt.) The title for the y axis used in the plot, which is like the main in plot(). Default is "data.x". |
Details
See Manual.pdf in "data" folder.
Value
Plot for the data and the estimated change-points. Note that this function only apply to one-dimensional observation.
Examples
library(StepSignalMargiLike)
n <- 5
data.x <- rnorm(n, 1, 1)
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 2,1))
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 1,1))
data.x <- matrix(data.x, 1)
data.t <- 1:(5*n)
index.ChPT <- c(n,2*n,3*n,4*n)
est.mean <- c(1,10,2,10,2)
PlotChangePoints(data.x, data.t, index.ChPT, est.mean)
PlotChangePoints(data.x, data.t, index.ChPT, est.mean, type.data="p",
col.data="green", col.est="black", main="Stepwise Signal Estimation",
sub="Using Marginal Likelihood", xlab="time", ylab="value")
StepSignalMargiLike_ChangePointAnalyzeNorm
Description
Supported C++ function used in function est.changepoints
.
Usage
StepSignalMargiLike_ChangePointAnalyzeNorm
Examples
n <- 5
max.segs <- 5
data.x <- rnorm(n, 1, 1)
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 2,1))
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 1,1))
data.t <- 1:(5*n)
prior <- prior.norm.A(data.x)
ChangePointAnalyzeNorm(data.x, n, max.segs, prior)
StepSignalMargiLike_ChangePointAnalyzeNormUnRes
Description
Supported C++ function used in function est.changepoints
.
Usage
StepSignalMargiLike_ChangePointAnalyzeNormUnRes
Examples
n <- 5
data.x <- rnorm(n, 1, 1)
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 2,1))
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 1,1))
data.t <- 1:(5*n)
prior <- prior.norm.A(data.x)
ChangePointAnalyzeNormUnRes(data.x, n, prior)
StepSignalMargiLike_ChangePointAnalyzePoiss
Description
Supported C++ function used in function est.changepoints
.
Usage
StepSignalMargiLike_ChangePointAnalyzePoiss
Examples
n <- 20
max.segs <- 20
data.x <- rpois(n, 1)
data.x <- c(data.x, rpois(n, 10))
data.x <- c(data.x, rpois(n, 50))
data.x <- c(data.x, rpois(n, 20))
data.x <- c(data.x, rpois(n, 80))
prior <- prior.pois(data.x)
ChangePointAnalyzePoiss(data.x, n, max.segs, prior)
StepSignalMargiLike_ChangePointAnalyzePoissUnRes
Description
Supported C++ function used in function est.changepoints
.
Usage
StepSignalMargiLike_ChangePointAnalyzePoissUnRes
Examples
n <- 20
data.x <- rpois(n, 1)
data.x <- c(data.x, rpois(n, 10))
data.x <- c(data.x, rpois(n, 50))
data.x <- c(data.x, rpois(n, 20))
data.x <- c(data.x, rpois(n, 80))
prior <- prior.pois(data.x)
ChangePointAnalyzePoissUnRes(data.x, n, prior)
est.changepoints
Description
This function estimates multiple change points using marginal likelihood method proposed by Du, Kao and Kou (2015), which we would denoted as DKK2015 afterward.
Usage
est.changepoints(data.x, model, prior, max.segs, logH, logMD)
Arguments
data.x |
Observed data in vector or matrix form. When the data is in matrix form, each column should represent a single observation. |
model |
The specified distributional assumption. Currently we have implemented two arguments: "normal" (data follows one dimensional Normal distribution with unknown mean and variance) and "poisson" (data follows Poisson distribution with unknown intensity). A third argument "user" is also accepted, given that the prior and the log marginal likelihood function are specified in the parameter prior and logMD. |
prior |
The prespecified prior parameters in
consistent with the form used in |
max.segs |
(Opt.) The maximum number of segments allowed, which is the value M in DKK2015. Must be a positive integer greater then 1. If missing, the function would process using the algorihtm by Jackson et al.(2005). |
logH |
(Opt.) A Boolean algebra determine whether to report the log H matrix in DKK2015. Default is FALSE. |
logMD |
(Opt.) The log marginal likelihood function (which
is the log of D function in DKK2015). The function must
be in the form of |
Details
See Manual.pdf in "data" folder.
Value
If logH
is FALSE, the function returns the set of
estimated change-points by the index of the data, where
each index is the end point of a segment. If the result
is no change-points, the function returns NULL
.
If logH
is TRUE, then the function
returns a list with three components:
changePTs
is the set of estimated change-points,
log.H
is the log value for the H matrix used in the algorithm,
where log.H(m,i) = log H(x1, x2, ..., xi | m)
, and max.j
records the j
that maximizes the marginal likelihood in each step.
See the manual in data folder for more details.
References
Chao Du, Chu-Lan Michael Kao and S. C. Kou (2015), "Stepwise Signal Extraction via Marginal Likelihood". Forthcoming in Journal of American Statistical Association.
Examples
library(StepSignalMargiLike)
n <- 5
data.x <- rnorm(n, 1, 1)
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 2,1))
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 1,1))
prior <- prior.norm.A(data.x)
max.segs <- 10
est.changepoints(data.x=data.x, model="normal", prior=prior)
est.changepoints(data.x=data.x, model="normal", prior=prior, max.segs=max.segs)
est.changepoints(data.x=data.x, model="normal", prior=prior, max.segs=max.segs,logH=TRUE)
est.mean.norm
Description
This function estimates the posterior mean for each
segments under the normal assumption with conjugate prior.
The variance \sigma^2
is assumed to be drawn from an
inverse Gamma distribution with shape parameter \nu0
and scale parameter \sigma0^2
, while mean is assumed
to be drawn from a normal distribution with mean \mu0
and variance \sigma^2/\kappa0
.
Usage
est.mean.norm(data.x, index.ChPT, prior)
Arguments
data.x |
Observed data in vector form where each element represents a single observation. |
index.ChPT |
The set of the index of change points
in a vector. Must be in accending order. This could be
obtained by |
prior |
Vector contatining prior parameters in the
order of ( |
Details
See Manual.pdf in "data" folder.
Value
Vector containing estimated mean for each segments.
References
Chao Du, Chu-Lan Michael Kao and S. C. Kou (2015), "Stepwise Signal Extraction via Marginal Likelihood". Forthcoming in Journal of American Statistical Association.
Examples
library(StepSignalMargiLike)
n <- 5
data.x <- rnorm(n, 1, 1)
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 2,1))
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 1,1))
prior <- prior.norm.A(data.x)
index.ChPT <- c(n,2*n,3*n,4*n)
est.mean.norm(data.x, index.ChPT, prior)
est.mean.pois
Description
This function estimates the posterior mean for each
segments under the Poisson assumption with conjugate prior.
The data is assumed to follow Poisson(\lambda
), where
\lambda
is assumed to have Beta prior with shape
parameters \alpha
and \beta
.
Usage
est.mean.pois(data.x, index.ChPT, prior)
Arguments
data.x |
Observed data in vector form where each element represents a single observation. |
index.ChPT |
The set of the index of change points
in a vector. Must be in accending order. This could be
obtained by |
prior |
Vector contatining prior parameters in the
order of ( |
.
Details
See Manual.pdf in "data" folder.
Value
Vector containing estimated mean for each segments.
References
Chao Du, Chu-Lan Michael Kao and S. C. Kou (2015), "Stepwise Signal Extraction via Marginal Likelihood". Forthcoming in Journal of American Statistical Association.
Examples
library(StepSignalMargiLike)
n <- 20
data.x <- rpois(n, 1)
data.x <- c(data.x, rpois(n, 10))
data.x <- c(data.x, rpois(n, 50))
data.x <- c(data.x, rpois(n, 20))
data.x <- c(data.x, rpois(n, 80))
data.x <- matrix(data.x,1)
prior <- c(1,2)
index.ChangePTs <- c(n, 2*n, 3*n, 4*n)
est.mean.pois(data.x, index.ChangePTs, prior)
prior.norm.A
Description
This function computes the Norm-A prior proposed in Du, Kao
and Kou (2015), which is used under conjugate normal
assumption. The variance \sigma^2
is assumed to be
drawn from an inverse Gamma distribution with shape
parameter \nu0
and scale parameter \sigma0^2
,
while mean is assumed to be drawn from a normal
distribution with mean \mu0
and variance
\sigma^2/\kappa0
.
Usage
prior.norm.A(data.x)
Arguments
data.x |
Observed data in vector form where each element represents a single observation. |
Details
See Manual.pdf in "data" folder.
Value
Vector for prior parameters in the order of (\mu0,
\kappa0, \nu0, \sigma0^2
)
References
Chao Du, Chu-Lan Michael Kao and S. C. Kou (2015), "Stepwise Signal Extraction via Marginal Likelihood". Forthcoming in Journal of American Statistical Association.
Examples
library(StepSignalMargiLike)
n <- 5
data.x <- rnorm(n, 1, 1)
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 2,1))
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 1,1))
prior.norm.A(data.x)
prior.norm.B
Description
This function computes the Norm-B prior proposed in Du, Kao
and Kou (2015), which is used under conjugate normal
assumption. The variance \sigma^2
is assumed to be
drawn from an inverse Gamma distribution with shape
parameter \nu0
and scale parameter \sigma0^2
,
while mean is assumed to be drawn from a normal
distribution with mean \mu0
and variance
\sigma^2/\kappa0
.
Usage
prior.norm.B(data.x)
Arguments
data.x |
Observed data in vector form where each element represents a single observation. |
Details
See Manual.pdf in "data" folder.
Value
Vector for prior parameters in the order of (\mu0,
\kappa0, \nu0, \sigma0^2
)
References
Chao Du, Chu-Lan Michael Kao and S. C. Kou (2015), "Stepwise Signal Extraction via Marginal Likelihood". Forthcoming in Journal of American Statistical Association.
Examples
library(StepSignalMargiLike)
n <- 5
data.x <- rnorm(n, 1, 1)
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 2,1))
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 1,1))
prior.norm.B(data.x)
prior.norm.C
Description
This function computes the Norm-C prior proposed in Du, Kao
and Kou (2015), which is used under conjugate normal
assumption. The variance \sigma^2
is assumed to be
drawn from an inverse Gamma distribution with shape
parameter \nu0
and scale parameter \sigma0^2
,
while mean is assumed to be drawn from a normal
distribution with mean \mu0
and variance
\sigma^2/\kappa0
.
Usage
prior.norm.C(data.x)
Arguments
data.x |
Observed data in vector form where each element represents a single observation. |
Details
See Manual.pdf in "data" folder.
Value
Vector for prior parameters in the order of (\mu0,
\kappa0, \nu0, \sigma0^2
)
References
Chao Du, Chu-Lan Michael Kao and S. C. Kou (2015), "Stepwise Signal Extraction via Marginal Likelihood". Forthcoming in Journal of American Statistical Association.
Examples
library(StepSignalMargiLike)
n <- 5
data.x <- rnorm(n, 1, 1)
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 2,1))
data.x <- c(data.x, rnorm(n, 10,1))
data.x <- c(data.x, rnorm(n, 1,1))
prior.norm.C(data.x)
prior.pois
Description
This function computes the Pois prior proposed in Du, Kao
and Kou (2015), which is used under the Poisson assumption
with conjugate prior. The data is assumed to follow
Poisson(\lambda
), where \lambda
is assumed to
have Beta prior with shape parameters \alpha
and
\beta
.
Usage
prior.pois(data.x)
Arguments
data.x |
Observed data in vector form where each element represents a single observation. |
Details
See Manual.pdf in "data" folder.
Value
Vector for prior parameters in the order of (\alpha,
\beta
)
References
Chao Du, Chu-Lan Michael Kao and S. C. Kou (2015), "Stepwise Signal Extraction via Marginal Likelihood". Forthcoming in Journal of American Statistical Association.
Examples
n <- 20
data.x <- rpois(n, 1)
data.x <- c(data.x, rpois(n, 10))
data.x <- c(data.x, rpois(n, 50))
data.x <- c(data.x, rpois(n, 20))
data.x <- c(data.x, rpois(n, 80))
prior.pois(data.x)