Skip to contents

Extracts block maxima and the number of non-missing observations per block.

Usage

block_maxima(data, block_length, block)

Arguments

data

A numeric vector containing a time series of raw data.

block_length

A numeric scalar. Used calculate the maxima of disjoint blocks of block_length contiguous values in the vector data. If length(data) is not an integer multiple of block_length then the values at the end of data that do not constitute a complete block of length block_length are discarded, without warning.

block

A numeric vector with the same length as data. The value of block[i] indicates the block into which data[i] falls. For example, block could provide the year in which observation i was observed.

Value

A list, with class c("list", "block_maxima", "evmissing"), containing the following numeric vectors:

  • maxima: the block maxima.

  • notNA: the numbers of non-missing observations in each block.

  • n: the maximal block length, that is, the largest number of values that could have been observed in each block.

If a block contains only missing values then its value of maxima is NA and its value of notNA is 0.

If block is supplied then these vectors are named using the values in block. Otherwise, these vectors do not have names.

Details

Exactly one of the arguments block_length or block must be supplied.

Examples

## Simulate example data
set.seed(7032025)
data <- rexp(15)

# Create some missing values
data[c(5, 7:8)] <- NA
# 5 blocks (columns), each with 3 observations
matrix(data, ncol = 5)
#>            [,1]      [,2]       [,3]       [,4]       [,5]
#> [1,] 0.05147985 0.7849467         NA 1.61767512 1.85907241
#> [2,] 0.17692329        NA         NA 0.08363226 0.40586358
#> [3,] 0.88829461 1.8383628 0.08814399 0.14537999 0.08440941
# Supplying block_length
block_length <- 3
block_maxima(data, block_length = block_length)
#> $maxima
#> [1] 0.88829461 1.83836285 0.08814399 1.61767512 1.85907241
#> 
#> $notNA
#> [1] 3 2 1 3 3
#> 
#> $n
#> [1] 3 3 3 3 3
#> 
#> attr(,"class")
#> [1] "list"         "block_maxima" "evmissing"   
# Supplying block
block <- rep(1:5, each = 3)
block_maxima(data, block = block)
#> $maxima
#>          1          2          3          4          5 
#> 0.88829461 1.83836285 0.08814399 1.61767512 1.85907241 
#> 
#> $notNA
#> 1 2 3 4 5 
#> 3 2 1 3 3 
#> 
#> $n
#> 1 2 3 4 5 
#> 3 3 3 3 3 
#> 
#> attr(,"class")
#> [1] "list"         "block_maxima" "evmissing"   

## Data with an incomplete block
data <- c(data, 1:2)

# Supplying block_length (the extra 2 observations are ignored)
block_length <- 3
block_maxima(data, block_length = block_length)
#> $maxima
#> [1] 0.88829461 1.83836285 0.08814399 1.61767512 1.85907241
#> 
#> $notNA
#> [1] 3 2 1 3 3
#> 
#> $n
#> [1] 3 3 3 3 3
#> 
#> attr(,"class")
#> [1] "list"         "block_maxima" "evmissing"   
# Supplying block (with an extra group indicator)
block <- c(block, 7, 7)
block_maxima(data, block = block)
#> $maxima
#>          1          2          3          4          5          7 
#> 0.88829461 1.83836285 0.08814399 1.61767512 1.85907241 2.00000000 
#> 
#> $notNA
#> 1 2 3 4 5 7 
#> 3 2 1 3 3 2 
#> 
#> $n
#> 1 2 3 4 5 7 
#> 3 3 3 3 3 2 
#> 
#> attr(,"class")
#> [1] "list"         "block_maxima" "evmissing"