GithubHelp home page GithubHelp logo

timemachine's People

Contributors

christophsax avatar

Stargazers

 avatar

Watchers

 avatar  avatar

timemachine's Issues

Generate pseudo_history vintages for 100s of series

I have a dataset with 100s of time series, now I would like to generate a pseudo realtime data set with pseudo_history().

For each series I know its publication lag:

series_name pub_lag
adp employment change 3
T5YIE 0

How should I set up the command pseudo_history() for such a use case?

Programmatic series selection in timemachine

library(timemachine)
#> Loading required package: miniUI
library(forecast)
#> Registered S3 method overwritten by 'xts':
#>   method     from
#>   as.zoo.xts zoo
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
#> Registered S3 methods overwritten by 'forecast':
#>   method             from    
#>   fitted.fracdiff    fracdiff
#>   residuals.fracdiff fracdiff

dates = seq(
  from = as.Date("2017-07-01"),
  to = as.Date("2017-10-01"),
  by = "month"
)

mytimemachine <- function(idname) {
  idname <<- idname  # global assignement needed!
  timemachine(
    aa = {
      m <- forecast(auto.arima(get(idname)), h = 3)
      m$mean
    },
    history = swiss_history,
    dates = dates
  )
}

mytimemachine("GDP.CH")
#> 2017-07-01
#> Attached: GDP.CH, GC, PC, INV, INV.CONSTR, INV.EQ, EXP, IMP, DEFL, CPI.NSA, CPI.SA, I, RR, EMPL.NSA, EMPL.SA, RU.NSA, RU.SA, UR.NSA, UR.SA, GDP.F, GDP.US, GDP.EA, GDP.JP
#> 2017-08-01
#> Attached: GDP.CH, GC, PC, INV, INV.CONSTR, INV.EQ, EXP, IMP, DEFL, CPI.NSA, CPI.SA, I, RR, EMPL.NSA, EMPL.SA, RU.NSA, RU.SA, UR.NSA, UR.SA, GDP.F, GDP.US, GDP.EA, GDP.JP
#> 2017-09-01
#> Attached: GDP.CH, GC, PC, INV, INV.CONSTR, INV.EQ, EXP, IMP, DEFL, CPI.NSA, CPI.SA, I, RR, EMPL.NSA, EMPL.SA, RU.NSA, RU.SA, UR.NSA, UR.SA, GDP.F, GDP.US, GDP.EA, GDP.JP
#> 2017-10-01
#> Attached: GDP.CH, GC, PC, INV, INV.CONSTR, INV.EQ, EXP, IMP, DEFL, CPI.NSA, CPI.SA, I, RR, EMPL.NSA, EMPL.SA, RU.NSA, RU.SA, UR.NSA, UR.SA, GDP.F, GDP.US, GDP.EA, GDP.JP
#> # A tibble: 12 x 4
#>    expr  pub_date   ref_date     value
#>    <chr> <date>     <date>       <dbl>
#>  1 aa    2017-07-01 2017-07-01 168678.
#>  2 aa    2017-07-01 2017-10-01 169190.
#>  3 aa    2017-07-01 2018-01-01 169708.
#>  4 aa    2017-08-01 2017-07-01 168678.
#>  5 aa    2017-08-01 2017-10-01 169190.
#>  6 aa    2017-08-01 2018-01-01 169708.
#>  7 aa    2017-09-01 2017-07-01 168678.
#>  8 aa    2017-09-01 2017-10-01 169190.
#>  9 aa    2017-09-01 2018-01-01 169708.
#> 10 aa    2017-10-01 2017-10-01 170404.
#> 11 aa    2017-10-01 2018-01-01 171072.
#> 12 aa    2017-10-01 2018-04-01 171675.
mytimemachine("GC")
#> 2017-07-01
#> Attached: GDP.CH, GC, PC, INV, INV.CONSTR, INV.EQ, EXP, IMP, DEFL, CPI.NSA, CPI.SA, I, RR, EMPL.NSA, EMPL.SA, RU.NSA, RU.SA, UR.NSA, UR.SA, GDP.F, GDP.US, GDP.EA, GDP.JP
#> 2017-08-01
#> Attached: GDP.CH, GC, PC, INV, INV.CONSTR, INV.EQ, EXP, IMP, DEFL, CPI.NSA, CPI.SA, I, RR, EMPL.NSA, EMPL.SA, RU.NSA, RU.SA, UR.NSA, UR.SA, GDP.F, GDP.US, GDP.EA, GDP.JP
#> 2017-09-01
#> Attached: GDP.CH, GC, PC, INV, INV.CONSTR, INV.EQ, EXP, IMP, DEFL, CPI.NSA, CPI.SA, I, RR, EMPL.NSA, EMPL.SA, RU.NSA, RU.SA, UR.NSA, UR.SA, GDP.F, GDP.US, GDP.EA, GDP.JP
#> 2017-10-01
#> Attached: GDP.CH, GC, PC, INV, INV.CONSTR, INV.EQ, EXP, IMP, DEFL, CPI.NSA, CPI.SA, I, RR, EMPL.NSA, EMPL.SA, RU.NSA, RU.SA, UR.NSA, UR.SA, GDP.F, GDP.US, GDP.EA, GDP.JP
#> # A tibble: 12 x 4
#>    expr  pub_date   ref_date    value
#>    <chr> <date>     <date>      <dbl>
#>  1 aa    2017-07-01 2017-07-01 19928.
#>  2 aa    2017-07-01 2017-10-01 19984.
#>  3 aa    2017-07-01 2018-01-01 20050.
#>  4 aa    2017-08-01 2017-07-01 19928.
#>  5 aa    2017-08-01 2017-10-01 19984.
#>  6 aa    2017-08-01 2018-01-01 20050.
#>  7 aa    2017-09-01 2017-07-01 19928.
#>  8 aa    2017-09-01 2017-10-01 19984.
#>  9 aa    2017-09-01 2018-01-01 20050.
#> 10 aa    2017-10-01 2017-10-01 20006.
#> 11 aa    2017-10-01 2018-01-01 20077.
#> 12 aa    2017-10-01 2018-04-01 20147.

