Skip to contents

With 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.

Usage

sim(fit, data, n_sim, PI = FALSE)

Arguments

fit

A model fit created by fit_attrib

data

The data with either observed values or reference values.

n_sim

Number of simulations

PI

Returns a draw from the quasipoisson distribution with the calculated mean as mean. If false the exponential of the mean is returned.

Value

A dataset with 500 simulations of the expected response for each row in the original dataset.

Details

vignette("intro", package="attrib")

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
#>    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
#>    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
#>    1:      827      1      1  789.1178
#>    2:      751      2      1  790.8777
#>    3:      811      3      1  792.9291
#>    4:      787      4      1  795.2444
#>    5:      828      5      1  797.7921
#>   ---                                 
#> 2866:      791    570      5  784.0123
#> 2867:      787    571      5  783.6033
#> 2868:      785    572      5  783.6412
#> 2869:      754    573      5  784.1016
#> 2870:      770    574      5  784.9650