diff --git a/articles/intro.html b/articles/intro.html index 06f9ad7..0a49cca 100644 --- a/articles/intro.html +++ b/articles/intro.html @@ -155,9 +155,9 @@

Parametrizing a Compartmental Model density_dt <- pop_dt[, .( - name, from = age, - weight = popF + popM - ) + from = c(age, max(age)+1), + weight = c(popF + popM, 0) + ), by = name ] rm(popF) @@ -169,7 +169,7 @@

Parametrizing a Compartmental Model
 plot_dt <- density_dt[, { # compute parameters for each country of interest
   paramix::parameter_summary(
-    f_param = ifr_levin, f_dense = .SD, model_agelimits
+    f_param = ifr_levin, f_pop = .SD, model_agelimits
   )
 }, by = name]

And plotting these different blends:

@@ -200,9 +200,9 @@

Typical Application# setup the model to outcome mapping using `alembic`s mapping_dt <- density_dt[, paramix::alembic( - f_param = ifr_levin, f_dense = .SD, + f_param = ifr_levin, f_pop = .SD, model_partition = model_agelimits, - output_partition = seq(min(from), max(from) + 1L, by = 5L) + output_partition = { res <- seq(min(from), max(from), by = 5L); res[length(res)] <- tail(model_agelimits, 1); res } ), by = name ] @@ -210,28 +210,28 @@

Typical Applicationparams <- mapping_dt[, paramix::blend(.SD), by = name] - + - + - + - + - + @@ -274,15 +274,15 @@

Typical Application
 model_density_dt <- density_dt[, .(
-  model_from = model_agelimits[findInterval(from, model_agelimits)],
+  model_partition = model_agelimits[findInterval(from, model_agelimits)],
   weight
-), by = name][, .(weight = sum(weight)), by = .(name, model_from)][,
+), by = name][, .(weight = sum(weight)), by = .(name, model_partition)][,
   weight := weight / sum(weight), by = name
 ]
 model_deaths_dt <- model_density_dt[
-  params, on = .(name, model_from)
+  params, on = .(name, model_partition)
 ][,
-  .(name, model_from, deaths = weight * 1e6 * value)
+  .(name, model_partition, deaths = weight * 1e6 * value)
 ]

model_from Afghanistan United Kingdom
00 - 4 0.0000074 0.0000074
55 - 19 0.0000269 0.0000271
2020 - 64 0.0011908 0.0024191
6565 - 100 0.0444615 0.0820226
@@ -319,8 +319,8 @@

Typical Application
 distill_methods_dt <- model_deaths_dt[,
   paramix::distill_summary(
-    .SD[, .(model_from, value = deaths)],
-    mapping_dt[name == .BY]
+    mapping_dt[name == .BY],
+    .SD[, .(model_partition, value = deaths)]
   ),
   by = name
 ]
diff --git a/articles/intro_files/figure-html/alembicplot-1.png b/articles/intro_files/figure-html/alembicplot-1.png index ec6464a..ad50dd2 100644 Binary files a/articles/intro_files/figure-html/alembicplot-1.png and b/articles/intro_files/figure-html/alembicplot-1.png differ diff --git a/articles/intro_files/figure-html/figlex-1.png b/articles/intro_files/figure-html/figlex-1.png index f5412e3..9343f19 100644 Binary files a/articles/intro_files/figure-html/figlex-1.png and b/articles/intro_files/figure-html/figlex-1.png differ diff --git a/articles/intro_files/figure-html/ifrfig-1.png b/articles/intro_files/figure-html/ifrfig-1.png index c902cbe..eb37579 100644 Binary files a/articles/intro_files/figure-html/ifrfig-1.png and b/articles/intro_files/figure-html/ifrfig-1.png differ diff --git a/pkgdown.yml b/pkgdown.yml index 73804dc..dc1a893 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -3,7 +3,7 @@ pkgdown: 2.1.1 pkgdown_sha: ~ articles: intro: intro.html -last_built: 2024-11-04T10:19Z +last_built: 2024-11-07T19:27Z urls: reference: https://cmmid.github.io/paramix/reference article: https://cmmid.github.io/paramix/articles diff --git a/reference/alembic.html b/reference/alembic.html index f530699..8434ca1 100644 --- a/reference/alembic.html +++ b/reference/alembic.html @@ -43,12 +43,13 @@

Create the Blending and Distilling Object

Usage

alembic(
   f_param,
-  f_dense,
+  f_pop,
   model_partition,
   output_partition,
-  pars_interp_opts = list(fun = stats::splinefun, method = "natural"),
-  dens_interp_opts = list(fun = stats::approxfun, method = "constant", yleft = 0, yright
-    = 0)
+  pars_interp_opts = interpolate_opts(fun = stats::splinefun, kind = "point", method =
+    "natural"),
+  pop_interp_opts = interpolate_opts(fun = stats::approxfun, kind = "integral", method =
+    "constant", yleft = 0, yright = 0)
 )
