Title: | Semiparametric Analysis of Change-Point |
---|---|
Description: | Semiparametric empirical likelihood ratio based tests of change-point with one-change or epidemic alternatives with data-based model diagnostic are contained. |
Authors: | Zhong Guan <[email protected]> |
Maintainer: | Zhong Guan <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.2 |
Built: | 2024-10-31 21:25:15 UTC |
Source: | CRAN |
By resampling with(out) replacement from the original sample data,
we can obtain bootstrap(permutation) versions of the test statistics.
The p
-values of the test(s) from the original data are approximated by the
p
-values of the bootstrap(permutation) version statistics.
BootsChapt(x, stat1, stat2 = NULL, B, replace = FALSE, alternative = c("one.change", "epidemic"), adj.Wn = FALSE, tol = 1.0e-7, maxit = 50,trace = FALSE,... )
BootsChapt(x, stat1, stat2 = NULL, B, replace = FALSE, alternative = c("one.change", "epidemic"), adj.Wn = FALSE, tol = 1.0e-7, maxit = 50,trace = FALSE,... )
x |
a numeric vector or matrix containing the data, one row per observation; |
stat1 |
test statistic |
stat2 |
test statistic |
B |
number of resamples |
replace |
a logical indicating whether bootstrap samples for bootstrap test
of the change-point are selected with or without replacement, if |
alternative |
a character string specifying the alternative hypothesis,
must be one of |
adj.Wn |
logical indicating if |
tol |
the desired accuracy (convergence tolerance), an argument of |
maxit |
the maximum number of iterations, an argument of |
trace |
logical indicating if output should be produced for each
iteration, an argument of |
... |
other arguments |
The procedure will fail when there is separation in the data in the sense of Albert \& Anderson(1984, Biometrika) and Santner \& Duffy (1986, Biometrika). In this case, the change-point(s) may be detected easily using nonparametric method based on cumsum. Now, this program does not check whether the data is separated.
p.boots |
bootstrap |
p.boots.Vn |
bootstrap |
p.boots.Wn |
bootstrap |
Default alternative is "one-change"
, even when stat2
is not NULL.
If alternative = "epidemic"
, both stat1
and stat2
should be provided.
Statistic Wn
need be adjusted only for one dimensional observations
and if no bootstrap test is conducted. However, if Wn
is already adjusted, you have to asign
adj.Wn = TRUE
to calculate the p
-value of Wn
.
Zhong Guan [email protected]
Guan, Z.(2001) Some Results About Empirical Likelihood Method, Ph.D. Thesis, The University of Toledo.
Guan, Z.(2004) A semiparametric changepoint model, Biometrika, 91, 4, 849–862.
Guan, Z. Semiparametric Tests for Change-points with Epidemic Alternatives.
SemiparChangePoint
, schapt
, p.OneChange
, p.Epidemic.Vn
, p.Epidemic.Wn
require(sac) #load the package # one-change alternative k<-10 n<-20 x<-rnorm(n,0,1) x[(k+1):n]<-x[(k+1):n]+1.5 T<-SemiparChangePoint(x, alternative = "one.change")$Sn BootsChapt(x, T, B = 5) #Choose larger B to get better approximate p-value.
require(sac) #load the package # one-change alternative k<-10 n<-20 x<-rnorm(n,0,1) x[(k+1):n]<-x[(k+1):n]+1.5 T<-SemiparChangePoint(x, alternative = "one.change")$Sn BootsChapt(x, T, B = 5) #Choose larger B to get better approximate p-value.
Using bootstrap method to approximate the p
-value of test of the model validity.
Bootstrap samples are drawn from the semiparametrica empirical distribution which
are estimates of the underlying population distributions.
BootsModelTest(x, k, m, B, Alpha, Beta, tol = 1.0e-7, maxit=50, trace=FALSE)
BootsModelTest(x, k, m, B, Alpha, Beta, tol = 1.0e-7, maxit=50, trace=FALSE)
x |
a numeric vector or matrix containing the data, one row per observation; |
k |
the estimated change-point, output of |
m |
= |
B |
number of resamples |
Alpha |
estimated parameter |
Beta |
estimated parameter |
tol |
the desired accuracy (convergence tolerance), an argument of |
maxit |
the maximum number of iterations, an argument of |
trace |
logical indicating if output should be produced for each
iteration, an argument of |
Delta |
The test statistic of the model validity |
Pvalue |
The bootstrapped |
Zhong Guan [email protected]
Guan, Z.(2001) Some Results About Empirical Likelihood Method, Ph.D. Thesis, The University of Toledo.
Guan, Z.(2004) A semiparametric changepoint model, Biometrika, 91, 4, 849–862.
Guan, Z. Semiparametric Tests for Change-points with Epidemic Alternatives.
## Nile data with one change-point: the annual flows drop in 1898. ## It is believed to be caused by the building of the first Aswan dam. if(! "package:stats" %in% search()) library(stats) data(Nile) require(sac) #load the package Nile.res<-SemiparChangePoint(Nile, alternative = "one.change") BootsModelTest(Nile, Nile.res$k.hat, length(Nile), B=5, Nile.res$alpha.hat, Nile.res$beta.hat) # Choose larger B to get better approximate p-value. # It takes longer to do bootstrap model test for large B.
## Nile data with one change-point: the annual flows drop in 1898. ## It is believed to be caused by the building of the first Aswan dam. if(! "package:stats" %in% search()) library(stats) data(Nile) require(sac) #load the package Nile.res<-SemiparChangePoint(Nile, alternative = "one.change") BootsModelTest(Nile, Nile.res$k.hat, length(Nile), B=5, Nile.res$alpha.hat, Nile.res$beta.hat) # Choose larger B to get better approximate p-value. # It takes longer to do bootstrap model test for large B.
Return the approximate critical values of the test statistics given level alfa
Sn.alfa(alfa,n,d,model=c("parametric","semiparametric"), tol = .Machine$double.eps^0.25, maxiter = 1000) CV.Epidemic.Vn(alfa, d, tol = 1e-10) CV.Epidemic.Wn(alfa, tol = 1e-07)
Sn.alfa(alfa,n,d,model=c("parametric","semiparametric"), tol = .Machine$double.eps^0.25, maxiter = 1000) CV.Epidemic.Vn(alfa, d, tol = 1e-10) CV.Epidemic.Wn(alfa, tol = 1e-07)
alfa |
significance level |
n |
sample size |
model |
a character string specifying the model,
must be one of |
d |
dimension of the data value |
tol |
the desired accuracy (convergence). |
maxiter |
the maximum number of iterations for |
Function Sn.alfa
returns the critical value
of Sn
for one-change alternative. The functions CV.Epidemic.Vn
and CV.Epidemic.Wn
calculate critical values
for Vn
and Wn
.
Critical values
Zhong Guan [email protected]
Csorgo, M. and Horvath, L. (1997), Limit Theorems in Change-Point Analysis, New York: John Wiley
require(sac) #load the package alpha<-0.05 n<-20 d<-1 Sn.alfa(alpha, n, d, model="semiparametric") CV.Epidemic.Vn(alpha, d) CV.Epidemic.Wn(alpha)
require(sac) #load the package alpha<-0.05 n<-20 d<-1 Sn.alfa(alpha, n, d, model="semiparametric") CV.Epidemic.Vn(alpha, d) CV.Epidemic.Wn(alpha)
Compute test statistic based on CUMSUM and change-point estimate
cumsum.test(x, alternative = c("one.change", "epidemic"))
cumsum.test(x, alternative = c("one.change", "epidemic"))
x |
a numeric vector or matrix containing the data, one row per observation; |
alternative |
a character string specifying the alternative hypothesis,
must be one of |
Sn |
test statistic |
k.hat |
estimated change-point |
m.hat |
the second estimated change-point for epidemic alternative |
Zhong Guan [email protected]
Csorgo, M. and Horvath, L. (1997), Limit Theorems in Change-Point Analysis, New York: John Wiley
require(sac) #load the package # one-change alternative k<-10 n<-30 x<-rnorm(n,0,1) x[(k+1):n]<-x[(k+1):n]+1.5 cumsum.test(x, alternative = "one.change") # epidemic alternative k<-10 m<-20 n<-30 x<-rnorm(n,0,1) x[(k+1):m]<-x[(k+1):m]+1.5 cumsum.test(x, alternative = "epidemic")
require(sac) #load the package # one-change alternative k<-10 n<-30 x<-rnorm(n,0,1) x[(k+1):n]<-x[(k+1):n]+1.5 cumsum.test(x, alternative = "one.change") # epidemic alternative k<-10 m<-20 n<-30 x<-rnorm(n,0,1) x[(k+1):m]<-x[(k+1):m]+1.5 cumsum.test(x, alternative = "epidemic")
Plot and compare the empirical likelihood and semiparametric empirical likelihood distribution functions, plot loglikelihood function.
Graf.Diagnostic(x, k, m, Alpha, Beta, Color, LTY, xlab = "x", ylab = "Estimated DF's", main = "Model Diagnostic", OneLegend = TRUE, lgnd1, lgnd2, arw1, arw2, ...) Plot.ll(x, ll, col, xaxis.lab = NULL, xlab = "k", ylab = "Loglikelihood", main = "Plot of Loglikelihood",...)
Graf.Diagnostic(x, k, m, Alpha, Beta, Color, LTY, xlab = "x", ylab = "Estimated DF's", main = "Model Diagnostic", OneLegend = TRUE, lgnd1, lgnd2, arw1, arw2, ...) Plot.ll(x, ll, col, xaxis.lab = NULL, xlab = "k", ylab = "Loglikelihood", main = "Plot of Loglikelihood",...)
x |
a numeric vector or matrix containing the data, one row per observation; |
ll |
loglikelihood function, output of |
col |
color code or character string for the loglikelihood curve |
xaxis.lab |
a vector of character strings or numeric values to be placed at
the tickpoints as |
k |
the estimated change-point, output of |
m |
= |
Alpha |
estimated parameter |
Beta |
estimated parameter |
Color |
a vector of character strings or color codes for
curves of estimated distribution functions |
LTY |
vector of lty's, LTY=c(lty1, lty2, lty3, lty4), corresponds to the above color codes |
xlab |
character string for x-axis lable |
ylab |
character string for y-axis lable |
main |
character string for main title |
OneLegend |
a logical indicating whether plot one or two legend. |
lgnd1 |
a numeric vector of two specify the position of the first legend box |
lgnd2 |
a numeric vector of two specify the position of the second legend box,
if |
arw1 |
a numeric vector of four numbers indicating start and end positions of the first arrows point to curves |
arw2 |
a numeric vector of four numbers indicating start and end positions of the second arrows point to curves |
... |
other arguments of function |
Zhong Guan [email protected]
Guan, Z.(2001) Some Results About Empirical Likelihood Method, Ph.D. Thesis, The University of Toledo;
Guan, Z.(2004) A semiparametric change-point model, Biometrika, 91, 4, 849–862.
Guan, Z. Semiparametric Tests for Changepoints with Epidemic Alternatives.
require(sac) #load the package k<-30 n<-80 x<-rnorm(n,0,1) x[(k+1):n]<-x[(k+1):n]+1.5 res<-SemiparChangePoint(x, alternative = "one.change") Plot.ll(x, res$ll, col="blue") ## Nile data with one change-point: the annual flows drop in 1898 which corresponds ## to k=28. It is believed to be caused by the building of the first Aswan dam. if(! "package:sac" %in% search()) library(sac) #if package sac has not been loaded, load it. if(! "package:stats" %in% search()) library(stats) data(Nile) plot(Nile, type="p") Nile.res<-SemiparChangePoint(Nile, alternative = "one.change") Color<-c(1,2,3,4); LTY<-c(1,2,3,4) ## Plots of estimated distribution functions Graf.Diagnostic(Nile, Nile.res$k.hat, length(Nile), Nile.res$alpha.hat, Nile.res$beta.hat, Color, LTY, xlab = "x", ylab = "Estimated DF's", main="Model Diagnostic for Nile Data", OneLegend = FALSE, lgnd1 = c(1100, 0.15), lgnd2 = c(600, .99), arw1=c(780, .93, 1010, .9), arw2 = c(1165, .15, 1015, .24)) ## Plot of loglikelihood function Plot.ll(Nile, Nile.res$ll, col = "blue") Plot.ll(Nile, Nile.res$ll, col = "blue", xaxis.lab = seq(1871,1970, length = 100), xlab = "Year")
require(sac) #load the package k<-30 n<-80 x<-rnorm(n,0,1) x[(k+1):n]<-x[(k+1):n]+1.5 res<-SemiparChangePoint(x, alternative = "one.change") Plot.ll(x, res$ll, col="blue") ## Nile data with one change-point: the annual flows drop in 1898 which corresponds ## to k=28. It is believed to be caused by the building of the first Aswan dam. if(! "package:sac" %in% search()) library(sac) #if package sac has not been loaded, load it. if(! "package:stats" %in% search()) library(stats) data(Nile) plot(Nile, type="p") Nile.res<-SemiparChangePoint(Nile, alternative = "one.change") Color<-c(1,2,3,4); LTY<-c(1,2,3,4) ## Plots of estimated distribution functions Graf.Diagnostic(Nile, Nile.res$k.hat, length(Nile), Nile.res$alpha.hat, Nile.res$beta.hat, Color, LTY, xlab = "x", ylab = "Estimated DF's", main="Model Diagnostic for Nile Data", OneLegend = FALSE, lgnd1 = c(1100, 0.15), lgnd2 = c(600, .99), arw1=c(780, .93, 1010, .9), arw2 = c(1165, .15, 1015, .24)) ## Plot of loglikelihood function Plot.ll(Nile, Nile.res$ll, col = "blue") Plot.ll(Nile, Nile.res$ll, col = "blue", xaxis.lab = seq(1871,1970, length = 100), xlab = "Year")
Calculate the approximate p
-values of the test statistics
Tn
, Vn
and Wn
using limit null distributions.
p.OneChange(n, d, Sn) p.Epidemic.Vn(Vn, d, tol = 1e-10) p.Epidemic.Wn(Wn, tol = 1e-07)
p.OneChange(n, d, Sn) p.Epidemic.Vn(Vn, d, tol = 1e-10) p.Epidemic.Wn(Wn, tol = 1e-07)
Sn |
test statistic |
Vn |
test statistic |
Wn |
test statistic |
n |
sample size |
d |
dimension of the data value |
tol |
the desired accuracy. |
p.value |
|
Zhong Guan [email protected]
Guan, Z.(2001) Some Results About Empirical Likelihood Method, Ph.D. Thesis, The University of Toledo.
Guan, Z.(2004) A semiparametric changepoint model, Biometrika, 91, 4, 849–862.
Guan, Z. Semiparametric Tests for Change-points with Epidemic Alternatives.
require(sac) #load the package # one-change alternative k<-10 n<-30 x<-rnorm(n,0,1) x[(k+1):n]<-x[(k+1):n]+1.5 T<-SemiparChangePoint(x, alternative = "one.change")$Sn p.OneChange(n, d=1, T) # epidemic alternative k<-5 m<-10 n<-20 x<-rnorm(n,0,1) x[(k+1):m]<-x[(k+1):m]+1.5 res<-SemiparChangePoint(x, alternative = "e") V<-res$Vn; W<-res$Wn p.Epidemic.Vn(V, d=1) p.Epidemic.Wn(W)
require(sac) #load the package # one-change alternative k<-10 n<-30 x<-rnorm(n,0,1) x[(k+1):n]<-x[(k+1):n]+1.5 T<-SemiparChangePoint(x, alternative = "one.change")$Sn p.OneChange(n, d=1, T) # epidemic alternative k<-5 m<-10 n<-20 x<-rnorm(n,0,1) x[(k+1):m]<-x[(k+1):m]+1.5 res<-SemiparChangePoint(x, alternative = "e") V<-res$Vn; W<-res$Wn p.Epidemic.Vn(V, d=1) p.Epidemic.Wn(W)
Semiparametric empirical likelihood ratio based test of changepoint with one-change or epidemic alternatives with data-based model diagnostic
schapt(x, n.boots = 0, replace = FALSE, alternative = c("one.change", "epidemic"), conf.level = 0.95, adj.Wn = FALSE, model.test = FALSE, n.model.boots = 0, tol=1.0e-7, maxit=50,trace=FALSE,... )
schapt(x, n.boots = 0, replace = FALSE, alternative = c("one.change", "epidemic"), conf.level = 0.95, adj.Wn = FALSE, model.test = FALSE, n.model.boots = 0, tol=1.0e-7, maxit=50,trace=FALSE,... )
x |
a numeric vector or matrix containing the data, one row per observation; |
n.boots |
number of bootstrap samples for bootstrap test of the change-point,
if |
replace |
a logical indicating whether bootstrap samples for bootstrap test
of the change-point are selected with or without replacement, if |
alternative |
a character string specifying the alternative hypothesis,
must be one of |
conf.level |
confidence level. |
adj.Wn |
logical indicating if |
model.test |
a logical indicating whether the test of model validity is performed. |
n.model.boots |
number of bootstrap samples for model test, if either
|
tol |
the desired accuracy (convergence tolerance), an argument of |
maxit |
the maximum number of iterations, an argument of |
trace |
logical indicating if output should be produced for each
iteration, an argument of |
... |
other future arguments |
Model: ,
where
and
are the
density (frequency) functions of the two hypothesized populations, and
can be chosen as
or
. The procedure will fail when there is separation in the data in the
sense of Albert \& Anderson(1984, Biometrika) and Santner \& Duffy (1986, Biometrika).
In this case, the change-point(s) may be detected easily using nonparametric method
based on cumsum. Currently, this function does not check whether the data are separated.
data.name |
dataset name |
parameter |
sample size |
alternative |
the alternative hypothesis |
statistic |
a list contains |
estimate |
a list contains change-point(s) and |
p.value |
a list contains |
Statistic Wn
need be adjusted only for one dimensional observations
and if no bootstrap test is conducted. If returned p
-value is 0, this means that the
p
-value is less than 1.0e-7.
Zhong Guan [email protected]
Guan, Z. (2001). Some Results About Empirical Likelihood Method, Ph.D. Thesis, The University of Toledo.
Guan, Z.(2004) A semiparametric change-point model, Biometrika, 91, 4, 849–862.
Guan, Z. Semiparametric Tests for Change-points with Epidemic Alternatives.
require(sac) #load the package # one-change alternative ## Nile data with one change-point: the annual flows drop in 1898. ## It is believed to be caused by the building of the first Aswan dam. if(! "package:sac" %in% search()) library(sac) #if package sac has not been loaded, load it. if(! "package:stats" %in% search()) library(stats) data(Nile) plot(Nile, type="p") schapt(Nile, alternative = "one.change")
require(sac) #load the package # one-change alternative ## Nile data with one change-point: the annual flows drop in 1898. ## It is believed to be caused by the building of the first Aswan dam. if(! "package:sac" %in% search()) library(sac) #if package sac has not been loaded, load it. if(! "package:stats" %in% search()) library(stats) data(Nile) plot(Nile, type="p") schapt(Nile, alternative = "one.change")
Calculate test statistics, loglikelihood function and estimate unknown parameters in the semiparametric model.
SemiparChangePoint(x, alternative = c("one.change", "epidemic"), adj.Wn = FALSE, tol = 1e-07, maxit = 50, trace = FALSE, ...)
SemiparChangePoint(x, alternative = c("one.change", "epidemic"), adj.Wn = FALSE, tol = 1e-07, maxit = 50, trace = FALSE, ...)
x |
a numeric vector or matrix containing the data, one row per observation; |
alternative |
a character string specifying the alternative hypothesis,
must be one of |
tol |
the desired accuracy (convergence tolerance), an argument of |
adj.Wn |
logical indicating if |
maxit |
the maximum number of iterations, an argument of |
trace |
logical indicating if output should be produced for each
iteration, an argument of |
... |
other future arguments |
Model: ,
where
and
are the
density (frequency) functions of the two hypothesized populations, and
can be chosen as
or
. The procedure will fail when there is separation in the data in the
sense of Albert \& Anderson(1984, Biometrika) and Santner \& Duffy (1986, Biometrika).
In this case, the change-point(s) may be detected easily using nonparametric method
based on cumsum. Currently, this function does not check whether the data are separated.
k.hat |
change-point estimate |
m.hat |
second change-point estimate for |
ll |
loglikelihood function |
Sn |
likelihood ratio test statistic for |
Vn |
test statistic based integal of weighted likelihood ratio for |
Wn |
test statistic based supremum of weighted likelihood ratio for |
alpha.hat |
estimate of |
beta.hat |
estimate of |
Statistic Wn
need be adjusted only for one dimensional observations
and if no bootstrap test is conducted.
Zhong Guan [email protected]
Guan, Z.(2001) Some Results About Empirical Likelihood Method, Ph.D. Thesis, The University of Toledo.
Guan, Z.(2004) A semiparametric change-point model, Biometrika, 91, 4, 849–862.
Guan, Z. Semiparametric Tests for Change-points with Epidemic Alternatives.
schapt
, p.OneChange
, p.Epidemic.Vn
,
p.Epidemic.Wn
require(sac) #load the package # one-change alternative k<-10 n<-30 x<-rnorm(n,0,1) x[(k+1):n]<-x[(k+1):n]+1.5 SemiparChangePoint(x, alternative = "one.change") # epidemic alternative k<-5 m<-10 n<-20 x<-rnorm(n,0,1) x[(k+1):m]<-x[(k+1):m]+1.5 SemiparChangePoint(x, alternative = "epidemic")
require(sac) #load the package # one-change alternative k<-10 n<-30 x<-rnorm(n,0,1) x[(k+1):n]<-x[(k+1):n]+1.5 SemiparChangePoint(x, alternative = "one.change") # epidemic alternative k<-5 m<-10 n<-20 x<-rnorm(n,0,1) x[(k+1):m]<-x[(k+1):m]+1.5 SemiparChangePoint(x, alternative = "epidemic")