powered by
Estimate the variance (using the sum of squared errors) with an estimator that is consistent when the mean changes at a known point.
cpt_consistent_var(x, k)
A numeric vector for the data set
The potential change point at which the data set is split
The estimated change-consistent variance
This is the estimator
$$\hat{\sigma}^2_{T,t} = T^{-1}\left(\sum_{s = 1}^t \left(X_s - \bar{X}_t\right)^2 + \sum_{s = t + 1}^{T}\left(X_s - \tilde{X}_{T - t} \right)^2\right)$$
where \(\bar{X}_t = t^{-1}\sum_{s = 1}^t X_s\) and \(\tilde{X}_{T - t} = (T - t)^{-1} \sum_{s = t + 1}^{T} X_s\). In this implementation, \(T\) is computed automatically as length(x) and k corresponds to \(t\), a potential change point.
length(x)
k
# NOT RUN { CPAT:::cpt_consistent_var(c(rnorm(500, mean = 0), rnorm(500, mean = 1)), k = 500) # }
Run the code above in your browser using DataLab