eventseq {hydromad} | R Documentation |
Identify discrete events from time series and apply functions to them.
eventseq(x, thresh = 0, mingap = 1, mindur = 1, extend = 0, inthresh = thresh, inx = x, indur = 1, below = FALSE, all = FALSE, continue = FALSE, n = NA) eventapply(X, events, FUN = sum, ..., by.column = TRUE, simplify = TRUE, TIMING = c("start", "middle", "end")) eventinfo(X, events, FUN = mean, ...)
x, X |
a |
thresh |
threshold value: the data must be strictly above this level (or, if
|
mingap |
the minimum number of time steps that can separate events. Any inter-event durations shorter than this will be subsumed into the surrounding event. |
mindur |
the minimum number of time steps in each event window. Any events whose duration is shorter than this will be skipped. |
extend |
a number of time steps to include on the end of each event window,
before accounting for |
inthresh |
|
inx |
optionally, a different series may be given to determine event
termination with |
indur |
the series must remain below |
below |
reverses the definition of events, to identify events where the data
falls below |
all |
to include the periods between events as additional levels (i.e. as
events in themselves). These inter-events will be assigned negative
levels, while the actual events will have positive levels. Otherwise
– in the default case – these inter-event periods are left as
|
continue |
set |
n |
number of events to be identified: if this is given (and > 0),
then a value of |
events |
a |
FUN, ..., by.column |
a function to apply to the values in each event. In the default case
of |
simplify |
if |
TIMING |
defines how to construct the time index of the result. Should the
time corresponding to an event be taken from the |
eventseq
returns a zoo object, with core data consisting of an
ordered factor
, representing the identified events, and
the same time index as x
. Periods between events are left as
NA
, unless all = TRUE
in which case they are treated as
separate events. The returned object stores thresh
as an
attribute.
eventapply
returns a zoo
object (an irregular time
series in this case), with the value returned from FUN
applied to each discrete event in X
.
eventinfo
returns a data.frame
with columns
Time
time that the event started (from time(X)
).
Month, Year
month and year (as integers) of the mid-point of the event.
Value
result of FUN
applied to the event.
Duration
length of the event in time steps / data points.
PreDuration
number of time steps since the last event ended.
Felix Andrews felix@nfrac.org
cut.Date
,
tapply
,
rollapply
,
aggregate.zoo
,
panel.xblocks
,
clusters
in the evd package.
data(Queanbeyan) ## wet period x <- window(Queanbeyan, start = "1974-01-01", end = "1976-12-01") evp <- eventseq(x$P, thresh = 5, inthresh = 1, indur = 4, continue = TRUE) evq <- eventseq(x$Q, thresh = 2, indur = 4, mingap = 5) nlevels(evp) ## number of events nlevels(evq) str(evq) table(coredata(evq)) eventapply(x$Q, evq, FUN = sum) eventapply(x, evq, FUN = mean) eventinfo(x$Q, evq) evplot <- xyplot(x) + layer_(panel.xblocks(evp, col = c("grey90", "grey80"), border = "grey80")) + layer(panel.xblocks(evq, block.y = 0, vjust = 1, col = 1)) evplot update(evplot, type = "s", xlim = as.Date(c("1990-07-01", "1990-08-31"))) + layer(panel.abline(h = c(5,1), lty = 2), packets = 1) ## example of requesting a threshold giving about 'n' events set.seed(0) ee <- eventseq(rnorm(100), n = 10, mingap = 2) nlevels(ee) attr(ee, "thresh") ## ## example of classifying events based on hydro properties ## data(Queanbeyan) x <- window(Queanbeyan, start = "1974-01-01", end = "1976-12-01") e <- eventseq(x$P, thresh = 5, inthresh = 1, indur = 4, continue = TRUE) ## classify events based on max flow qclass <- cut(ave(coredata(x$Q), coredata(e), FUN = max), c(0, 0.5, 1, Inf)) qclass <- zoo(qclass, time(x)) ## Classify events based on antecedent flow x <- merge(x, Q1 = lag(x$Q, -1), all = c(TRUE, FALSE)) head1 <- function(z) z[1] q1class <- cut(ave(coredata(x$Q1), coredata(e), FUN = head1), c(0, 0.2, 0.3, Inf)) q1class <- zoo(q1class, time(x)) ## combined classification combin <- factor(paste("M", unclass(qclass), "_A", unclass(q1class), sep ="")) combin <- zoo(combin, time(x)) ## check results head(data.frame(x, event = unclass(e), qclass, q1class, combin), 50) ## number of events in each class each.e <- !duplicated(e) table(coredata(combin[each.e]))