Created on 2019-08-20 by the reprex package (v0.3.0)

Forecast horizon adjustment in evaluation of results

Wie kann den Forecast Horizon h so setzen, dass es nicht die Quartale als Referenz nimmt, also von 1 bis 9, sondern die Monate, sprich von 1 bis 27? Der Code unten macht sehr schön die Quartale.

results <- structure(list(expr = c("bdg1", "bdg1", "bdg1", "bdg1", "bdg1", 
"bdg1", "bdg1", "bdg1", "bdg1", "bdg1", "bdg1", "bdg1", "bdg1", 
"bdg1", "bdg1", "bdg1", "bdg1", "bdg1", "bdg1", "bdg1", "bdg1", 
"bdg1", "bdg1", "bdg1", "bdg1", "bdg1", "bdg1"), pub_date = structure(c(14214, 
14245, 14276, 14304, 14335, 14365, 14396, 14426, 14457, 14488, 
14518, 14549, 14579, 14610, 14641, 14669, 14700, 14730, 14761, 
14791, 14822, 14853, 14883, 14914, 14944, 14975, 15006), class = "Date"), 
    ref_date = structure(c(14883, 14883, 14883, 14883, 14883, 
    14883, 14883, 14883, 14883, 14883, 14883, 14883, 14883, 14883, 
    14883, 14883, 14883, 14883, 14883, 14883, 14883, 14883, 14883, 
    14883, 14883, 14883, 14883), class = "Date"), value = c(-0.506681784942139, 
    -0.571015209472469, 0.142607140892838, -0.156631763687276, 
    -0.242282371579598, -0.129473293377144, 0.00508796161221747, 
    0.871150764454464, 0.86779210729246, 0.798360420519133, 0.793553987258127, 
    0.801069194315595, 0.792874354495371, 0.739087556088245, 
    0.760095102547694, 0.750505127575601, 1.10703202479419, 1.11619016768242, 
    1.17228081482969, 1.1391799835059, 1.24485315943325, 1.00193624512288, 
    1.08847534736896, 1.20249116401625, 1.04852976364214, 1.02529181687138, 
    1.02529181687138)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -27L), .Names = c("expr", "pub_date", "ref_date", 
"value"))

