Closed njtierney closed 1 year ago
This has been thought about further here: https://github.com/njtierney/conmat/blob/568f87f7a1eec7c042dec13f63adc08e2ad27ce0/R/utils.R#L247-L283
thinking further on this it is just going to be much simpler to pass along the age_breaks
argument throughout the package:
here's the old way:
library(conmat)
perth <- abs_age_lga("Perth (C)")
perth_contact <- extrapolate_polymod(
perth
)
perth_contact
#>
#> ── Setting Prediction Matrices ─────────────────────────────────────────────────
#> A list of matrices containing the model predicted contact rate between ages in
#> each setting.
#> There are 16 age breaks, ranging 0-75+ years, with a regular 5 year interval
#> • home: a 16x16 <matrix>
#> • work: a 16x16 <matrix>
#> • school: a 16x16 <matrix>
#> • other: a 16x16 <matrix>
#> • all: a 16x16 <matrix>
#> ℹ Access each <matrix> with `x$name`
#> ℹ e.g., `x$home`
age_breaks(perth_contact)
#> [1] 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 Inf
perth_contact$home
#> [0,5) [5,10) [10,15) [15,20) [20,25) [25,30)
#> [0,5) 0.39743272 0.32858156 0.16266890 0.11549597 0.17737726 0.32337782
#> [5,10) 0.19517061 0.31631444 0.20405822 0.07308499 0.05366436 0.09450085
#> [10,15) 0.07340049 0.15501627 0.26262315 0.13052669 0.04629618 0.03647250
#> [15,20) 0.08129556 0.08660778 0.20361271 0.34617980 0.17117933 0.06733926
#> [20,25) 0.33520290 0.17073579 0.19389231 0.45958005 0.75033980 0.43371301
#> [25,30) 1.12422936 0.55310701 0.28100613 0.33259296 0.79787952 1.25287546
#> [30,35) 1.46981373 1.16733001 0.53958673 0.26907742 0.34942848 0.77286620
#> [35,40) 0.75228654 1.03184699 0.76692996 0.32500119 0.17969761 0.22452945
#> [40,45) 0.24714099 0.42175817 0.56434159 0.38442657 0.17519410 0.09664137
#> [45,50) 0.12258162 0.15477531 0.26467697 0.33499218 0.24021233 0.11346046
#> [50,55) 0.11634877 0.09453224 0.11980486 0.19681878 0.25441570 0.18843147
#> [55,60) 0.13583681 0.09907539 0.07972905 0.09715725 0.16291241 0.21212824
#> [60,65) 0.12409809 0.11019331 0.07728851 0.05785383 0.07334905 0.12295444
#> [65,70) 0.08047604 0.09043208 0.07481086 0.04645367 0.03568280 0.04680601
#> [70,75) 0.04563800 0.05602698 0.05732976 0.04134836 0.02651310 0.02292755
#> [75,Inf) 0.04426322 0.05402899 0.05735758 0.05301371 0.04629475 0.04067223
#> [30,35) [35,40) [40,45) [45,50) [50,55) [55,60)
#> [0,5) 0.42309386 0.32249828 0.17482882 0.11643874 0.12111968 0.14046086
#> [5,10) 0.19959024 0.26274269 0.17721602 0.08732629 0.05845263 0.06085201
#> [10,15) 0.07008581 0.14835228 0.18013774 0.11344430 0.05627581 0.03720051
#> [15,20) 0.05451947 0.09806839 0.19141749 0.22397873 0.14421799 0.07071525
#> [20,25) 0.19008268 0.14557817 0.23420575 0.43119851 0.50050295 0.31834779
#> [25,30) 0.77343430 0.33462789 0.23767091 0.37468074 0.68194766 0.76257233
#> [30,35) 1.18337183 0.71235629 0.27862083 0.19726013 0.32950674 0.60259651
#> [35,40) 0.47832995 0.74598235 0.41641836 0.15812553 0.12221004 0.21381367
#> [40,45) 0.11337564 0.25235141 0.41451479 0.23314619 0.09520851 0.07604271
#> [45,50) 0.05977803 0.07136314 0.17362987 0.31201559 0.18803938 0.07732844
#> [50,55) 0.09111415 0.05032666 0.06469804 0.17158054 0.31976171 0.19028456
#> [55,60) 0.16775025 0.08864244 0.05202211 0.07103519 0.19156607 0.35290686
#> [60,65) 0.17318176 0.15183317 0.08300011 0.04953457 0.06990436 0.19371084
#> [65,70) 0.08608739 0.13403123 0.11850338 0.06277680 0.03878107 0.05928730
#> [70,75) 0.03335757 0.06575363 0.10223365 0.08777977 0.04847661 0.03283896
#> [75,Inf) 0.03731198 0.04258510 0.06921557 0.11451449 0.14108751 0.12662847
#> [60,65) [65,70) [70,75) [75,Inf)
#> [0,5) 0.12923192 0.09276131 0.06398890 0.03949403
#> [5,10) 0.06816025 0.06191473 0.04666018 0.02863430
#> [10,15) 0.03631734 0.03890983 0.03627042 0.02309264
#> [15,20) 0.04240693 0.03768949 0.04080715 0.03329481
#> [20,25) 0.14434743 0.07772649 0.07025032 0.07806026
#> [25,30) 0.44513693 0.18756273 0.11175844 0.12616273
#> [30,35) 0.62651639 0.34471913 0.16247928 0.11565443
#> [35,40) 0.36883088 0.36038124 0.21505704 0.08863433
#> [40,45) 0.12218423 0.19309132 0.20262997 0.08730195
#> [45,50) 0.05430515 0.07617760 0.12956877 0.10756643
#> [50,55) 0.06992880 0.04294051 0.06529161 0.12092723
#> [55,60) 0.19508361 0.06608822 0.04452763 0.10926521
#> [60,65) 0.35290261 0.19172258 0.07114219 0.07726893
#> [65,70) 0.17321190 0.32753478 0.18703148 0.06145177
#> [70,75) 0.05283892 0.15375773 0.28357109 0.09684605
#> [75,Inf) 0.09018228 0.07938642 0.15218488 0.24365406
age_breaks(perth_contact$home)
#> [1] "[0,5)" "[5,10)" "[10,15)" "[15,20)" "[20,25)" "[25,30)"
#> [7] "[30,35)" "[35,40)" "[40,45)" "[45,50)" "[50,55)" "[55,60)"
#> [13] "[60,65)" "[65,70)" "[70,75)" "[75,Inf)"
Created on 2023-03-08 with reprex v2.0.2
here's the new way
library(conmat)
perth <- abs_age_lga("Perth (C)")
perth_contact <- extrapolate_polymod(
perth
)
perth_contact
#>
#> ── Setting Prediction Matrices ─────────────────────────────────────────────────
#> A list of matrices containing the model predicted contact rate between ages in
#> each setting.
#> There are 16 age breaks, ranging 0-75+ years, with a regular 5 year interval
#> • home: a 16x16 <matrix>
#> • work: a 16x16 <matrix>
#> • school: a 16x16 <matrix>
#> • other: a 16x16 <matrix>
#> • all: a 16x16 <matrix>
#> ℹ Access each <matrix> with `x$name`
#> ℹ e.g., `x$home`
age_breaks(perth_contact)
#> [1] 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 Inf
perth_contact$home
#> [0,5) [5,10) [10,15) [15,20) [20,25) [25,30)
#> [0,5) 0.39743272 0.32858156 0.16266890 0.11549597 0.17737726 0.32337782
#> [5,10) 0.19517061 0.31631444 0.20405822 0.07308499 0.05366436 0.09450085
#> [10,15) 0.07340049 0.15501627 0.26262315 0.13052669 0.04629618 0.03647250
#> [15,20) 0.08129556 0.08660778 0.20361271 0.34617980 0.17117933 0.06733926
#> [20,25) 0.33520290 0.17073579 0.19389231 0.45958005 0.75033980 0.43371301
#> [25,30) 1.12422936 0.55310701 0.28100613 0.33259296 0.79787952 1.25287546
#> [30,35) 1.46981373 1.16733001 0.53958673 0.26907742 0.34942848 0.77286620
#> [35,40) 0.75228654 1.03184699 0.76692996 0.32500119 0.17969761 0.22452945
#> [40,45) 0.24714099 0.42175817 0.56434159 0.38442657 0.17519410 0.09664137
#> [45,50) 0.12258162 0.15477531 0.26467697 0.33499218 0.24021233 0.11346046
#> [50,55) 0.11634877 0.09453224 0.11980486 0.19681878 0.25441570 0.18843147
#> [55,60) 0.13583681 0.09907539 0.07972905 0.09715725 0.16291241 0.21212824
#> [60,65) 0.12409809 0.11019331 0.07728851 0.05785383 0.07334905 0.12295444
#> [65,70) 0.08047604 0.09043208 0.07481086 0.04645367 0.03568280 0.04680601
#> [70,75) 0.04563800 0.05602698 0.05732976 0.04134836 0.02651310 0.02292755
#> [75,Inf) 0.04426322 0.05402899 0.05735758 0.05301371 0.04629475 0.04067223
#> [30,35) [35,40) [40,45) [45,50) [50,55) [55,60)
#> [0,5) 0.42309386 0.32249828 0.17482882 0.11643874 0.12111968 0.14046086
#> [5,10) 0.19959024 0.26274269 0.17721602 0.08732629 0.05845263 0.06085201
#> [10,15) 0.07008581 0.14835228 0.18013774 0.11344430 0.05627581 0.03720051
#> [15,20) 0.05451947 0.09806839 0.19141749 0.22397873 0.14421799 0.07071525
#> [20,25) 0.19008268 0.14557817 0.23420575 0.43119851 0.50050295 0.31834779
#> [25,30) 0.77343430 0.33462789 0.23767091 0.37468074 0.68194766 0.76257233
#> [30,35) 1.18337183 0.71235629 0.27862083 0.19726013 0.32950674 0.60259651
#> [35,40) 0.47832995 0.74598235 0.41641836 0.15812553 0.12221004 0.21381367
#> [40,45) 0.11337564 0.25235141 0.41451479 0.23314619 0.09520851 0.07604271
#> [45,50) 0.05977803 0.07136314 0.17362987 0.31201559 0.18803938 0.07732844
#> [50,55) 0.09111415 0.05032666 0.06469804 0.17158054 0.31976171 0.19028456
#> [55,60) 0.16775025 0.08864244 0.05202211 0.07103519 0.19156607 0.35290686
#> [60,65) 0.17318176 0.15183317 0.08300011 0.04953457 0.06990436 0.19371084
#> [65,70) 0.08608739 0.13403123 0.11850338 0.06277680 0.03878107 0.05928730
#> [70,75) 0.03335757 0.06575363 0.10223365 0.08777977 0.04847661 0.03283896
#> [75,Inf) 0.03731198 0.04258510 0.06921557 0.11451449 0.14108751 0.12662847
#> [60,65) [65,70) [70,75) [75,Inf)
#> [0,5) 0.12923192 0.09276131 0.06398890 0.03949403
#> [5,10) 0.06816025 0.06191473 0.04666018 0.02863430
#> [10,15) 0.03631734 0.03890983 0.03627042 0.02309264
#> [15,20) 0.04240693 0.03768949 0.04080715 0.03329481
#> [20,25) 0.14434743 0.07772649 0.07025032 0.07806026
#> [25,30) 0.44513693 0.18756273 0.11175844 0.12616273
#> [30,35) 0.62651639 0.34471913 0.16247928 0.11565443
#> [35,40) 0.36883088 0.36038124 0.21505704 0.08863433
#> [40,45) 0.12218423 0.19309132 0.20262997 0.08730195
#> [45,50) 0.05430515 0.07617760 0.12956877 0.10756643
#> [50,55) 0.06992880 0.04294051 0.06529161 0.12092723
#> [55,60) 0.19508361 0.06608822 0.04452763 0.10926521
#> [60,65) 0.35290261 0.19172258 0.07114219 0.07726893
#> [65,70) 0.17321190 0.32753478 0.18703148 0.06145177
#> [70,75) 0.05283892 0.15375773 0.28357109 0.09684605
#> [75,Inf) 0.09018228 0.07938642 0.15218488 0.24365406
age_breaks(perth_contact$home)
#> [1] 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 Inf
Created on 2023-03-08 with reprex v2.0.2
Currently with age breaks, we get the following out
However if we want to present that information differently, or compare it to other age groups, which might be formatted differently, we need to extract those numbers. I'm not sure the best way to do this, but one approach could be some kind of
tidy_age_breaks
function, which returns a data frame - however this all feels a bit complex!Created on 2023-01-17 with reprex v2.0.2
Session info
``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.2.1 (2022-06-23) #> os macOS Monterey 12.3.1 #> system aarch64, darwin20 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Australia/Brisbane #> date 2023-01-17 #> pandoc 2.19.2 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.2.0) #> cli 3.4.1 2022-09-23 [1] CRAN (R 4.2.0) #> codetools 0.2-18 2020-11-04 [1] CRAN (R 4.2.1) #> colorspace 2.0-3 2022-02-21 [1] CRAN (R 4.2.0) #> conmat * 0.0.1.9000 2023-01-16 [1] local #> DBI 1.1.3 2022-06-18 [1] CRAN (R 4.2.0) #> digest 0.6.30 2022-10-18 [1] CRAN (R 4.2.0) #> dplyr 1.0.10 2022-09-01 [1] CRAN (R 4.2.0) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.0) #> evaluate 0.18 2022-11-07 [1] CRAN (R 4.2.0) #> fansi 1.0.3 2022-03-24 [1] CRAN (R 4.2.0) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.0) #> fs 1.5.2 2021-12-08 [1] CRAN (R 4.2.0) #> furrr 0.3.1 2022-08-15 [1] CRAN (R 4.2.0) #> future 1.29.0 2022-11-06 [1] CRAN (R 4.2.0) #> generics 0.1.3 2022-07-05 [1] CRAN (R 4.2.0) #> ggplot2 3.4.0 2022-11-04 [1] CRAN (R 4.2.0) #> globals 0.16.2 2022-11-21 [1] CRAN (R 4.2.1) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.0) #> gtable 0.3.1 2022-09-01 [1] CRAN (R 4.2.0) #> highr 0.9 2021-04-16 [1] CRAN (R 4.2.0) #> hms 1.1.2 2022-08-19 [1] CRAN (R 4.2.0) #> htmltools 0.5.3 2022-07-18 [1] CRAN (R 4.2.0) #> knitr 1.41 2022-11-18 [1] CRAN (R 4.2.0) #> lattice 0.20-45 2021-09-22 [1] CRAN (R 4.2.1) #> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.2.0) #> listenv 0.8.0 2019-12-05 [1] CRAN (R 4.2.0) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.0) #> Matrix 1.5-3 2022-11-11 [1] CRAN (R 4.2.0) #> mgcv 1.8-41 2022-10-21 [1] CRAN (R 4.2.0) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.2.0) #> nlme 3.1-160 2022-10-10 [1] CRAN (R 4.2.0) #> parallelly 1.32.1 2022-07-21 [1] CRAN (R 4.2.0) #> pillar 1.8.1 2022-08-19 [1] CRAN (R 4.2.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.0) #> purrr * 0.3.5 2022-10-06 [1] CRAN (R 4.2.0) #> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.2.0) #> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.2.0) #> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.2.0) #> R.utils 2.12.2 2022-11-11 [1] CRAN (R 4.2.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.0) #> readr 2.1.3 2022-10-01 [1] CRAN (R 4.2.0) #> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.2.0) #> rlang 1.0.6 2022-09-24 [1] CRAN (R 4.2.0) #> rmarkdown 2.18 2022-11-09 [1] CRAN (R 4.2.0) #> rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.2.0) #> scales 1.2.1 2022-08-20 [1] CRAN (R 4.2.0) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.0) #> stringi 1.7.8 2022-07-11 [1] CRAN (R 4.2.0) #> stringr 1.5.0 2022-12-02 [1] CRAN (R 4.2.0) #> styler 1.8.1 2022-11-07 [1] CRAN (R 4.2.0) #> tibble 3.1.8 2022-07-22 [1] CRAN (R 4.2.0) #> tidyr 1.2.1 2022-09-08 [1] CRAN (R 4.2.0) #> tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.2.0) #> tzdb 0.3.0 2022-03-28 [1] CRAN (R 4.2.0) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.2.0) #> vctrs 0.5.1 2022-11-16 [1] CRAN (R 4.2.0) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.0) #> xfun 0.35 2022-11-16 [1] CRAN (R 4.2.0) #> yaml 2.3.6 2022-10-18 [1] CRAN (R 4.2.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library #> #> ────────────────────────────────────────────────────────────────────────────── ```