Skip to contents

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.

Usage

baseline_est(
  data_train,
  data_predict,
  n_sim = 1000,
  fixef,
  ranef,
  response,
  offset
)

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) { # \dontrun{
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
#> Key: <cut_doe, location_code, n_death, n0_0, p0_0, n0_1, p0_1, n0_2, p0_2, n0_3, p0_3, n0_4, p0_4, n0_5, p0_5, week, year, pop, id_row, type>
#>            cut_doe location_code n_death  n0_0  p0_0  n0_1      p0_1  n0_2
#>             <Date>        <fctr>   <int> <num> <num> <num>     <num> <num>
#>      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
#>             <num> <num> <num> <num> <num> <num> <num> <int> <num>  <num>  <int>
#>      1: 0.6923077    13     1    13     1    13     1     1  2018 673469      1
#>      2: 0.6923077    13     1    13     1    13     1     1  2018 673469      1
#>      3: 0.6923077    13     1    13     1    13     1     1  2018 673469      1
#>      4: 0.6923077    13     1    13     1    13     1     1  2018 673469      1
#>      5: 0.6923077    13     1    13     1    13     1     1  2018 673469      1
#>     ---                                                                        
#> 103996:        NA    NA    NA    NA    NA    NA    NA    52  2019 681071    104
#> 103997:        NA    NA    NA    NA    NA    NA    NA    52  2019 681071    104
#> 103998:        NA    NA    NA    NA    NA    NA    NA    52  2019 681071    104
#> 103999:        NA    NA    NA    NA    NA    NA    NA    52  2019 681071    104
#> 104000:        NA    NA    NA    NA    NA    NA    NA    52  2019 681071    104
#>         sim_id sim_value          type
#>          <num>     <int>        <char>
#>      1:      1        27 quasi_poisson
#>      2:      2        10 quasi_poisson
#>      3:      3        20 quasi_poisson
#>      4:      4        13 quasi_poisson
#>      5:      5        16 quasi_poisson
#>     ---                               
#> 103996:    996        21 quasi_poisson
#> 103997:    997        18 quasi_poisson
#> 103998:    998        14 quasi_poisson
#> 103999:    999        19 quasi_poisson
#> 104000:   1000        10 quasi_poisson
#> 
#> $aggregated
#> Key: <cut_doe, location_code, n_death, n0_0, p0_0, n0_1, p0_1, n0_2, p0_2, n0_3, p0_3, n0_4, p0_4, n0_5, p0_5, week, year, pop, id_row, type>
#>         cut_doe location_code n_death  n0_0  p0_0  n0_1      p0_1  n0_2
#>          <Date>        <fctr>   <int> <num> <num> <num>     <num> <num>
#>   1: 2018-01-01  county_nor03      13     0     0     4 0.3076923     9
#>   2: 2018-01-08  county_nor03      15     0     0     2 0.1333333    10
#>   3: 2018-01-15  county_nor03       6     0     0     1 0.1666667     5
#>   4: 2018-01-22  county_nor03      14     0     0     4 0.2857143     9
#>   5: 2018-01-29  county_nor03      15     0     0     3 0.2000000    11
#>  ---                                                                   
#> 100: 2019-11-25  county_nor03      13     0     0     0 0.0000000    10
#> 101: 2019-12-02  county_nor03       9     0     0     5 0.5555556     8
#> 102: 2019-12-09  county_nor03      12     0     0     2 0.1666667    12
#> 103: 2019-12-16  county_nor03       1     0     0     1 1.0000000    NA
#> 104: 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
#>          <num> <num>     <num> <num> <num> <num> <num> <int> <num>  <num>
#>   1: 0.6923077    13 1.0000000    13     1    13     1     1  2018 673469
#>   2: 0.6666667    15 1.0000000    15     1    15     1     2  2018 673469
#>   3: 0.8333333     6 1.0000000     6     1     6     1     3  2018 673469
#>   4: 0.6428571    14 1.0000000    14     1    14     1     4  2018 673469
#>   5: 0.7333333    14 0.9333333    15     1    15     1     5  2018 673469
#>  ---                                                                     
#> 100: 0.7692308    13 1.0000000    13     1    NA    NA    48  2019 681071
#> 101: 0.8888889     9 1.0000000    NA    NA    NA    NA    49  2019 681071
#> 102: 1.0000000    NA        NA    NA    NA    NA    NA    50  2019 681071
#> 103:        NA    NA        NA    NA    NA    NA    NA    51  2019 681071
#> 104:        NA    NA        NA    NA    NA    NA    NA    52  2019 681071
#>      id_row          type median.sim_value q025.sim_value q975.sim_value
#>       <int>        <char>            <num>          <num>          <num>
#>   1:      1 quasi_poisson               14              7         22.000
#>   2:      2 quasi_poisson               14              7         21.025
#>   3:      3 quasi_poisson               13              7         21.000
#>   4:      4 quasi_poisson               13              7         22.000
#>   5:      5 quasi_poisson               13              7         21.000
#>  ---                                                                    
#> 100:    100 quasi_poisson               15              8         24.000
#> 101:    101 quasi_poisson               15              8         23.000
#> 102:    102 quasi_poisson               15              7         22.000
#> 103:    103 quasi_poisson               15              8         24.000
#> 104:    104 quasi_poisson               15              8         23.000
#> 
#> $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
#>