Prepare the clean dataframe for modelling
clean_data.Rd
Prepare the clean dataframe for modelling
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.
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)
)
osem:::clean_data(sample_data, max.ar = 4, max.dl = 4)
#> # A tibble: 366 × 46
#> index time trend yvar xvar ln.yvar ln.xvar D.yvar D.xvar D.ln.yvar
#> <int> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 2000-01-01 1 98.4 101. 4.59 4.61 NA NA NA
#> 2 2 2000-01-02 2 102. 101. 4.62 4.61 3.39 0.0845 0.0339
#> 3 3 2000-01-03 3 101. 100. 4.62 4.61 -0.738 -0.471 -0.00728
#> 4 4 2000-01-04 4 98.9 98.9 4.59 4.59 -2.09 -1.27 -0.0210
#> 5 5 2000-01-05 5 99.5 99.3 4.60 4.60 0.548 0.462 0.00553
#> 6 6 2000-01-06 6 99.8 102. 4.60 4.62 0.327 2.37 0.00328
#> 7 7 2000-01-07 7 99.0 99.8 4.59 4.60 -0.831 -1.84 -0.00837
#> 8 8 2000-01-08 8 100. 99.0 4.60 4.60 0.987 -0.798 0.00993
#> 9 9 2000-01-09 9 100. 100. 4.61 4.61 0.463 1.07 0.00462
#> 10 10 2000-01-10 10 100. 99.1 4.61 4.60 -0.352 -1.03 -0.00351
#> # ℹ 356 more rows
#> # ℹ 36 more variables: D.ln.xvar <dbl>, L1.yvar <dbl>, L1.xvar <dbl>,
#> # L1.ln.yvar <dbl>, L1.ln.xvar <dbl>, L1.D.yvar <dbl>, L1.D.xvar <dbl>,
#> # L1.D.ln.yvar <dbl>, L1.D.ln.xvar <dbl>, L2.yvar <dbl>, L2.xvar <dbl>,
#> # L2.ln.yvar <dbl>, L2.ln.xvar <dbl>, L2.D.yvar <dbl>, L2.D.xvar <dbl>,
#> # L2.D.ln.yvar <dbl>, L2.D.ln.xvar <dbl>, L3.yvar <dbl>, L3.xvar <dbl>,
#> # L3.ln.yvar <dbl>, L3.ln.xvar <dbl>, L3.D.yvar <dbl>, L3.D.xvar <dbl>, …