Skip to contents

Setup observation model and data

Usage

enw_obs(family = c("negbin", "poisson"), observation_indicator = NULL, data)

Arguments

family

Character string, the observation model to use in the likelihood; enforced by base::match.arg(). By default this is a negative binomial ("negbin") with Poisson ("poisson") also being available. Support for additional observation models is planned, please open an issue with suggestions.

observation_indicator

A character string, the name of the column in the data that indicates whether an observation is observed or not (using a logical variable) and therefore whether or not it should be used in the likelihood. This variable should be present in the data input to enw_preprocess_data(). It can be generated using flag_observation in enw_complete_dates() or it can be created directly using enw_flag_observed_observations(). If either of these approaches are used then the variable will be name .observed. Default is NULL.

data

Output from enw_preprocess_data().

Value

A list as required by stan.

See also

Examples

enw_obs(data = enw_example("preprocessed"))
#> $family
#> [1] "negbin"
#> 
#> $data
#> $data$n
#> [1] 630
#> 
#> $data$t
#> [1] 41
#> 
#> $data$s
#> [1] 41
#> 
#> $data$g
#> [1] 1
#> 
#> $data$groups
#> [1] 1
#> 
#> $data$st
#>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#> [26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#> 
#> $data$ts
#>        1
#>  [1,]  1
#>  [2,]  2
#>  [3,]  3
#>  [4,]  4
#>  [5,]  5
#>  [6,]  6
#>  [7,]  7
#>  [8,]  8
#>  [9,]  9
#> [10,] 10
#> [11,] 11
#> [12,] 12
#> [13,] 13
#> [14,] 14
#> [15,] 15
#> [16,] 16
#> [17,] 17
#> [18,] 18
#> [19,] 19
#> [20,] 20
#> [21,] 21
#> [22,] 22
#> [23,] 23
#> [24,] 24
#> [25,] 25
#> [26,] 26
#> [27,] 27
#> [28,] 28
#> [29,] 29
#> [30,] 30
#> [31,] 31
#> [32,] 32
#> [33,] 33
#> [34,] 34
#> [35,] 35
#> [36,] 36
#> [37,] 37
#> [38,] 38
#> [39,] 39
#> [40,] 40
#> [41,] 41
#> 
#> $data$sl
#>  [1] 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 19 18 17
#> [26] 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1
#> 
#> $data$csl
#>  [1]  20  40  60  80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380
#> [20] 400 420 440 459 477 494 510 525 539 552 564 575 585 594 602 609 615 620 624
#> [39] 627 629 630
#> 
#> $data$lsl
#>  [1] 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 19 18 17
#> [26] 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1
#> 
#> $data$clsl
#>  [1]  20  40  60  80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380
#> [20] 400 420 440 459 477 494 510 525 539 552 564 575 585 594 602 609 615 620 624
#> [39] 627 629 630
#> 
#> $data$nsl
#>  [1] 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 19 18 17
#> [26] 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1
#> 
#> $data$cnsl
#>  [1]  20  40  60  80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380
#> [20] 400 420 440 459 477 494 510 525 539 552 564 575 585 594 602 609 615 620 624
#> [39] 627 629 630
#> 
#> $data$sg
#>  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#> [39] 1 1 1
#> 
#> $data$dmax
#> [1] 20
#> 
#> $data$sdmax
#>  [1] 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
#> [26] 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
#> 
#> $data$csdmax
#>  [1]  20  40  60  80 100 120 140 160 180 200 220 240 260 280 300 320 340 360 380
#> [20] 400 420 440 460 480 500 520 540 560 580 600 620 640 660 680 700 720 740 760
#> [39] 780 800 820
#> 
#> $data$obs
#>        0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
#>  [1,] 21 12  3  4  3  0  1  2  4  3  0  0  2  0  0  0  1  2  1  0
#>  [2,] 22 12  4  5  0  1 10  2  5  3  0  1  0  3  1  0  1  0  0  0
#>  [3,] 28 15  3  3  0  1  3  2  3  2  1  0  2  3  0  3  0  0  0  0
#>  [4,] 19 13  0  0  0  4  2  2  2  1  1  1  0  1  0  0  1  0  0  0
#>  [5,] 20  7  1  3 10  3  0  4  3  3  2  0  1  2  0  1  2  1  0  0
#>  [6,]  9  6  6  0  4  5  4  0  1  4  0  0  1  1  1  2  0  0  0  2
#>  [7,]  3 16  4  4  1  1  2  0  0  0  0  1  1  1  1  0  0  0  1  0
#>  [8,] 36 19 10  4  2  3  0  3  2  3  0  2  1  1  2  2  0  0  1  0
#>  [9,] 28 18  8  4  1  2  3  6  1  5  2  2  3  0  2  0  1  0  0  0
#> [10,] 34 19  2  1  5  2  4  3  7  3  1  0  4  3  3  1  2  0  0  1
#> [11,] 30 12  4  1 10  6  0  2  2  1  2  1  4  0  2  3  0  0  4  0
#> [12,] 31  8  4  9  8  2  5  2  1  1  2  4  1  3  1  0  1  2  2  2
#> [13,]  8  4 14  8  6  5  1  3  0  4  1  2  4  2  0  1  2  2  2  0
#> [14,]  9  6  2  3  0  0  0  0  1  2  4  1  0  0  0  0  0  0  0  0
#> [15,] 35 11  6  4  4  1  0  2  2  2  2  0  0  1  4  1  0  0  0  0
#> [16,] 51 28 25  3  5  2  3  5  5  7  1  0  0  4  5  5  1  1  0  0
#> [17,] 47 37  9  2  2  3  4  4  4  3  0  2  0 10  4  3  0  0  0  0
#> [18,] 36 20  2  4 11  8  8  3  5  2  0  2  4  4  0  2  2  0  0  1
#> [19,] 38 16  3 15 14  7  5  5  0  0  5  0  5  1  6  0  0  3  1  0
#> [20,]  7  5  5 11  7  5  1  3  1  6  3  3  4  1  1  7  2  3  2  0
#> [21,] 13 13  8  6  1  3  2  0  0  2  0  2  0  5  3  0  0  0  0  1
#> [22,] 51 43  6  4  4  3  1  6  4  5  5  4  0  4  5  0  2  2  0  0
#> [23,] 51 43 18  5  6  1  2  8  7  7  6  1  0  4  3  1  3  0  0  0
#> [24,] 45 21  6  2  2 11 17  5  7  4  1  0  5  3  0  2  2  0  0  0
#> [25,] 47 31  5  4 20  6  1  9  3  1  0  2  1  5  2  0  0  0  0  0
#> [26,] 40 15  6 23 14 13  8  9  0  1  3  3  2  0  1  1  0  0  0  0
#> [27,] 13 14 27 14  7  7  0  0  0  7  1  4  2  1  0  0  0  0  0  0
#> [28,] 14 23 11  3  1  1  0  0  0  1  0  2  2  0  0  0  0  0  0  0
#> [29,] 78 43 23 11  5  1  0  5  2  2  1  4  0  0  0  0  0  0  0  0
#> [30,] 80 53 17 15  7  3 14 12 13 13  6  0  0  0  0  0  0  0  0  0
#> [31,] 89 48 28  8  1 14 13 13 10 12  1  0  0  0  0  0  0  0  0  0
#> [32,] 86 44  9  3 27 13  7 11  4  0  0  0  0  0  0  0  0  0  0  0
#> [33,] 79 36  7 16 19 13  8  8  3  0  0  0  0  0  0  0  0  0  0  0
#> [34,] 22 24 35 18 10  4  7  5  0  0  0  0  0  0  0  0  0  0  0  0
#> [35,] 23 32 22 10  8  2  1  0  0  0  0  0  0  0  0  0  0  0  0  0
#> [36,] 96 85 30 18 10  3  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#> [37,] 92 86 23 18  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#> [38,] 84 87 27  4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#> [39,] 98 61 12  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#> [40,] 69 43  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#> [41,] 45  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#> 
#> $data$flat_obs
#>   [1] 21 12  3  4  3  0  1  2  4  3  0  0  2  0  0  0  1  2  1  0 22 12  4  5  0
#>  [26]  1 10  2  5  3  0  1  0  3  1  0  1  0  0  0 28 15  3  3  0  1  3  2  3  2
#>  [51]  1  0  2  3  0  3  0  0  0  0 19 13  0  0  0  4  2  2  2  1  1  1  0  1  0
#>  [76]  0  1  0  0  0 20  7  1  3 10  3  0  4  3  3  2  0  1  2  0  1  2  1  0  0
#> [101]  9  6  6  0  4  5  4  0  1  4  0  0  1  1  1  2  0  0  0  2  3 16  4  4  1
#> [126]  1  2  0  0  0  0  1  1  1  1  0  0  0  1  0 36 19 10  4  2  3  0  3  2  3
#> [151]  0  2  1  1  2  2  0  0  1  0 28 18  8  4  1  2  3  6  1  5  2  2  3  0  2
#> [176]  0  1  0  0  0 34 19  2  1  5  2  4  3  7  3  1  0  4  3  3  1  2  0  0  1
#> [201] 30 12  4  1 10  6  0  2  2  1  2  1  4  0  2  3  0  0  4  0 31  8  4  9  8
#> [226]  2  5  2  1  1  2  4  1  3  1  0  1  2  2  2  8  4 14  8  6  5  1  3  0  4
#> [251]  1  2  4  2  0  1  2  2  2  0  9  6  2  3  0  0  0  0  1  2  4  1  0  0  0
#> [276]  0  0  0  0  0 35 11  6  4  4  1  0  2  2  2  2  0  0  1  4  1  0  0  0  0
#> [301] 51 28 25  3  5  2  3  5  5  7  1  0  0  4  5  5  1  1  0  0 47 37  9  2  2
#> [326]  3  4  4  4  3  0  2  0 10  4  3  0  0  0  0 36 20  2  4 11  8  8  3  5  2
#> [351]  0  2  4  4  0  2  2  0  0  1 38 16  3 15 14  7  5  5  0  0  5  0  5  1  6
#> [376]  0  0  3  1  0  7  5  5 11  7  5  1  3  1  6  3  3  4  1  1  7  2  3  2  0
#> [401] 13 13  8  6  1  3  2  0  0  2  0  2  0  5  3  0  0  0  0  1 51 43  6  4  4
#> [426]  3  1  6  4  5  5  4  0  4  5  0  2  2  0  0 51 43 18  5  6  1  2  8  7  7
#> [451]  6  1  0  4  3  1  3  0  0 45 21  6  2  2 11 17  5  7  4  1  0  5  3  0  2
#> [476]  2  0 47 31  5  4 20  6  1  9  3  1  0  2  1  5  2  0  0 40 15  6 23 14 13
#> [501]  8  9  0  1  3  3  2  0  1  1 13 14 27 14  7  7  0  0  0  7  1  4  2  1  0
#> [526] 14 23 11  3  1  1  0  0  0  1  0  2  2  0 78 43 23 11  5  1  0  5  2  2  1
#> [551]  4  0 80 53 17 15  7  3 14 12 13 13  6  0 89 48 28  8  1 14 13 13 10 12  1
#> [576] 86 44  9  3 27 13  7 11  4  0 79 36  7 16 19 13  8  8  3 22 24 35 18 10  4
#> [601]  7  5 23 32 22 10  8  2  1 96 85 30 18 10  3 92 86 23 18  4 84 87 27  4 98
#> [626] 61 12 69 43 45
#> 
#> $data$flat_obs_lookup
#>   [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18
#>  [19]  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36
#>  [37]  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54
#>  [55]  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72
#>  [73]  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90
#>  [91]  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108
#> [109] 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
#> [127] 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
#> [145] 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
#> [163] 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
#> [181] 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
#> [199] 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
#> [217] 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
#> [235] 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
#> [253] 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
#> [271] 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
#> [289] 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
#> [307] 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
#> [325] 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
#> [343] 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
#> [361] 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
#> [379] 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
#> [397] 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
#> [415] 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
#> [433] 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
#> [451] 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
#> [469] 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
#> [487] 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
#> [505] 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
#> [523] 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
#> [541] 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
#> [559] 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
#> [577] 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
#> [595] 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
#> [613] 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
#> 
#> $data$latest_obs
#>         1
#>  [1,]  59
#>  [2,]  70
#>  [3,]  69
#>  [4,]  47
#>  [5,]  63
#>  [6,]  46
#>  [7,]  36
#>  [8,]  91
#>  [9,]  86
#> [10,]  95
#> [11,]  84
#> [12,]  89
#> [13,]  69
#> [14,]  28
#> [15,]  75
#> [16,] 151
#> [17,] 134
#> [18,] 114
#> [19,] 124
#> [20,]  77
#> [21,]  59
#> [22,] 149
#> [23,] 166
#> [24,] 133
#> [25,] 137
#> [26,] 139
#> [27,]  97
#> [28,]  58
#> [29,] 175
#> [30,] 233
#> [31,] 237
#> [32,] 204
#> [33,] 189
#> [34,] 125
#> [35,]  98
#> [36,] 242
#> [37,] 223
#> [38,] 202
#> [39,] 171
#> [40,] 112
#> [41,]  45
#> 
#> $data$model_obs
#> [1] 1
#> 
#> 
#> $priors
#>    variable                                              description
#>      <char>                                                   <char>
#> 1: sqrt_phi One over the square root of the reporting overdispersion
#>             distribution  mean    sd
#>                   <char> <num> <num>
#> 1: Zero truncated normal     0     1
#> 
#> $inits
#> function (data, priors) 
#> {
#>     priors <- enw_priors_as_data_list(priors)
#>     fn <- function() {
#>         init <- list(sqrt_phi = numeric(0), phi = numeric(0))
#>         if (data$model_obs == 1) {
#>             init$sqrt_phi <- array(max(abs(rnorm(1, priors$sqrt_phi_p[1], 
#>                 priors$sqrt_phi_p[2]/10)), 1e-04))
#>             init$phi <- 1/(init$sqrt_phi^2)
#>         }
#>         return(init)
#>     }
#>     return(fn)
#> }
#> <bytecode: 0x560ddfc6bb58>
#> <environment: 0x560ddfc6ae98>
#>