errors <-
  results %>%
  group_by(ref_date, pub_date, expr) %>%
  mutate(h = seq(n())) %>%
  ungroup() 

A tibble: 27 x 4
expr pub_date ref_date value

1 bdg1 2008-12-01 2010-10-01 -0.507
2 bdg1 2009-01-01 2010-10-01 -0.571
3 bdg1 2009-02-01 2010-10-01 0.143
4 bdg1 2009-03-01 2010-10-01 -0.157
5 bdg1 2009-04-01 2010-10-01 -0.242
6 bdg1 2009-05-01 2010-10-01 -0.129
7 bdg1 2009-06-01 2010-10-01 0.00509
8 bdg1 2009-07-01 2010-10-01 0.871
9 bdg1 2009-08-01 2010-10-01 0.868
10 bdg1 2009-09-01 2010-10-01 0.798
... with 17 more rows

hier sollte es dann also bei 27 beginnen und dann runterzählen. Any help kindly appreciated!

pseudo_history() on data_frame of monthly data

Frage 1: wie muss ich vorgehen um eine Vielzahl von Monatsindikatoren in die pseudo_history zu bringen?

Frage 2: ist es danach korrekt, diese neu generierte Tabelle mit der pseudo_history der target variable zu mergen via ts_c() und auf dieses neue Objekt options(timemachine.history = NEW_OBJECT) anzuwenden?

library("timemachine")
library("tsbox")

