Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow prediction to predict for ages <1 or other regular times #75

Closed
njtierney opened this issue Jun 23, 2022 · 2 comments
Closed

Allow prediction to predict for ages <1 or other regular times #75

njtierney opened this issue Jun 23, 2022 · 2 comments
Milestone

Comments

@njtierney
Copy link
Collaborator

njtierney commented Jun 23, 2022

https://idem-lab.github.io/conmat/reference/predict_contacts.html

@njtierney
Copy link
Collaborator Author

Assigning to @MikeLydeamore

@njtierney
Copy link
Collaborator Author

It seems that this now works? It is unclear what the issue to me was:

library(conmat)
polymod_setting_models$home
#> 
#> Call:  mgcv::bam(formula = formula, family = stats::poisson, data = ., 
#>     offset = log(participants))
#> 
#> Coefficients:
#>            (Intercept)      school_probability        work_probability  
#>              6.493e-01              -1.442e-01               1.481e-01  
#>   s(gam_age_offdiag).1    s(gam_age_offdiag).2    s(gam_age_offdiag).3  
#>             -7.637e+01               3.727e+00               1.333e+01  
#>   s(gam_age_offdiag).4    s(gam_age_offdiag).5    s(gam_age_offdiag).6  
#>              1.264e+00               4.240e+00               1.775e+00  
#>   s(gam_age_offdiag).7    s(gam_age_offdiag).8    s(gam_age_offdiag).9  
#>             -1.031e+00               1.662e-01               0.000e+00  
#> s(gam_age_offdiag_2).1  s(gam_age_offdiag_2).2  s(gam_age_offdiag_2).3  
#>             -3.461e-04              -1.245e-05               3.558e-05  
#> s(gam_age_offdiag_2).4  s(gam_age_offdiag_2).5  s(gam_age_offdiag_2).6  
#>              7.667e-06               1.673e-05              -1.517e-05  
#> s(gam_age_offdiag_2).7  s(gam_age_offdiag_2).8  s(gam_age_offdiag_2).9  
#>             -1.454e-05              -1.592e-05              -3.658e+01  
#> s(gam_age_diag_prod).1  s(gam_age_diag_prod).2  s(gam_age_diag_prod).3  
#>              1.732e+00              -2.292e-01               6.706e-01  
#> s(gam_age_diag_prod).4  s(gam_age_diag_prod).5  s(gam_age_diag_prod).6  
#>              1.252e-01               1.412e-01               1.773e-01  
#> s(gam_age_diag_prod).7  s(gam_age_diag_prod).8  s(gam_age_diag_prod).9  
#>             -3.042e-01               1.141e-01               7.966e-01  
#>  s(gam_age_diag_sum).1   s(gam_age_diag_sum).2   s(gam_age_diag_sum).3  
#>             -6.203e-01              -2.365e-01               3.936e-01  
#>  s(gam_age_diag_sum).4   s(gam_age_diag_sum).5   s(gam_age_diag_sum).6  
#>             -1.735e-01               2.407e-02              -1.014e-02  
#>  s(gam_age_diag_sum).7   s(gam_age_diag_sum).8   s(gam_age_diag_sum).9  
#>              3.443e-03               7.260e-02               0.000e+00  
#>      s(gam_age_pmax).1       s(gam_age_pmax).2       s(gam_age_pmax).3  
#>              5.904e+00              -4.460e-01              -1.303e+00  
#>      s(gam_age_pmax).4       s(gam_age_pmax).5       s(gam_age_pmax).6  
#>             -2.804e-01              -8.263e-01              -4.846e-01  
#>      s(gam_age_pmax).7       s(gam_age_pmax).8       s(gam_age_pmax).9  
#>              5.319e-01               3.135e-01               4.053e+01  
#>      s(gam_age_pmin).1       s(gam_age_pmin).2       s(gam_age_pmin).3  
#>             -5.091e-02               2.375e-02              -2.782e-02  
#>      s(gam_age_pmin).4       s(gam_age_pmin).5       s(gam_age_pmin).6  
#>             -2.755e-02              -1.336e-02               3.870e-02  
#>      s(gam_age_pmin).7       s(gam_age_pmin).8       s(gam_age_pmin).9  
#>              2.465e-02              -5.669e-03              -3.865e+01  
#> 
#> Degrees of Freedom: 8787 Total (i.e. Null);  8754.398 Residual
#> Null Deviance:       44000 
#> Residual Deviance: 10280     AIC: 26970

