Skip to contents

Prepare the clean dataframe for modelling

Usage

clean_data(raw_data, max.ar = 4, max.dl = 2, trend = TRUE)

Arguments

raw_data

A tibble or data.frame with the y variable and the x variables. Needs to have a column called 'time', which is of class Date. Variable names need to be in column 'na_item', and values in column 'values'.

max.ar

Integer. The maximum number of lags to use for the AR terms. as well as for the independent variables.

max.dl

Integer. The maximum number of lags to use for the independent variables (the distributed lags).

trend

Logical. Should a trend be added? Default is TRUE.

Value

A tibble with the cleaned data.

Examples

sample_data <- dplyr::tibble(
  time = rep(seq.Date(
    from = as.Date("2000-01-01"),
    to = as.Date("2000-12-31"), by = 1
  ), each = 2),
  na_item = rep(c("yvar", "xvar"), 366), values = rnorm(366 * 2, mean = 100)
)
aggregate.model:::clean_data(sample_data, max.ar = 4, max.dl = 4)
#> # A tibble: 366 × 28
#>    index time       trend  yvar  xvar ln.yvar ln.xvar D.ln.yvar D.ln.xvar
#>    <int> <date>     <dbl> <dbl> <dbl>   <dbl>   <dbl>     <dbl>     <dbl>
#>  1     1 2000-01-01     1  98.4 101.     4.59    4.61  NA       NA       
#>  2     2 2000-01-02     2 102.  101.     4.62    4.61   0.0339   0.000840
#>  3     3 2000-01-03     3 101.  100.     4.62    4.61  -0.00728 -0.00469 
#>  4     4 2000-01-04     4  98.9  98.9    4.59    4.59  -0.0210  -0.0127  
#>  5     5 2000-01-05     5  99.5  99.3    4.60    4.60   0.00553  0.00467 
#>  6     6 2000-01-06     6  99.8 102.     4.60    4.62   0.00328  0.0235  
#>  7     7 2000-01-07     7  99.0  99.8    4.59    4.60  -0.00837 -0.0183  
#>  8     8 2000-01-08     8 100.   99.0    4.60    4.60   0.00993 -0.00802 
#>  9     9 2000-01-09     9 100.  100.     4.61    4.61   0.00462  0.0107  
#> 10    10 2000-01-10    10 100.   99.1    4.61    4.60  -0.00351 -0.0104  
#> # ℹ 356 more rows
#> # ℹ 19 more variables: L1.D.ln.yvar <dbl>, L1.D.ln.xvar <dbl>,
#> #   L1.ln.yvar <dbl>, L1.ln.xvar <dbl>, L2.D.ln.yvar <dbl>, L2.D.ln.xvar <dbl>,
#> #   L2.ln.yvar <dbl>, L2.ln.xvar <dbl>, L3.D.ln.yvar <dbl>, L3.D.ln.xvar <dbl>,
#> #   L3.ln.yvar <dbl>, L3.ln.xvar <dbl>, L4.D.ln.yvar <dbl>, L4.D.ln.xvar <dbl>,
#> #   L4.ln.yvar <dbl>, L4.ln.xvar <dbl>, q_2 <int>, q_3 <int>, q_4 <int>