dta <- structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, 61.481006, 58.857049, 59.242728, 
57.394994, 56.780823, 56.132335, 53.96825, 53.177727, 53.78973, 
50.352191, 48.597276, 47.09809, 50.068857, 49.220064, 48.4233, 
44.834267, 40.356769, 45.781857, 47.261783, 46.636696, 47.281833, 
47.583723, 46.105661, 49.914601, 50.656413, 53.183586, 52.724529, 
53.893057, 54.83731, 55.900363, 60.681033, 56.959559, 57.116975, 
57.975628, 59.559429, 58.937327, 57.440081, 57.288777, 57.22586, 
57.72176, 56.765583, 54.697867, 55.700123, 54.786896, 50.699391, 
50.154701, 49.896231, 50.826276, 46.251106, 48.171144, 49.283641, 
51.222098, 51.942546, 52.731403, 55.522627, 55.47006, 58.808512, 
61.732733, 61.479249, 61.661505, 58.356902, 60.595626, 61.90567, 
63.762693, 63.815429, 64.088621, 60.153999, 61.997755, 62.549996, 
63.026796, 61.329778, 59.550411, 57.167653, 54.717035, 51.534965, 
46.904027, 47.620669, 47.366377, 44.222626, 43.292673, 44.667411, 
41.40868, 39.215695, 41.308652, 44.677088, 46.705239, 48.015919, 
48.748946, 50.130922, 49.504175, 49.383163, 46.527406, 46.074503, 
46.509469, 52.169285, 46.32808, 48.015995, 49.290532, 45.965258, 
45.822409, 43.219604, 43.698029, 48.541393, 51.280682, 52.157872, 
54.278471, 55.049091, 53.81716, 56.489512, 53.881038, 58.876912, 
58.569519, 57.889117, 57.621017, 54.845328, 55.234341, 56.015731, 
54.80292, 53.679822, 54.050851, 52.490971, 47.615934, 51.724028, 
51.200589, 52.37204, 51.94741, 51.783009, 50.676276, 58.523104, 
58.084198, 56.468492, 56.592854, 58.481711, 60.903702, 62.779868, 
63.472528, 63.804721, 63.864678, 64.480932, 65.853775, 65.779066, 
63.466652, 66.175509, 66.906063, 62.553569, 64.283554, 61.222021, 
61.794463, 59.876203, 62.87484, 62.485397, 62.886291, 59.406877, 
61.105834, 61.906172, 61.875533, 61.892313, 60.699477, 58.018542, 
55.777674, 55.330439, 54.630483, 52.377589, 51.676317, 48.909912, 
46.290755, 36.170746, 35.089496, 36.441261, 33.501931, 32.879724, 
35.420966, 39.561177, 41.910829, 43.590895, 49.386207, 54.959863, 
54.959504, 55.592536, 54.771514, 56.957461, 57.426285, 63.71277, 
64.108108, 65.16279, 63.949701, 65.505551, 61.298826, 62.32585, 
62.145334, 62.678882, 60.625537, 60.505899, 62.040462, 58.457601, 
57.996903, 57.753367, 53.866712, 52.168522, 52.038234, 50.588769, 
49.004712, 45.819341, 49.333427, 47.910997, 47.950096, 50.568051, 
46.709538, 45.890086, 47.724321, 46.682034, 46.816451, 45.605033, 
46.778456, 48.5428, 49.947659, 52.323094, 50.040567, 49.655981, 
48.972675, 52.415164, 51.684275, 55.21799, 55.52062, 56.806439, 
54.637304, 56.972046, 54.120359, 56.163625, 56.977715, 54.32479, 
54.86243, 53.770848, 54.076539, 53.399577, 54.073174, 51.565473, 
54.192213, 51.690495, 52.599805, 49.612651, 47.971448, 47.754378, 
47.873692, 47.845236, 49.789611, 49.590881, 51.287462, 48.088433, 
49.622844, 48.71384, 49.752088, 50.816714, 51.067484, 52.832851, 
52.982981, 56.279048, 51.108466, 50.875039, 51.698094, 54.519177, 
55.239914, 55.513878, 55.887999, 54.974043, 58.094389, 57.464562, 
58.335638, 55.719123, 59.980663, 60.279548, 61.412128, 62.177216, 
61.50319, 64.585728, 65.561556, 65.296017, 65.450934, 60.276087, 
63.620851, 62.415046, 61.580441, 61.930521, 64.814788, NaN, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, 99.501305, 100.248382, 100.078951, 94.186669, 
96.292492, 91.653911, 92.254047, 88.492059, 89.957219, 88.69435, 
86.673418, 86.94696, 90.879503, 89.245105, 89.656445, 96.228874, 
93.898861, 97.650219, 98.828576, 101.612057, 101.997869, 101.230586, 
105.687884, 111.427507, 110.749815, 108.008646, 107.369113, 109.961889, 
107.615364, 108.36063, 112.317991, 112.040318, 112.34915, 114.397031, 
107.984066, 106.861048, 104.054958, 97.774113, 102.954049, 100.214249, 
104.162704, 98.027929, 97.826268, 96.634005, 96.181744, 93.022481, 
87.523834, 91.269186, 95.553449, 102.015698, 99.318494, 103.137761, 
102.689395, 103.374937, 107.234646, 108.178722, 110.76927, 114.094632, 
114.43496, 112.621698, 104.472523, 106.974185, 111.638104, 110.683348, 
108.17878, 111.77668, 105.124857, 102.201072, 102.097924, 102.852667, 
103.199146, 102.302014, 99.328182, 95.263555, 93.335938, 88.044439, 
83.434603, 87.332845, 90.542983, 94.122428, 91.891692, 83.917714, 
80.848436, 83.479795, 93.799296, 99.408233, 100.196253, 100.913541, 
105.632358, 101.652076, 95.776375, 95.999099, 93.719823, 94.702188, 
95.180696, 95.852128, 97.278011, 95.832943, 94.081202, 92.808528, 
95.810806, 96.295982, 101.979694, 102.741928, 104.441418, 111.922919, 
113.534041, 111.76951, 110.421103, 112.463349, 112.150355, 113.731978, 
111.227388, 109.8938, 107.910234, 107.536339, 106.052374, 101.115117, 
98.959026, 100.390357, 100.055504, 101.022068, 100.387432, 100.481601, 
101.818311, 103.339738, 103.34459, 101.674352, 103.779091, 107.83464, 
108.71202, 109.341725, 111.635017, 111.975905, 111.041064, 110.354663, 
108.732337, 106.884462, 106.973457, 107.090058, 108.87131, 108.20023, 
107.828296, 107.164468, 110.112013, 107.451683, 109.610297, 104.386831, 
103.004782, 103.33263, 105.106871, 104.211926, 101.646796, 97.961011, 
101.164349, 101.056704, 97.462079, 94.811914, 92.185058, 83.332929, 
85.383903, 83.683249, 81.917405, 81.3495, 81.771502, 80.038802, 
71.377957, 67.772135, 70.780808, 74.866347, 76.314171, 88.689248, 
97.842247, 107.227517, 111.916082, 115.742203, 117.615547, 118.853487, 
121.427066, 117.695849, 112.026158, 116.307885, 113.94133, 117.427694, 
116.597738, 111.231593, 109.819555, 109.607432, 109.27713, 103.82075, 
106.181738, 107.781631, 102.174211, 101.750021, 103.25056, 103.254782, 
99.105551, 98.105074, 89.072696, 85.124292, 82.877088, 84.248012, 
87.987261, 92.519579, 99.417577, 101.121926, 103.288251, 102.043409, 
97.338767, 95.416932, 98.204944, 100.976193, 100.857232, 101.675736, 
101.748545, 101.583094, 105.787254, 106.223878, 104.887749, 101.617687, 
100.307647, 101.420607, 106.181387, 106.341568, 108.13514, 107.287109, 
108.888897, 105.594897, 106.019028, 106.357739, 104.693886, 104.197591, 
100.753477, 99.991623, 98.01718, 100.365854, 97.206255, 99.69125, 
97.559906, 98.024285, 95.511774, 86.479443, 88.911985, 89.079421, 
103.234515, 98.576245, 100.911628, 100.652339, 100.606693, 101.97321, 
99.127473, 98.105399, 101.766192, 103.002255, 101.987832, 103.612223, 
102.051776, 102.08772, 101.075767, 100.221771, 100.969933, 102.71923, 
102.416446, 103.089981, 102.742355, 108.16279, 108.147366, 107.468454, 
103.863916, 105.32695, 107.434802, 104.427945, 106.144063, 109.245349, 
110.286943, 111.437629, 107.517935, 108.255689, 105.037057, 103.293145, 
100.013446, 101.256753, 101.68433, 100.302153, NaN, NA, NA, NA
), .Dim = c(468L, 2L), .Dimnames = list(NULL, c("pmi.ind_tot", 
"kofbaro")), .Tsp = c(1980, 2018.91666666667, 12), class = c("mts", 
"ts", "matrix"))

# does not work
pseudo_history(dta, "1 month") 

# does not work
dta %>%
  ts_tbl() %>% 
  group_by(id) %>% 
  pseudo_history("1 month")

# does not yield pseudo real-time dataset
indic.pseudo_rt <- dta %>% 
  ts_tbl() %>% 
  rename(ref_date = "time") %>%
  rename(var = "id") %>% 
  mutate(pub_date = add_to_date(ref_date, "1 month")) %>% 
  select(pub_date, ref_date, var, value)

timemachine installation

Ich habe bereits Pakete deinstalliert (miniUI und timemachine), RStudio neu gestartet, die Pakets nochmal installiert, aber es funktioniert immer nicht.

√  checking for file 'C:\Users\David\AppData\Local\Temp\RtmpmwbsmJ\remotes1db465d3324\christophsax-timemachine-b5eb705/DESCRIPTION' (472ms)
-  preparing 'timemachine':
√  checking DESCRIPTION meta-information ... 
-  checking for LF line-endings in source and make files and shell scripts
-  checking for empty or unneeded directories
-  building 'timemachine_0.0.3.tar.gz'
   
Installing package into ‘C:/Users/David/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
* installing *source* package 'timemachine' ...
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
Error: (converted from warning) package 'miniUI' was built under R version 4.0.5
Execution halted
ERROR: lazy loading failed for package 'timemachine'
* removing 'C:/Users/David/Documents/R/win-library/4.0/timemachine'
Error: Failed to install 'timemachine' from GitHub:
  (converted from warning) installation of package ‘C:/Users/David/AppData/Local/Temp/RtmpmwbsmJ/file1db42e9090c/timemachine_0.0.3.tar.gz’ had non-zero exit status

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.