fairfield_abs_data <- abs_age_lga("Fairfield (C)")

fairfield_abs_data
#> # A tibble: 18 × 4 (conmat_population)
#>  - age: lower.age.limit
#>  - population: population
#>    lga           lower.age.limit  year population
#>    <chr>                   <dbl> <dbl>      <dbl>
#>  1 Fairfield (C)               0  2020      12261
#>  2 Fairfield (C)               5  2020      13093
#>  3 Fairfield (C)              10  2020      13602
#>  4 Fairfield (C)              15  2020      14323
#>  5 Fairfield (C)              20  2020      15932
#>  6 Fairfield (C)              25  2020      16190
#>  7 Fairfield (C)              30  2020      14134
#>  8 Fairfield (C)              35  2020      13034
#>  9 Fairfield (C)              40  2020      12217
#> 10 Fairfield (C)              45  2020      13449
#> 11 Fairfield (C)              50  2020      13419
#> 12 Fairfield (C)              55  2020      13652
#> 13 Fairfield (C)              60  2020      12907
#> 14 Fairfield (C)              65  2020      10541
#> 15 Fairfield (C)              70  2020       8227
#> 16 Fairfield (C)              75  2020       5598
#> 17 Fairfield (C)              80  2020       4006
#> 18 Fairfield (C)              85  2020       4240

# We can predict the contact rate for Fairfield from the existing contact
# data, say, between the age groups of 0-15 in 5 year bins for school:
fairfield_contacts_0_5_quarterly <- predict_setting_contacts(
  contact_model = polymod_setting_models,
  population = fairfield_abs_data,
  # three monthly - quarterly
  age_breaks = seq(from = 0, to = 5, length.out = 5*4)
)

autoplot(fairfield_contacts_0_5_quarterly)

Created on 2025-01-15 with reprex v2.1.1

Standard output and standard error

-- nothing to show --