@@ -58,17 +59,17 @@

Argumentsf_param

a function, f(x) which transforms the feature (e.g. age), -and yields the parameter value. Alternatively, a data.frame where the first -column is the feature (x) and the second is the parameter (y); see +to yield the parameter values. Alternatively, a data.frame where the first +column is the feature and the second is the parameter; see xy.coords() for details. If the latter, combined with pars_interp_opts, and defaulting to spline interpolation.

-
f_dense
+
f_pop

like f_param, either a density function (though it does not have to integrate to 1 like a pdf) or a data.frame of values. If the -latter, combined with dens_interp_opts and defaulting to constant density -from each x to the next.

+latter, it is treated as a series of populations within intervals, and +then interpolated with pop_interp_opts to create a density function.

model_partition
@@ -83,19 +84,22 @@

Argumentspars_interp_opts

a list, minimally with an element fun, corresponding to an interpolation function. Defaults to splinefun() -"natural" interpolation

+"natural" interpolation.

-
dens_interp_opts
+
pop_interp_opts

ibid, but for density. Defaults to approxfun() -"constant" interpolation

+"constant" interpolation.

Value

-

a data.frame which maps fractions of the original model partitions -to the desired partitions, according to underlying relative outcome rates and -densities

+

a data.table with columns model_partition, output_partition, weight and +relpop. The first two columns identify partition lower bounds, for both the model +and output, the other values are associated with; the combination of +model_partition and output_partition forms a unique identifier, but individually they +may appear multiple times. Generally, this object is only useful as an input +to the blend() and distill() tools.

diff --git a/reference/blend.html b/reference/blend.html index 58b05a8..9ecdbb1 100644 --- a/reference/blend.html +++ b/reference/blend.html @@ -54,7 +54,7 @@

Arguments

Value

-

a data.table of with two columns: model_from (partition lower +

a data.table of with two columns: model_partition (partition lower bounds) and value (parameter values for those partitions)

@@ -68,6 +68,7 @@

Examples from = 0:99, weight = ifelse(0:99 < 65, 1, .99^(0:99-64)) ) # flat age distribution, then 1% annual deaths alembic_dt <- alembic(ifr_levin, age_pyramid, age_limits, 0:100) +#> Warning: data may not support bounds: upper bound 0 > last column 1 entry 0 ifr_blend <- blend(alembic_dt) # the actual function @@ -90,6 +91,7 @@

Examplesbad_alembic_dt <- alembic( ifr_levin, within(age_pyramid, weight <- 1), age_limits, 0:100 ) +#> Warning: data may not support bounds: upper bound 0 > last column 1 entry 0 ifr_unif <- blend(bad_alembic_dt) lines( age_limits, c(ifr_unif$value, tail(ifr_unif$value, 1)), diff --git a/reference/distill.html b/reference/distill.html index 1937c7c..5aeaf4b 100644 --- a/reference/distill.html +++ b/reference/distill.html @@ -47,7 +47,7 @@

Distill Outcomes

Usage

-
distill(alembic_dt, outcomes_dt)
+
distill(alembic_dt, outcomes_dt, groupcol = names(outcomes_dt)[1])
@@ -63,20 +63,146 @@

Argumentsgroupcol +

a string, the name of the outcome model group column. The +outcomes_dt[[groupcol]] column must match the model_partition lower +bounds, as provided when constructing the alembic_dt with alembic().

+

Value

-

a data.frame, with new_from and recalculated value column

+

a data.frame, with output_partition and recalculated value column

Details

When the value column is re-calculated, note that it will aggregate all -matching from / model_from rows in outcomes_dt. If you need to group +rows with matching groupcol entries in outcomes_dt. If you need to group by other features in your input data (e.g. if you need to distill outcomes -across multiple simulation outputs), that has to be done outside of any call -to distill().

+across multiple simulation outputs or at multiple time points), that has to +be done by external grouping then calling distill().

+
+

Examples

+

+ifr_levin <- function(age_in_years) {
+  (10^(-3.27 + 0.0524 * age_in_years))/100
+}
+age_limits <- c(seq(0, 69, by = 5), 70, 80, 100)
+age_pyramid <- data.table(
+  from = 0:99, weight = ifelse(0:99 < 65, 1, .99^(0:99-64))
+) # flat age distribution, then 1% annual deaths
+alembic_dt <- alembic(ifr_levin, age_pyramid, age_limits, 0:100)
+#> Warning: data may not support bounds: upper bound 0 > last column 1 entry 0
+
+results <- data.table(model_partition = head(age_limits, -1))[, value := 10]
+distill(alembic_dt, results)
+#>      output_partition     value
+#>                 <int>     <num>
+#>   1:                0 1.5485580
+#>   2:                1 1.7471391
+#>   3:                2 1.9711854
+#>   4:                3 2.2239626
+#>   5:                4 2.5091549
+#>   6:                5 1.5485580
+#>   7:                6 1.7471391
+#>   8:                7 1.9711854
+#>   9:                8 2.2239626
+#>  10:                9 2.5091549
+#>  11:               10 1.5485580
+#>  12:               11 1.7471391
+#>  13:               12 1.9711854
+#>  14:               13 2.2239626
+#>  15:               14 2.5091549
+#>  16:               15 1.5485580
+#>  17:               16 1.7471391
+#>  18:               17 1.9711854
+#>  19:               18 2.2239626
+#>  20:               19 2.5091549
+#>  21:               20 1.5485580
+#>  22:               21 1.7471391
+#>  23:               22 1.9711854
+#>  24:               23 2.2239626
+#>  25:               24 2.5091549
+#>  26:               25 1.5485580
+#>  27:               26 1.7471391
+#>  28:               27 1.9711854
+#>  29:               28 2.2239626
+#>  30:               29 2.5091549
+#>  31:               30 1.5485580
+#>  32:               31 1.7471391
+#>  33:               32 1.9711854
+#>  34:               33 2.2239626
+#>  35:               34 2.5091549
+#>  36:               35 1.5485580
+#>  37:               36 1.7471391
+#>  38:               37 1.9711854
+#>  39:               38 2.2239626
+#>  40:               39 2.5091549
+#>  41:               40 1.5485580
+#>  42:               41 1.7471391
+#>  43:               42 1.9711854
+#>  44:               43 2.2239626
+#>  45:               44 2.5091549
+#>  46:               45 1.5485580
+#>  47:               46 1.7471391
+#>  48:               47 1.9711854
+#>  49:               48 2.2239626
+#>  50:               49 2.5091549
+#>  51:               50 1.5485580
+#>  52:               51 1.7471391
+#>  53:               52 1.9711854
+#>  54:               53 2.2239626
+#>  55:               54 2.5091549
+#>  56:               55 1.5485580
+#>  57:               56 1.7471391
+#>  58:               57 1.9711854
+#>  59:               58 2.2239626
+#>  60:               59 2.5091549
+#>  61:               60 1.5485580
+#>  62:               61 1.7471391
+#>  63:               62 1.9711854
+#>  64:               63 2.2239626
+#>  65:               64 2.5091549
+#>  66:               65 1.5836554
+#>  67:               66 1.7688698
+#>  68:               67 1.9757458
+#>  69:               68 2.2068167
+#>  70:               69 2.4649122
+#>  71:               70 0.5782919
+#>  72:               71 0.6459253
+#>  73:               72 0.7214687
+#>  74:               73 0.8058472
+#>  75:               74 0.9000941
+#>  76:               75 1.0053635
+#>  77:               76 1.1229445
+#>  78:               77 1.2542771
+#>  79:               78 1.4009695
+#>  80:               79 1.5648182
+#>  81:               80 0.1629244
+#>  82:               81 0.1819790
+#>  83:               82 0.2032622
+#>  84:               83 0.2270344
+#>  85:               84 0.2535870
+#>  86:               85 0.2832449
+#>  87:               86 0.3163715
+#>  88:               87 0.3533723
+#>  89:               88 0.3947005
+#>  90:               89 0.4408622
+#>  91:               90 0.4924227
+#>  92:               91 0.5500134
+#>  93:               92 0.6143395
+#>  94:               93 0.6861889
+#>  95:               94 0.7664412
+#>  96:               95 0.8560794
+#>  97:               96 0.9562011
+#>  98:               97 1.0680324
+#>  99:               98 1.1929429
+#> 100:               99 0.0000000
+#>      output_partition     value
+
+
diff --git a/reference/distill_summary.html b/reference/distill_summary.html index 0c5112e..1e81551 100644 --- a/reference/distill_summary.html +++ b/reference/distill_summary.html @@ -44,26 +44,33 @@

Distillation Calculation Comparison Summary

Usage

-
distill_summary(model_outcomes_dt, alembic_dt)
+
distill_summary(alembic_dt, outcomes_dt, groupcol = names(outcomes_dt)[1])

Arguments

-
model_outcomes_dt
-

a data.table (or convertable to such) with columns -model_from and value

+
alembic_dt
+

an alembic() return value

-
alembic_dt
-

an alembic() return value

+
outcomes_dt
+

a long-format data.frame with a column either named +from or model_from and a column value (other columns will be silently +ignored)

+ + +
groupcol
+

a string, the name of the outcome model group column. The +outcomes_dt[[groupcol]] column must match the model_partition lower +bounds, as provided when constructing the alembic_dt with alembic().

Value

a data.table, columns:

Value

-

a new function, f(x) = f_param(x)*f_density(x)

+

a new function, f(x) = f_param(x)*f_pop(x)