Skip to contents

Add the estimated fitted values back to the original

Usage

add_to_original_data(
  clean_data,
  isat_object,
  dep_var_basename = "imports_of_goods_and_services",
  ardl_or_ecm = "ardl"
)

Arguments

clean_data

An input data.frame or tibble. Must be the output of clean_data() to fit all requirements.

isat_object

An object of class 'isat'. Most likely should be the 'best_model' element that is returned by the 'estimate_module()' function.

dep_var_basename

A character string of the name of the dependent variable as contained in clean_data() in a level form (i.e. no ln or D in front of the name).

ardl_or_ecm

Either 'ardl' or 'ecm' to determine whether to estimate the model as an Autoregressive Distributed Lag Function (ardl) or as an Equilibrium Correction Model (ecm).

Value

A tibble with the fitted values as one column.

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)
)
sample_data_clean <- aggregate.model:::clean_data(sample_data, max.ar = 4, max.dl = 4)
estimation <- aggregate.model:::estimate_module(sample_data_clean, "yvar", "xvar")
aggregate.model:::add_to_original_data(
  sample_data_clean, estimation$best_model,
  dep_var_basename = "yvar")
#> # A tibble: 366 × 30
#>    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.6 100.     4.59    4.61  NA       NA       
#>  2     2 2000-01-02     2  97.6 100.     4.58    4.61  -0.0106  -0.00261 
#>  3     3 2000-01-03     3 101.  101.     4.61    4.62   0.0309   0.0115  
#>  4     4 2000-01-04     4  98.2  99.8    4.59    4.60  -0.0246  -0.0139  
#>  5     5 2000-01-05     5  99.8  99.7    4.60    4.60   0.0159  -0.000355
#>  6     6 2000-01-06     6  99.4 101.     4.60    4.61  -0.00311  0.00910 
#>  7     7 2000-01-07     7 102.   98.4    4.63    4.59   0.0260  -0.0227  
#>  8     8 2000-01-08     8 101.   98.1    4.61    4.59  -0.0153  -0.00236 
#>  9     9 2000-01-09     9  99.5  99.9    4.60    4.60  -0.0103   0.0183  
#> 10    10 2000-01-10    10 101.   99.1    4.61    4.60   0.0106  -0.00866 
#> # ℹ 356 more rows
#> # ℹ 21 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>,
#> #   yvar.hat <dbl>, yvar.level.hat <dbl>