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.
Arguments
- object
A result from
nowcast()orauto_nowcast(). The native fit stored inobject@fitis serialized automatically.- file
Path to write (a single
.rdsfile).
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/Rtmp4sGqZH/file197414516819.rds.
#> ℹ Restore with `load_nowcast("/tmp/Rtmp4sGqZH/file197414516819.rds")`.
#> mean median sd mad q2.5 q5 q10 q25 q50 q75 q90
#> 1 61.000 61 0.00000000 0.0000 61.000 61.00 61.0 61 61 61.00 61.0
#> 2 50.000 50 0.00000000 0.0000 50.000 50.00 50.0 50 50 50.00 50.0
#> 3 44.000 44 0.00000000 0.0000 44.000 44.00 44.0 44 44 44.00 44.0
#> 4 46.000 46 0.00000000 0.0000 46.000 46.00 46.0 46 46 46.00 46.0
#> 5 39.000 39 0.00000000 0.0000 39.000 39.00 39.0 39 39 39.00 39.0
#> 6 34.000 34 0.00000000 0.0000 34.000 34.00 34.0 34 34 34.00 34.0
#> 7 24.000 24 0.00000000 0.0000 24.000 24.00 24.0 24 24 24.00 24.0
#> 8 17.000 17 0.00000000 0.0000 17.000 17.00 17.0 17 17 17.00 17.0
#> 9 17.000 17 0.00000000 0.0000 17.000 17.00 17.0 17 17 17.00 17.0
#> 10 16.000 16 0.00000000 0.0000 16.000 16.00 16.0 16 16 16.00 16.0
#> 11 17.000 17 0.00000000 0.0000 17.000 17.00 17.0 17 17 17.00 17.0
#> 12 22.000 22 0.00000000 0.0000 22.000 22.00 22.0 22 22 22.00 22.0
#> 13 15.000 15 0.00000000 0.0000 15.000 15.00 15.0 15 15 15.00 15.0
#> 14 19.000 19 0.00000000 0.0000 19.000 19.00 19.0 19 19 19.00 19.0
#> 15 4.000 4 0.00000000 0.0000 4.000 4.00 4.0 4 4 4.00 4.0
#> 16 10.000 10 0.00000000 0.0000 10.000 10.00 10.0 10 10 10.00 10.0
#> 17 2.000 2 0.00000000 0.0000 2.000 2.00 2.0 2 2 2.00 2.0
#> 18 3.000 3 0.00000000 0.0000 3.000 3.00 3.0 3 3 3.00 3.0
#> 19 5.000 5 0.00000000 0.0000 5.000 5.00 5.0 5 5 5.00 5.0
#> 20 7.000 7 0.00000000 0.0000 7.000 7.00 7.0 7 7 7.00 7.0
#> 21 3.000 3 0.00000000 0.0000 3.000 3.00 3.0 3 3 3.00 3.0
#> 22 5.000 5 0.00000000 0.0000 5.000 5.00 5.0 5 5 5.00 5.0
#> 23 3.000 3 0.00000000 0.0000 3.000 3.00 3.0 3 3 3.00 3.0
#> 24 6.000 6 0.00000000 0.0000 6.000 6.00 6.0 6 6 6.00 6.0
#> 25 6.000 6 0.00000000 0.0000 6.000 6.00 6.0 6 6 6.00 6.0
#> 26 11.000 11 0.00000000 0.0000 11.000 11.00 11.0 11 11 11.00 11.0
#> 27 6.000 6 0.00000000 0.0000 6.000 6.00 6.0 6 6 6.00 6.0
#> 28 8.000 8 0.00000000 0.0000 8.000 8.00 8.0 8 8 8.00 8.0
#> 29 6.000 6 0.00000000 0.0000 6.000 6.00 6.0 6 6 6.00 6.0
#> 30 7.000 7 0.00000000 0.0000 7.000 7.00 7.0 7 7 7.00 7.0
#> 31 17.000 17 0.00000000 0.0000 17.000 17.00 17.0 17 17 17.00 17.0
#> 32 46.000 46 0.00000000 0.0000 46.000 46.00 46.0 46 46 46.00 46.0
#> 33 41.000 41 0.00000000 0.0000 41.000 41.00 41.0 41 41 41.00 41.0
#> 34 54.005 54 0.07071068 0.0000 54.000 54.00 54.0 54 54 54.00 54.0
#> 35 44.010 44 0.09974843 0.0000 44.000 44.00 44.0 44 44 44.00 44.0
#> 36 57.005 57 0.07071068 0.0000 57.000 57.00 57.0 57 57 57.00 57.0
#> 37 45.020 45 0.14035132 0.0000 45.000 45.00 45.0 45 45 45.00 45.0
#> 38 78.045 78 0.23074056 0.0000 78.000 78.00 78.0 78 78 78.00 78.0
#> 39 52.140 52 0.38878758 0.0000 52.000 52.00 52.0 52 52 52.00 53.0
#> 40 72.135 72 0.40940575 0.0000 72.000 72.00 72.0 72 72 72.00 73.0
#> 41 71.280 71 0.55961221 0.0000 71.000 71.00 71.0 71 71 71.00 72.0
#> 42 88.675 88 0.97680383 0.0000 88.000 88.00 88.0 88 88 89.00 90.0
#> 43 73.650 73 1.84240939 1.4826 72.000 72.00 72.0 72 73 74.00 76.0
#> 44 88.915 88 3.18882707 2.9652 85.000 85.00 86.0 87 88 91.00 93.0
#> 45 132.350 131 7.00807144 5.9304 124.000 124.95 125.0 127 131 135.00 142.0
#> 46 99.995 96 15.28736382 14.8260 79.975 82.00 83.9 89 96 108.00 122.1
#> 47 107.805 99 34.34318340 32.6172 62.975 65.95 70.9 82 99 129.00 156.1
#> 48 102.275 82 73.88242306 51.8910 17.000 25.95 35.8 51 82 131.75 212.3
#> q95 q97.5 .event_num event_date
#> 1 61.00 61.000 0 1990-01-01
#> 2 50.00 50.000 1 1990-01-08
#> 3 44.00 44.000 2 1990-01-15
#> 4 46.00 46.000 3 1990-01-22
#> 5 39.00 39.000 4 1990-01-29
#> 6 34.00 34.000 5 1990-02-05
#> 7 24.00 24.000 6 1990-02-12
#> 8 17.00 17.000 7 1990-02-19
#> 9 17.00 17.000 8 1990-02-26
#> 10 16.00 16.000 9 1990-03-05
#> 11 17.00 17.000 10 1990-03-12
#> 12 22.00 22.000 11 1990-03-19
#> 13 15.00 15.000 12 1990-03-26
#> 14 19.00 19.000 13 1990-04-02
#> 15 4.00 4.000 14 1990-04-09
#> 16 10.00 10.000 15 1990-04-16
#> 17 2.00 2.000 16 1990-04-23
#> 18 3.00 3.000 17 1990-04-30
#> 19 5.00 5.000 18 1990-05-07
#> 20 7.00 7.000 19 1990-05-14
#> 21 3.00 3.000 20 1990-05-21
#> 22 5.00 5.000 21 1990-05-28
#> 23 3.00 3.000 22 1990-06-04
#> 24 6.00 6.000 23 1990-06-11
#> 25 6.00 6.000 24 1990-06-18
#> 26 11.00 11.000 25 1990-06-25
#> 27 6.00 6.000 26 1990-07-02
#> 28 8.00 8.000 27 1990-07-09
#> 29 6.00 6.000 28 1990-07-16
#> 30 7.00 7.000 29 1990-07-23
#> 31 17.00 17.000 30 1990-07-30
#> 32 46.00 46.000 31 1990-08-06
#> 33 41.00 41.000 32 1990-08-13
#> 34 54.00 54.000 33 1990-08-20
#> 35 44.00 44.000 34 1990-08-27
#> 36 57.00 57.000 35 1990-09-03
#> 37 45.00 45.000 36 1990-09-10
#> 38 78.00 79.000 37 1990-09-17
#> 39 53.00 53.000 38 1990-09-24
#> 40 73.00 73.000 39 1990-10-01
#> 41 72.00 73.000 40 1990-10-08
#> 42 90.00 91.000 41 1990-10-15
#> 43 77.00 80.000 42 1990-10-22
#> 44 95.00 98.000 43 1990-10-29
#> 45 148.00 152.025 44 1990-11-05
#> 46 130.10 139.025 45 1990-11-12
#> 47 174.05 183.125 46 1990-11-19
#> 48 236.20 281.050 47 1990-11-26
# }
