Skip to contents

By "design function" we a function building a "design matrix" X with its columns being functions \(X_i(t)\) where \(t\) is the time (actually a date). Each row of the matrix corresponds to a value of the time. It is assumed that the time is the first formal argument of the function. The name of this argument is arbitrary. This allows to use design functions with different names fot the 1-st argument such as "t", "date", "Date", ...

Usage

designVars(designList, dt, trace = 0, dropDup = "Cst")

Arguments

designList

A list with a specific structure describing the design functions to evaluate, and the arguments (except the date) to use. Each element of the list is itself a list with the two elements named what and args as do.call. The element what contains the name of the design function and the element args contains the named list of values for the arguments of what, with the first argument omitted.

dt

A "date" vector on which the design functions will be evaluated. This should be an object with class "Date" or an object that will be coerced to this class e.g. a character vector with a suitable format.

trace

Integer level of verbosity

dropDup

Character giving the names of variables that must be dropped when they are duplicated across designs.

Value

A data frame with length(dt) rows containing the new variables.

Details

Any design function used should fulfill the following requirements.

  1. The first argument must be the date. The name of this argument will not be used in the call.

  2. The returned value should be an object inheriting from the "matrix" class with suitable column names. For compatibility reasons, it can also be a list containing the design matrix as its element named "X".

The call to a design function should mention Date as the first argument. This call refers to the dailyMet object used, from which the Date column will be used.

Note

The naming of the elements of the list given in designList is arbitrary and does not impact the result. The names can be used to make code clearer.

Caution

When several designs are used, some conflit may arise because some names in the design matrices are identical. Unless the corresponding names are in dropDup, the latest variable will be automatically renamed as in data.frame. For instance if two variables "t1" then the second one will be renamed "t1.1", see Examples. This is a possible source of confusion, and good options could be either to drop this variable or to wrap the design function into another function which uses different column names.

Examples


if (require(NSGEV)) {
  desList <-
      list("sinAndCos" = list(what = "tsDesign",
                              args = list(type = "trigo", df = 7)),
           "polys" = list(what = "tsDesign",
                          args = list(type = "polynom", df = 3)),
           "breaks" = list(what = "NSGEV::breaksX",
                           args = list(breaks = c("1970-01-01", "1990-01-01"))))

  des1 <- designVars(desList, dt = c("2021-01-01", "2021-01-02"), trace = 1)
  des2 <- designVars(desList, dt = Rennes$Date, trace = 1)
  des1
  head(des2)
}
#>    o evaluation of `tsDesign`. Date is added in 1-st arg `dt`
#>    o evaluation of `tsDesign`. Date is added in 1-st arg `dt`
#>    o evaluation of `NSGEV::breaksX`. Date is added in 1-st arg `date`
#>    o evaluation of `tsDesign`. Date is added in 1-st arg `dt`
#>    o evaluation of `tsDesign`. Date is added in 1-st arg `dt`
#>    o evaluation of `NSGEV::breaksX`. Date is added in 1-st arg `date`
#>            Cst     cosj1      sinj1     cosj2      sinj2     cosj3     sinj3
#> 1945-01-02   1 0.9994082 0.03439806 0.9976335 0.06875541 0.9946781 0.1030314
#> 1945-01-03   1 0.9986686 0.05158437 0.9946781 0.10303138 0.9880390 0.1542040
#> 1945-01-04   1 0.9976335 0.06875541 0.9905454 0.13718540 0.9787691 0.2049661
#> 1945-01-05   1 0.9963032 0.08590610 0.9852403 0.17117706 0.9668929 0.2551824
#> 1945-01-06   1 0.9946781 0.10303138 0.9787691 0.20496611 0.9524422 0.3047192
#> 1945-01-07   1 0.9927586 0.12012617 0.9711394 0.23851258 0.9354554 0.3534447
#>                   t1       t2      t1.1 t1_1970 t1_1990
#> 1945-01-02 -38.82957 1507.735 -24.99658       0       0
#> 1945-01-03 -38.82683 1507.523 -24.99384       0       0
#> 1945-01-04 -38.82409 1507.310 -24.99110       0       0
#> 1945-01-05 -38.82136 1507.098 -24.98836       0       0
#> 1945-01-06 -38.81862 1506.885 -24.98563       0       0
#> 1945-01-07 -38.81588 1506.673 -24.98289       0       0