getOTevents: Define over-threshold events

View source: R/TimeSeries.R

getOTeventsR Documentation

Define over-threshold events

Description

Definition of over-threshold events, i.e continuous runs of over-threshold values, with successive runs being potentially merged according to some independence constraints. NA's are treated as below-threshold values

Usage

getOTevents(x, threshold, minIEduration = 0, IEminval = threshold)

Arguments

x

numeric vector, values.

threshold

numeric, threshold value.

minIEduration

numeric, minimum inter-event duration: two runs separated by less than minIEduration steps are merged.

IEminval

numeric, minimum inter-event value: if the series does not go below IEminval between two events, they are merged.

Value

An integer vector with same size as x, containing the index of over-threshold events (and 0 for values below the threshold).

Examples

x <- as.numeric(arima.sim(n=365,list(ar=c(0.9))))
# No independence constraint
events <- getOTevents(x=x,threshold=2)
plot(x,type='l',col='gray')
for(i in 1:max(events)){foo=x;foo[events!=i]=NA;points(foo,col=i,pch=19)}
# At least 5 time steps between events
events <- getOTevents(x=x,threshold=2,minIEduration=5)
plot(x,type='l',col='gray')
for(i in 1:max(events)){foo=x;foo[events!=i]=NA;points(foo,col=i,pch=19)}
# At least 5 time steps between events and values go back below 0
events <- getOTevents(x=x,threshold=2,minIEduration=5,IEminval=0)
plot(x,type='l',col='gray')
for(i in 1:max(events)){foo=x;foo[events!=i]=NA;points(foo,col=i,pch=19)}

benRenard/BFunk documentation built on July 20, 2022, 7:07 a.m.