Calculates the (sliding) maxima of all blocks of b contiguous values
and all sets of the maxima of disjoint blocks of b contiguous values
in the vector x. This provides the first step of computations in
spm.
Usage
all_max_rcpp(x, b = 1, which_dj = c("all", "first", "last"), ...)Arguments
- x
A numeric vector of raw observations.
- b
A numeric scalar. The block size.
- which_dj
A character scalar. Determines Which sets of disjoint maxima are calculated:
"all", all sets;"first", only the set whose first block starts on the first observation inx;"last", only the set whose last block end on the last observation inx.- ...
Further arguments to be passed to
roll_max.
Value
A list containing
ysa numeric vector containing one set of sliding block maxima.
xsa numeric vector containing the values that contribute to
ys, that is, the whole input vectorx.ydif
which_dj = "all"afloor(n / b)byn - floor(n / b) * b + 1numeric matrix. Each column contains a set of disjoint maxima. Otherwise, afloor(n / b)by 1 numeric matrix containing one set of block maxima.xdif
which_dj = "all"afloor(n / b) * bbyn - floor(n / b) * b + 1numeric matrix. Each column contains the values inxthat contribute to the corresponding column inyd. Otherwise, afloor(n / b)by 1 numeric matrix containing one the one set of the values inxthat contribute toyd.
Details
Sliding maxima. The function
roll_max in the RcppRoll
package is used.
Disjoint maxima. If n = length(x) is an integer
multiple of b, or if which_dj = "first" or
which_dj = "last" then only one set of n / b disjoint
block maxima are returned.
Otherwise, n - floor(n / b) * b + 1 sets of floor(n / b)
disjoint block maxima are returned. Set i are the disjoint maxima
of x[i:(i + floor(n / b) * b - 1)]. That is, all possible sets
of contiguous disjoint maxima achieving the maxima length of
floor(n / b) are calculated.
In both instances na.rm = TRUE is passed to max so
that blocks containing missing values produce a non-missing result.
Also returned are the values in x that contribute to each set
of block maxima.
See also
spm for semiparametric estimation of the
extremal index based on block maxima.
Examples
x <- 1:11
all_max_rcpp(x, 3)
#> $ys
#> [1] 3 4 5 6 7 8 9 10 11
#>
#> $xs
#> [1] 1 2 3 4 5 6 7 8 9 10 11
#>
#> $yd
#> [,1] [,2] [,3]
#> [1,] 3 4 5
#> [2,] 6 7 8
#> [3,] 9 10 11
#>
#> $xd
#> [,1] [,2] [,3]
#> [1,] 1 2 3
#> [2,] 2 3 4
#> [3,] 3 4 5
#> [4,] 4 5 6
#> [5,] 5 6 7
#> [6,] 6 7 8
#> [7,] 7 8 9
#> [8,] 8 9 10
#> [9,] 9 10 11
#>
all_max_rcpp(x, 3, which_dj = "first")
#> $ys
#> [1] 3 4 5 6 7 8 9 10 11
#>
#> $xs
#> [1] 1 2 3 4 5 6 7 8 9 10 11
#>
#> $yd
#> [,1]
#> [1,] 3
#> [2,] 6
#> [3,] 9
#>
#> $xd
#> [,1]
#> [1,] 1
#> [2,] 2
#> [3,] 3
#> [4,] 4
#> [5,] 5
#> [6,] 6
#> [7,] 7
#> [8,] 8
#> [9,] 9
#>
all_max_rcpp(x, 3, which_dj = "last")
#> $ys
#> [1] 3 4 5 6 7 8 9 10 11
#>
#> $xs
#> [1] 1 2 3 4 5 6 7 8 9 10 11
#>
#> $yd
#> [,1]
#> [1,] 5
#> [2,] 8
#> [3,] 11
#>
#> $xd
#> [,1]
#> [1,] 3
#> [2,] 4
#> [3,] 5
#> [4,] 6
#> [5,] 7
#> [6,] 8
#> [7,] 9
#> [8,] 10
#> [9,] 11
#>