resid: Calculate the residuals related to the estimated signal

View source: R/Finalised_coding.R

residR Documentation

Calculate the residuals related to the estimated signal

Description

This function returns a difference between x and the estimated signal with change-points at cpt. The input in the argument type_chg will indicate the type of changes in the signal.

Usage

resid(
  x,
  cpt,
  type_chg = c("mean", "slope"),
  type_res = c("raw", "standardised")
)

Arguments

x

A numeric vector containing the data.

cpt

A positive integer vector with the locations of the change-points. If missing, the ID function is called internally to detect any change-points that might be present in x.

type_chg

A character string, which defines the type of the detected change-points. If type_chg = ``mean'', then the change-points represent the locations of changes in the mean of a piecewise-constant signal. If type_chg = ``slope'', then the change-points represent the locations of changes in the slope of a piecewise-linear and continuous signal.

type_res

A choice of "raw" and "standardised" residuals.

Value

If type_res = "raw", the function returns the difference between the data and the estimated signal. If type_res = "standardised", then the function returns the difference between the data and the estimated signal, divided by the estimated standard deviation.

Author(s)

Andreas Anastasiou, anastasiou.andreas@ucy.ac.cy

Examples

single.cpt.pcm <- c(rep(4,1000),rep(0,1000))
single.cpt.pcm.noise <- single.cpt.pcm + rnorm(2000)
cpt_detect <- ID(single.cpt.pcm.noise, contrast = "mean")

residuals_cpt_raw <- resid(single.cpt.pcm.noise, cpt = cpt_detect$cpt, type_chg = "mean",
type_res = "raw")

residuals_cpt_stand. <- resid(single.cpt.pcm.noise, cpt = cpt_detect$cpt, type_chg = "mean",
type_res = "standardised")

plot(residuals_cpt_raw)
plot(residuals_cpt_stand.)

IDetect documentation built on May 7, 2026, 5:09 p.m.