I'm using a very good R package named "changepoint" to detect changes in the variance in my series.
At the moment i'm using cpt.var function, it is very powerful to d开发者_JS百科etect changes BUT I would like to have a more tolerance method.
cpt.var(mod$residuals)
where mod is a linear regression:
mod <- lm(priceA ~ priceB)
If you look at the help file for ?cpt.var
you can change the penalty argument from the default SIC
to Manual
. When using the Manual
, you can specify a type I error value through the value
argument.
Here is an example based on the help file:
# Example of multiple changes in variance at 50,100,150 in simulated data
set.seed(1)
x = c(rnorm(50,0,1), rnorm(50,0,10), rnorm(50,0,5), rnorm(50,0,1))
##Key arguments Manual and value
##Returns 4 changes points
cpt.var(x, penalty="Manual", value="log(2*log(n))", method="BinSeg",
dist="CSS", Q=5, class=FALSE)
##Returns 5 changes points - a false positive
cpt.var(x, penalty="Manual", value="0.5*log(2*log(n))", method="BinSeg",
dist="CSS", Q=5, class=FALSE)
精彩评论