L0TFinv.opt {L0TFinv} | R Documentation |
The inverse L0 trend filtering with optimal change points
Description
Fit the input data points to a piecewise constant or piecewise linear trend with optimal change points.
Usage
L0TFinv.opt(y = y, kmax = kmax, q = q, first = 0, last = 1, penalty = "bic")
Arguments
y |
The input data points |
kmax |
The maximum number of change points |
q |
0 or 1. Correspond to a piecewise constant or piecewise linear trend |
first |
The value ranges from 0 to 1. Represent the minimum percentile point where a change point may occur. If 'first' = 0.01, it means that change points cannot appear in the first 1% of the data points. If 'first' = 0, there is no constraint on the position of the change point. |
last |
The value ranges from 0 to 1. Represent the maximum percentile point where a change point may occur. If 'last' = 0.99, it means that change points cannot appear in the last 1% of the data points. If 'last' = 1, there is no constraint on the position of the change point. |
penalty |
'sic' or 'bic' penalty |
Details
Let the fitted trend be denoted as \hat{\boldsymbol{y}}
, then
\text{sic} = n \times \log(\frac{1}{n}\|\boldsymbol{y}-\hat{\boldsymbol{y}}\|_2^2)+2\log(\log(n)) \times \log(n) \times \text{df}(\hat{\boldsymbol{y}})
and
\text{bic} = n \times \log(\frac{1}{n}\|\boldsymbol{y}-\hat{\boldsymbol{y}}\|_2^2)+2\times \log(n) \times \text{df}(\hat{\boldsymbol{y}}).
The term \text{df}(\hat{\boldsymbol{y}})
represents the degrees of freedom for the estimated trend, where \text{df}(\hat{\boldsymbol{y}})=k+q+1
. Here, k
refers to the number of change points in the estimated trend.
Value
An S3 object of type "L0TFinvopt". A list containing the fitted trend results:
sic |
Information criterion value with a penalty term of |
bic |
Information criterion value with a penalty term of |
mse |
The mean square error between the fitted trend and the input data |
y |
The input data points |
betaopt |
The fitted |
yopt |
The fitted trend with optimal change points |
Aopt |
The set of position indicators of the fitted change points with optimal change points |
kopt |
Optimal number of change points |
beta.all |
A data frame with dimensions |
y.all |
A data frame with dimensions |
A.all |
A list of length |
Examples
tau = c(0.1, 0.3, 0.4, 0.7, 0.85)
h = c(-1, 5, 3, 0, -1, 2)
BlocksData <- SimuBlocksInv(n = 500, sigma = 0.2, seed = 50, tau = tau ,h = h)
res <- L0TFinv.opt(y=BlocksData$y, kmax=20, q=0, first=0.01, last=1, penalty="bic")
print(res$Aopt)
print(BlocksData$setA)
plot(BlocksData$x, BlocksData$y, xlab="", ylab="")
lines(BlocksData$x, BlocksData$y0, col = "red")
lines(BlocksData$x, res$yopt, col = "lightgreen")
tau1 = c(0.4, 0.6, 0.7)
h1 = c(-3, 5, -4, 6)
a0 = -10
WaveData <- SimuWaveInv(n = 500, sigma = 0.1, seed = 50, tau = tau1, h = h1, a0 = a0)
res1 <- L0TFinv.opt(y=WaveData$y, kmax=10, q=1, first=0, last=0.99, penalty="sic")
print(res1$Aopt)
print(WaveData$setA)
plot(WaveData$x, WaveData$y, xlab="", ylab="")
lines(WaveData$x, WaveData$y0, col = "red")
lines(WaveData$x, res1$yopt, col = "lightgreen")