Session info

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.2 (2024-10-31)
#>  os       macOS Sequoia 15.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Australia/Melbourne
#>  date     2025-01-15
#>  pandoc   3.2.1 @ /opt/homebrew/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version    date (UTC) lib source
#>  cli            3.6.3      2024-06-21 [1] CRAN (R 4.4.0)
#>  codetools      0.2-20     2024-03-31 [2] CRAN (R 4.4.2)
#>  colorspace     2.1-1      2024-07-26 [1] CRAN (R 4.4.0)
#>  conmat       * 0.0.2.9000 2024-08-19 [1] local
#>  curl           6.1.0      2025-01-06 [1] CRAN (R 4.4.1)
#>  digest         0.6.37     2024-08-19 [1] CRAN (R 4.4.1)
#>  dplyr          1.1.4      2023-11-17 [1] CRAN (R 4.4.0)
#>  evaluate       1.0.1      2024-10-10 [1] CRAN (R 4.4.1)
#>  farver         2.1.2      2024-05-13 [1] CRAN (R 4.4.0)
#>  fastmap        1.2.0      2024-05-15 [1] CRAN (R 4.4.0)
#>  fs             1.6.5      2024-10-30 [1] CRAN (R 4.4.1)
#>  furrr          0.3.1      2022-08-15 [1] CRAN (R 4.4.0)
#>  future         1.34.0     2024-07-29 [1] CRAN (R 4.4.0)
#>  generics       0.1.3      2022-07-05 [1] CRAN (R 4.4.0)
#>  ggplot2        3.5.1      2024-04-23 [1] CRAN (R 4.4.0)
#>  globals        0.16.3     2024-03-08 [1] CRAN (R 4.4.0)
#>  glue           1.8.0      2024-09-30 [1] CRAN (R 4.4.1)
#>  gtable         0.3.6      2024-10-25 [1] CRAN (R 4.4.1)
#>  hms            1.1.3      2023-03-21 [1] CRAN (R 4.4.0)
#>  htmltools      0.5.8.1    2024-04-04 [1] CRAN (R 4.4.0)
#>  knitr          1.49       2024-11-08 [1] CRAN (R 4.4.1)
#>  labeling       0.4.3      2023-08-29 [1] CRAN (R 4.4.0)
#>  lattice        0.22-6     2024-03-20 [2] CRAN (R 4.4.2)
#>  lifecycle      1.0.4      2023-11-07 [1] CRAN (R 4.4.0)
#>  listenv        0.9.1      2024-01-29 [1] CRAN (R 4.4.0)
#>  magrittr       2.0.3      2022-03-30 [1] CRAN (R 4.4.0)
#>  Matrix         1.7-1      2024-10-18 [2] CRAN (R 4.4.2)
#>  mgcv           1.9-1      2023-12-21 [2] CRAN (R 4.4.2)
#>  munsell        0.5.1      2024-04-01 [1] CRAN (R 4.4.0)
#>  nlme           3.1-166    2024-08-14 [2] CRAN (R 4.4.2)
#>  parallelly     1.41.0     2024-12-18 [1] CRAN (R 4.4.1)
#>  patchwork      1.3.0      2024-09-16 [1] CRAN (R 4.4.1)
#>  pillar         1.10.1     2025-01-07 [1] CRAN (R 4.4.1)
#>  pkgconfig      2.0.3      2019-09-22 [1] CRAN (R 4.4.0)
#>  purrr        * 1.0.2      2023-08-10 [1] CRAN (R 4.4.0)
#>  R6             2.5.1      2021-08-19 [1] CRAN (R 4.4.0)
#>  RColorBrewer   1.1-3      2022-04-03 [1] CRAN (R 4.4.0)
#>  readr          2.1.5      2024-01-10 [1] CRAN (R 4.4.0)
#>  reprex         2.1.1      2024-07-06 [1] CRAN (R 4.4.0)
#>  rlang          1.1.4      2024-06-04 [1] CRAN (R 4.4.0)
#>  rmarkdown      2.29       2024-11-04 [1] CRAN (R 4.4.1)
#>  rstudioapi     0.17.1     2024-10-22 [1] CRAN (R 4.4.1)
#>  scales         1.3.0      2023-11-28 [1] CRAN (R 4.4.0)
#>  sessioninfo    1.2.2      2021-12-06 [1] CRAN (R 4.4.0)
#>  tibble         3.2.1      2023-03-20 [1] CRAN (R 4.4.0)
#>  tidyr          1.3.1      2024-01-24 [1] CRAN (R 4.4.0)
#>  tidyselect     1.2.1      2024-03-11 [1] CRAN (R 4.4.0)
#>  tzdb           0.4.0      2023-05-12 [1] CRAN (R 4.4.0)
#>  utf8           1.2.4      2023-10-22 [1] CRAN (R 4.4.0)
#>  vctrs          0.6.5      2023-12-01 [1] CRAN (R 4.4.0)
#>  withr          3.0.2      2024-10-28 [1] CRAN (R 4.4.1)
#>  xfun           0.50.5     2025-01-15 [1] Github (yihui/xfun@116d689)
#>  xml2           1.3.6      2023-12-04 [1] CRAN (R 4.4.0)
#>  yaml           2.3.10     2024-07-26 [1] CRAN (R 4.4.0)
#> 
#>  [1] /Users/nick/Library/R/arm64/4.4/library
#>  [2] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants