Baseline estimator for mortality. If a random effect is present the negative binomial distribution is used. Otherwise a quisipoisson is fitted to the data. We use simmulations to generate n_sim responses for each row in the dataset to create a baseline.
Arguments
- data_train
Data to train on.
- data_predict
Data to predict on
- n_sim
number of simulations to preform. Default setting is n_sim = 1000
- fixef
Fixed effekts
- ranef
Random effekts, default is NULL
- response
Response
- offset
Offset, can be NULL
Value
Residualplots for all ncor_i and some evaluationmetrixs for each of them as well as a plot containing credible intervals using the simulation
Details
For more details see the help vignette:
vignette("nowcast", package="attrib")
Examples
if (FALSE) {
data <- attrib::data_fake_nowcasting_county_aggregated
n_sim <- 100
fixef <- "sin(2 * pi * (week) / 53) + cos(2 * pi * (week ) / 53) + year"
ranef <- "(1|location_code)"
response <- "n_death"
data_train <- data[cut_doe< "2019-06-30"]
data_predict <- data
offset <- "log(pop)"
baseline_est(data_train, data_predict, n_sim = 1000, fixef, ranef, response, offset)
}
data <- data.table::as.data.table(data_fake_nowcasting_county_aggregated)
data <- data[location_code == "county_nor03"]
n_sim <- 100
fixef <- "sin(2 * pi * (week) / 53) + cos(2 * pi * (week ) / 53) + year"
ranef <- NULL
response <- "n_death"
data_train <- data[cut_doe< "2019-06-30"]
data_predict <- data
offset <- "log(pop)"
baseline_est(data_train, data_predict, n_sim = 1000, fixef, ranef, response, offset)
#> $simulations
#> cut_doe location_code n_death n0_0 p0_0 n0_1 p0_1 n0_2
#> 1: 2018-01-01 county_nor03 13 0 0 4 0.3076923 9
#> 2: 2018-01-01 county_nor03 13 0 0 4 0.3076923 9
#> 3: 2018-01-01 county_nor03 13 0 0 4 0.3076923 9
#> 4: 2018-01-01 county_nor03 13 0 0 4 0.3076923 9
#> 5: 2018-01-01 county_nor03 13 0 0 4 0.3076923 9
#> ---
#> 103996: 2019-12-23 county_nor03 0 0 NA NA NA NA
#> 103997: 2019-12-23 county_nor03 0 0 NA NA NA NA
#> 103998: 2019-12-23 county_nor03 0 0 NA NA NA NA
#> 103999: 2019-12-23 county_nor03 0 0 NA NA NA NA
#> 104000: 2019-12-23 county_nor03 0 0 NA NA NA NA
#> p0_2 n0_3 p0_3 n0_4 p0_4 n0_5 p0_5 week year pop id_row sim_id
#> 1: 0.6923077 13 1 13 1 13 1 1 2018 673469 1 1
#> 2: 0.6923077 13 1 13 1 13 1 1 2018 673469 1 2
#> 3: 0.6923077 13 1 13 1 13 1 1 2018 673469 1 3
#> 4: 0.6923077 13 1 13 1 13 1 1 2018 673469 1 4
#> 5: 0.6923077 13 1 13 1 13 1 1 2018 673469 1 5
#> ---
#> 103996: NA NA NA NA NA NA NA 52 2019 681071 104 996
#> 103997: NA NA NA NA NA NA NA 52 2019 681071 104 997
#> 103998: NA NA NA NA NA NA NA 52 2019 681071 104 998
#> 103999: NA NA NA NA NA NA NA 52 2019 681071 104 999
#> 104000: NA NA NA NA NA NA NA 52 2019 681071 104 1000
#> sim_value type
#> 1: 17 quasi_poisson
#> 2: 12 quasi_poisson
#> 3: 17 quasi_poisson
#> 4: 12 quasi_poisson
#> 5: 13 quasi_poisson
#> ---
#> 103996: 20 quasi_poisson
#> 103997: 11 quasi_poisson
#> 103998: 15 quasi_poisson
#> 103999: 9 quasi_poisson
#> 104000: 20 quasi_poisson
#>
#> $aggregated
#> cut_doe location_code n_death n0_0 p0_0 n0_1 p0_1 n0_2 p0_2
#> 1: 2018-01-01 county_nor03 13 0 0 4 0.3076923 9 0.6923077
#> 2: 2018-01-08 county_nor03 15 0 0 2 0.1333333 10 0.6666667
#> 3: 2018-01-15 county_nor03 6 0 0 1 0.1666667 5 0.8333333
#> 4: 2018-01-22 county_nor03 14 0 0 4 0.2857143 9 0.6428571
#> 5: 2018-01-29 county_nor03 15 0 0 3 0.2000000 11 0.7333333
#> ---
#> 100: 2019-11-25 county_nor03 13 0 0 0 0.0000000 10 0.7692308
#> 101: 2019-12-02 county_nor03 9 0 0 5 0.5555556 8 0.8888889
#> 102: 2019-12-09 county_nor03 12 0 0 2 0.1666667 12 1.0000000
#> 103: 2019-12-16 county_nor03 1 0 0 1 1.0000000 NA NA
#> 104: 2019-12-23 county_nor03 0 0 NA NA NA NA NA
#> n0_3 p0_3 n0_4 p0_4 n0_5 p0_5 week year pop id_row type
#> 1: 13 1.0000000 13 1 13 1 1 2018 673469 1 quasi_poisson
#> 2: 15 1.0000000 15 1 15 1 2 2018 673469 2 quasi_poisson
#> 3: 6 1.0000000 6 1 6 1 3 2018 673469 3 quasi_poisson
#> 4: 14 1.0000000 14 1 14 1 4 2018 673469 4 quasi_poisson
#> 5: 14 0.9333333 15 1 15 1 5 2018 673469 5 quasi_poisson
#> ---
#> 100: 13 1.0000000 13 1 NA NA 48 2019 681071 100 quasi_poisson
#> 101: 9 1.0000000 NA NA NA NA 49 2019 681071 101 quasi_poisson
#> 102: NA NA NA NA NA NA 50 2019 681071 102 quasi_poisson
#> 103: NA NA NA NA NA NA 51 2019 681071 103 quasi_poisson
#> 104: NA NA NA NA NA NA 52 2019 681071 104 quasi_poisson
#> median.sim_value q025.sim_value q975.sim_value
#> 1: 14 7 22
#> 2: 13 6 22
#> 3: 13 6 21
#> 4: 13 6 21
#> 5: 13 6 21
#> ---
#> 100: 15 8 24
#> 101: 15 8 23
#> 102: 15 8 24
#> 103: 15 7 24
#> 104: 15 8 23
#>
#> $fit
#>
#> Call: stats::glm(formula = stats::as.formula(formula), family = "quasipoisson",
#> data = data_train)
#>
#> Coefficients:
#> (Intercept) sin(2 * pi * (week)/53) cos(2 * pi * (week)/53)
#> -88.02798 -0.06323 0.08444
#> year log(pop)
#> 0.04489 NA
#>
#> Degrees of Freedom: 77 Total (i.e. Null); 74 Residual
#> Null Deviance: 78.14
#> Residual Deviance: 73.16 AIC: NA
#>