convertSingleParam {crossvalidationCP}R Documentation

Provides estimators that allows list of parameters

Description

Converts estimators allowing single parameters to estimators allowing a list of parameters. The resulting function can be passed to the argument estimator in the cross-validation functions, see See Also.

Usage

convertSingleParam(estimator)

Arguments

estimator

the function to be converted, i.e. a function providing a local estimate. The function must have the arguments Y, param and ..., where Y will be the observations, and param a single parameter of arbitrary type. Hence lists can be used when multiple parameter of different types are needed. It has to return either a vector with the estimated change-points or a list containing the named entries cps and value. In this case cps has to be a numeric vector with the estimated change-points as before and value has to be a list of length one entry longer than cps giving the locally estimated values. An example is given below.

Value

a function that can be passed to the argument estimator in the cross-validation functions, see the functions listed in See Also

References

Pein, F., and Shah, R. D. (2021) Cross-validation for change-point regression: pitfalls and solutions. arXiv:2112.03220.

See Also

crossvalidationCP, VfoldCV, COPPS, CV1, CVmod

Examples

# wrapper around pelt to demonstrate an estimator that allows a single parameter only
singleParamEstimator <- function(Y, param, minseglen = 1, ...) {
  if (is.numeric(param)) {
    ret <- changepoint::cpt.mean(data = Y, penalty = "Manual", pen.value = param, method = "PELT",
                                 minseglen = minseglen)
  } else {
    ret <- changepoint::cpt.mean(data = Y, penalty = param, method = "PELT", minseglen = minseglen)
  }
  
  list(cps = ret@cpts[-length(ret@cpts)], value = as.list(ret@param.est$mean))
}
# conversion to an estimator that is suitable for crossvalidationCP() etc.
estimatorMultiParam <- convertSingleParam(singleParamEstimator)
crossvalidationCP(rnorm(100), estimator = estimatorMultiParam, param = list("SIC", "MBIC"))

[Package crossvalidationCP version 1.1 Index]