
Generates simulations of expected mortality by simulating the model coefficients.
Source:R/sim.R
      sim.RdWith the given fit from fit_attrib the function sim, from package arm, is used to generate 500 simulations of all the coefficients, from there respective posterior distributions. This is then used to compute the expected response for all simulations and rows in the input dataset.
Examples
response <- "deaths_n"
fixef <- "ili_isoweekmean7_13_pr100 +
  sin(2 * pi * (isoweek - 1) / 52) +
  cos(2 * pi * (isoweek - 1) / 52)"
ranef <- " (ili_isoweekmean7_13_pr100| season)"
offset <- "log(pop_jan1_n)"
data <- attrib::data_fake_attrib_nation
fit <- fit_attrib(data = data, response = response, fixef = fixef, ranef = ranef, offset = offset)
#> boundary (singular) fit: see help('isSingular')
n_sim <- 5
sim(fit, data, n_sim)
#>       location_code isoyear isoweek isoyearweek    season seasonweek pop_jan1_n
#>              <char>   <int>   <int>      <char>    <char>      <num>      <num>
#>    1:    nation_nor    2009      30     2009-30 2009/2010          1    5367580
#>    2:    nation_nor    2009      31     2009-31 2009/2010          2    5367580
#>    3:    nation_nor    2009      32     2009-32 2009/2010          3    5367580
#>    4:    nation_nor    2009      33     2009-33 2009/2010          4    5367580
#>    5:    nation_nor    2009      34     2009-34 2009/2010          5    5367580
#>   ---                                                                          
#> 2866:    nation_nor    2020      25     2020-25 2019/2020         48    5367580
#> 2867:    nation_nor    2020      26     2020-26 2019/2020         49    5367580
#> 2868:    nation_nor    2020      27     2020-27 2019/2020         50    5367580
#> 2869:    nation_nor    2020      28     2020-28 2019/2020         51    5367580
#> 2870:    nation_nor    2020      29     2020-29 2019/2020         52    5367580
#>       ili_isoweekmean0_6_pr100 ili_isoweekmean7_13_pr100 heatwavedays_n
#>                          <num>                     <num>          <num>
#>    1:             8.989140e-07              0.000000e+00     0.81818182
#>    2:             2.524744e-06              8.989140e-07     0.54545455
#>    3:             6.818846e-06              2.524744e-06     0.36363636
#>    4:             1.771046e-05              6.818846e-06     0.54545455
#>    5:             4.423928e-05              1.771046e-05     0.36363636
#>   ---                                                                  
#> 2866:             2.433569e-03              4.808987e-03     0.00000000
#> 2867:             1.184660e-03              2.433569e-03     0.18181818
#> 2868:             5.547034e-04              1.184660e-03     0.36363636
#> 2869:             2.498084e-04              5.547034e-04     0.09090909
#> 2870:             1.081928e-04              2.498084e-04     0.90909091
#>       deaths_n id_row sim_id sim_value
#>          <int>  <int>  <num>     <num>
#>    1:      827      1      1  785.1130
#>    2:      751      2      1  786.7189
#>    3:      811      3      1  788.6452
#>    4:      787      4      1  790.8664
#>    5:      828      5      1  793.3524
#>   ---                                 
#> 2866:      791    570      5  778.7174
#> 2867:      787    571      5  778.3289
#> 2868:      785    572      5  778.3929
#> 2869:      754    573      5  778.8821
#> 2870:      770    574      5  779.7753