pkgdown/extra.css

Skip to contents

Serializes a nowcast() (or auto_nowcast()) result to a single .rds bundle that can be restored later with load_nowcast(). The RTMB autodiff tape is not saved (its external pointers cannot be serialized); instead the fitted parameters and the Laplace mode + precision are stored, which is all predict() needs. The input tbl_now and the model() specification are saved too, so the loaded object can also be re-fit.

Usage

save_nowcast(object, file)

Arguments

object

A nowcast_class from nowcast() or auto_nowcast().

file

Path to write (a single .rds file).

Value

file, invisibly.

See also

Examples

# \donttest{
if (requireNamespace("tbl.now", quietly = TRUE)) {
  library(tbl.now)
  data(denguedat)
  dn <- subset(denguedat, onset_week <= as.Date("1990-12-01") &
                          report_week <= as.Date("1990-12-01"))
  tn <- tbl_now(dn, event_date = onset_week, report_date = report_week,
                data_type = "linelist", verbose = FALSE)
  nc <- nowcast(tn, type = "one_stage", n_draws = 200)
  f  <- tempfile(fileext = ".rds")
  save_nowcast(nc, f)
  nc2 <- load_nowcast(f)
  predict(nc2, summary = TRUE)          # works without the original RTMB tape
}
#>  Added default temporal effects: 52-period seasonality (weekly data).
#>  To use your own effects, attach them to the <tbl_now> with
#>   `tbl.now::add_temporal_effects()` + `tbl.now::compute_temporal_effects()`
#>   before calling `nowcast()`.
#>  To disable, call `nowcast(..., temporal_effects = "none")`.
#>  Saved nowcast to /tmp/Rtmp1MjIz5/file1bb05811d43f.rds.
#>  Restore with `load_nowcast("/tmp/Rtmp1MjIz5/file1bb05811d43f.rds")`.
#>       mean median          sd     mad    q2.5     q5   q10 q25   q50   q75
#> 1   61.000   61.0  0.00000000  0.0000  61.000  61.00  61.0  61  61.0  61.0
#> 2   50.000   50.0  0.00000000  0.0000  50.000  50.00  50.0  50  50.0  50.0
#> 3   44.000   44.0  0.00000000  0.0000  44.000  44.00  44.0  44  44.0  44.0
#> 4   46.000   46.0  0.00000000  0.0000  46.000  46.00  46.0  46  46.0  46.0
#> 5   39.000   39.0  0.00000000  0.0000  39.000  39.00  39.0  39  39.0  39.0
#> 6   34.000   34.0  0.00000000  0.0000  34.000  34.00  34.0  34  34.0  34.0
#> 7   24.000   24.0  0.00000000  0.0000  24.000  24.00  24.0  24  24.0  24.0
#> 8   17.000   17.0  0.00000000  0.0000  17.000  17.00  17.0  17  17.0  17.0
#> 9   17.000   17.0  0.00000000  0.0000  17.000  17.00  17.0  17  17.0  17.0
#> 10  16.000   16.0  0.00000000  0.0000  16.000  16.00  16.0  16  16.0  16.0
#> 11  17.000   17.0  0.00000000  0.0000  17.000  17.00  17.0  17  17.0  17.0
#> 12  22.000   22.0  0.00000000  0.0000  22.000  22.00  22.0  22  22.0  22.0
#> 13  15.000   15.0  0.00000000  0.0000  15.000  15.00  15.0  15  15.0  15.0
#> 14  19.000   19.0  0.00000000  0.0000  19.000  19.00  19.0  19  19.0  19.0
#> 15   4.000    4.0  0.00000000  0.0000   4.000   4.00   4.0   4   4.0   4.0
#> 16  10.000   10.0  0.00000000  0.0000  10.000  10.00  10.0  10  10.0  10.0
#> 17   2.000    2.0  0.00000000  0.0000   2.000   2.00   2.0   2   2.0   2.0
#> 18   3.000    3.0  0.00000000  0.0000   3.000   3.00   3.0   3   3.0   3.0
#> 19   5.000    5.0  0.00000000  0.0000   5.000   5.00   5.0   5   5.0   5.0
#> 20   7.000    7.0  0.00000000  0.0000   7.000   7.00   7.0   7   7.0   7.0
#> 21   3.000    3.0  0.00000000  0.0000   3.000   3.00   3.0   3   3.0   3.0
#> 22   5.000    5.0  0.00000000  0.0000   5.000   5.00   5.0   5   5.0   5.0
#> 23   3.000    3.0  0.00000000  0.0000   3.000   3.00   3.0   3   3.0   3.0
#> 24   6.000    6.0  0.00000000  0.0000   6.000   6.00   6.0   6   6.0   6.0
#> 25   6.000    6.0  0.00000000  0.0000   6.000   6.00   6.0   6   6.0   6.0
#> 26  11.000   11.0  0.00000000  0.0000  11.000  11.00  11.0  11  11.0  11.0
#> 27   6.000    6.0  0.00000000  0.0000   6.000   6.00   6.0   6   6.0   6.0
#> 28   8.000    8.0  0.00000000  0.0000   8.000   8.00   8.0   8   8.0   8.0
#> 29   6.000    6.0  0.00000000  0.0000   6.000   6.00   6.0   6   6.0   6.0
#> 30   7.000    7.0  0.00000000  0.0000   7.000   7.00   7.0   7   7.0   7.0
#> 31  17.000   17.0  0.00000000  0.0000  17.000  17.00  17.0  17  17.0  17.0
#> 32  46.000   46.0  0.00000000  0.0000  46.000  46.00  46.0  46  46.0  46.0
#> 33  41.000   41.0  0.00000000  0.0000  41.000  41.00  41.0  41  41.0  41.0
#> 34  54.000   54.0  0.00000000  0.0000  54.000  54.00  54.0  54  54.0  54.0
#> 35  44.005   44.0  0.07071068  0.0000  44.000  44.00  44.0  44  44.0  44.0
#> 36  57.020   57.0  0.14035132  0.0000  57.000  57.00  57.0  57  57.0  57.0
#> 37  45.020   45.0  0.14035132  0.0000  45.000  45.00  45.0  45  45.0  45.0
#> 38  78.045   78.0  0.23074056  0.0000  78.000  78.00  78.0  78  78.0  78.0
#> 39  52.065   52.0  0.24714450  0.0000  52.000  52.00  52.0  52  52.0  52.0
#> 40  72.150   72.0  0.39785859  0.0000  72.000  72.00  72.0  72  72.0  72.0
#> 41  71.375   71.0  0.62153562  0.0000  71.000  71.00  71.0  71  71.0  72.0
#> 42  88.655   88.0  0.93291298  0.0000  88.000  88.00  88.0  88  88.0  89.0
#> 43  73.405   73.0  1.99773113  1.4826  72.000  72.00  72.0  72  73.0  74.0
#> 44  88.815   88.0  3.46566432  2.2239  85.000  85.00  85.0  87  88.0  90.0
#> 45 132.535  130.0  8.18926709  5.9304 123.975 124.00 125.0 127 130.0 136.0
#> 46 103.065   98.0 20.88977473 16.3086  80.000  80.95  82.9  89  98.0 112.0
#> 47 109.225   99.0 38.19185073 32.6172  61.000  65.85  70.0  82  99.0 129.0
#> 48 105.490   86.5 75.60350089 51.1497  26.000  31.95  38.0  54  86.5 126.5
#>      q90    q95   q97.5 .event_num event_date
#> 1   61.0  61.00  61.000          0 1990-01-01
#> 2   50.0  50.00  50.000          1 1990-01-08
#> 3   44.0  44.00  44.000          2 1990-01-15
#> 4   46.0  46.00  46.000          3 1990-01-22
#> 5   39.0  39.00  39.000          4 1990-01-29
#> 6   34.0  34.00  34.000          5 1990-02-05
#> 7   24.0  24.00  24.000          6 1990-02-12
#> 8   17.0  17.00  17.000          7 1990-02-19
#> 9   17.0  17.00  17.000          8 1990-02-26
#> 10  16.0  16.00  16.000          9 1990-03-05
#> 11  17.0  17.00  17.000         10 1990-03-12
#> 12  22.0  22.00  22.000         11 1990-03-19
#> 13  15.0  15.00  15.000         12 1990-03-26
#> 14  19.0  19.00  19.000         13 1990-04-02
#> 15   4.0   4.00   4.000         14 1990-04-09
#> 16  10.0  10.00  10.000         15 1990-04-16
#> 17   2.0   2.00   2.000         16 1990-04-23
#> 18   3.0   3.00   3.000         17 1990-04-30
#> 19   5.0   5.00   5.000         18 1990-05-07
#> 20   7.0   7.00   7.000         19 1990-05-14
#> 21   3.0   3.00   3.000         20 1990-05-21
#> 22   5.0   5.00   5.000         21 1990-05-28
#> 23   3.0   3.00   3.000         22 1990-06-04
#> 24   6.0   6.00   6.000         23 1990-06-11
#> 25   6.0   6.00   6.000         24 1990-06-18
#> 26  11.0  11.00  11.000         25 1990-06-25
#> 27   6.0   6.00   6.000         26 1990-07-02
#> 28   8.0   8.00   8.000         27 1990-07-09
#> 29   6.0   6.00   6.000         28 1990-07-16
#> 30   7.0   7.00   7.000         29 1990-07-23
#> 31  17.0  17.00  17.000         30 1990-07-30
#> 32  46.0  46.00  46.000         31 1990-08-06
#> 33  41.0  41.00  41.000         32 1990-08-13
#> 34  54.0  54.00  54.000         33 1990-08-20
#> 35  44.0  44.00  44.000         34 1990-08-27
#> 36  57.0  57.00  57.000         35 1990-09-03
#> 37  45.0  45.00  45.000         36 1990-09-10
#> 38  78.0  78.00  79.000         37 1990-09-17
#> 39  52.0  53.00  53.000         38 1990-09-24
#> 40  73.0  73.00  73.000         39 1990-10-01
#> 41  72.0  73.00  73.000         40 1990-10-08
#> 42  90.0  91.00  91.000         41 1990-10-15
#> 43  75.0  76.00  77.025         42 1990-10-22
#> 44  93.0  95.05  97.025         43 1990-10-29
#> 45 141.0 146.05 155.000         44 1990-11-05
#> 46 128.0 137.05 148.050         45 1990-11-12
#> 47 161.1 183.10 194.250         46 1990-11-19
#> 48 190.3 258.15 320.075         47 1990-11-26
# }