Skip to contents

Calculate corresponding weight to return period

Usage

calculate_weight(x, margin = 1, type = c("period", "frequency"))

Arguments

x

vector or array of period.

margin

integer, the margins to be used in case x is an array.

type

character, define if x should be considered as return periods or frequencies.

Value

vector or array of corresponding weight.

Author

Frédéric Grelot, frederic.grelot.1994_cran@m4x.org

Examples

 
x1 = c(4, 10, 30, 100, 1000)
names(x1) = c("min", "small", "medium", "large", "max")
calculate_weight(x1)
#>        min      small     medium      large        max 
#> 0.07500000 0.10833333 0.04500000 0.01616667 0.00450000 
x2 = c(10, 15, 50, 100, 1500)
calculate_weight(cbind(x2), margin = 2)
#>               x2
#> [1,] 0.016666667
#> [2,] 0.040000000
#> [3,] 0.028333333
#> [4,] 0.009666667
#> [5,] 0.004666667
y1 = cbind(x1, x2)
calculate_weight(y1, 2)
#>                x1          x2
#> min    0.07500000 0.016666667
#> small  0.10833333 0.040000000
#> medium 0.04500000 0.028333333
#> large  0.01616667 0.009666667
#> max    0.00450000 0.004666667
y2 = apply(y1, 2, sample, 5)
calculate_weight(y2, 2)
#>              x1          x2
#> [1,] 0.01616667 0.004666667
#> [2,] 0.10833333 0.040000000
#> [3,] 0.07500000 0.009666667
#> [4,] 0.04500000 0.016666667
#> [5,] 0.00450000 0.028333333
y3 = y1 * rep(2:3, each = 5)
if (FALSE) z = abind::abind(y1, y2, along = 3, make.names = TRUE) # \dontrun{}
z = array(cbind(y1, y3), dim = c(dim(y1), 2), dimnames = c(dimnames(y1), list(c("y1", "y3"))))
calculate_weight(z, 2:3)
#> , , y1
#> 
#>                x1          x2
#> min    0.07500000 0.016666667
#> small  0.10833333 0.040000000
#> medium 0.04500000 0.028333333
#> large  0.01616667 0.009666667
#> max    0.00450000 0.004666667
#> 
#> , , y3
#> 
#>                 x1          x2
#> min    0.037500000 0.005555556
#> small  0.054166667 0.013333333
#> medium 0.022500000 0.009444444
#> large  0.008083333 0.003222222
#> max    0.002250000 0.001555556
#>