diff --git a/articles/biokinetics.html b/articles/biokinetics.html index 67bdfce..5b63283 100644 --- a/articles/biokinetics.html +++ b/articles/biokinetics.html @@ -121,14 +121,14 @@

Figure 2
 res <- mod$simulate_population_trajectories()
 head(res)
-#>        t        me        lo       hi titre_type infection_history
-#>    <int>     <num>     <num>    <num>     <char>            <char>
-#> 1:     0  76.47141  57.27662 102.3284  Ancestral   Infection naive
-#> 2:     1  95.17182  72.93386 123.2567  Ancestral   Infection naive
-#> 3:     2 117.85935  92.96590 147.9895  Ancestral   Infection naive
-#> 4:     3 145.82635 115.93716 178.9671  Ancestral   Infection naive
-#> 5:     4 180.04790 145.31797 220.9776  Ancestral   Infection naive
-#> 6:     5 222.61054 179.30822 277.7049  Ancestral   Infection naive
+#> time_since_last_exp me lo hi titre_type infection_history +#> <int> <num> <num> <num> <char> <char> +#> 1: 0 122.4521 94.33718 159.6148 Alpha Infection naive +#> 2: 1 153.0463 120.28414 192.0631 Alpha Infection naive +#> 3: 2 190.3371 154.97114 235.0330 Alpha Infection naive +#> 4: 3 236.9884 195.79415 286.8267 Alpha Infection naive +#> 5: 4 294.8035 246.31186 355.2880 Alpha Infection naive +#> 6: 5 367.0770 307.58535 442.0933 Alpha Infection naive

See data for the definition of the returned columns.

Using ggplot2:

@@ -154,10 +154,10 @@

Figure 2 c("Ancestral", "Alpha", "Delta"))] ggplot(data = plot_data) + - geom_line(aes(x = t, + geom_line(aes(x = time_since_last_exp, y = me, colour = titre_type)) + - geom_ribbon(aes(x = t, + geom_ribbon(aes(x = time_since_last_exp, ymin = lo, ymax = hi, fill = titre_type), alpha = 0.65) + @@ -191,12 +191,12 @@

Figure 4head(res) #> infection_history titre_type mu_p mu_s rel_drop_me mu_p_me mu_s_me #> <char> <char> <num> <num> <num> <num> <num> -#> 1: Infection naive Ancestral 533.1158 251.9865 0.3927568 559.8482 219.1231 -#> 2: Infection naive Ancestral 575.2759 214.5542 0.3927568 559.8482 219.1231 -#> 3: Infection naive Ancestral 536.4465 234.0302 0.3927568 559.8482 219.1231 -#> 4: Infection naive Ancestral 518.4062 210.3247 0.3927568 559.8482 219.1231 -#> 5: Infection naive Ancestral 549.9587 240.2445 0.3927568 559.8482 219.1231 -#> 6: Infection naive Ancestral 555.5118 228.2212 0.3927568 559.8482 219.1231 +#> 1: Infection naive Alpha 1258.690 258.2081 0.1948519 1231.681 238.9652 +#> 2: Infection naive Alpha 1345.815 258.1007 0.1948519 1231.681 238.9652 +#> 3: Infection naive Alpha 1208.841 277.9311 0.1948519 1231.681 238.9652 +#> 4: Infection naive Alpha 1160.909 244.2667 0.1948519 1231.681 238.9652 +#> 5: Infection naive Alpha 1219.513 244.6807 0.1948519 1231.681 238.9652 +#> 6: Infection naive Alpha 1115.654 276.2072 0.1948519 1231.681 238.9652

The values we’re going to plot are the mean peak titre values (mu_p) and mean set point titre values (mu_s), for different titre types and infection histories. See data for a full definition of all the returned @@ -257,14 +257,14 @@

Figure 5#> method from #> fortify.SpatialPolygonsDataFrame ggplot2 head(res) -#> calendar_date titre_type me lo hi time_shift -#> <IDat> <char> <num> <num> <num> <num> -#> 1: 2021-03-08 Ancestral 522.7076 425.0735 669.0837 0 -#> 2: 2021-03-09 Ancestral 519.7460 434.3634 642.1416 0 -#> 3: 2021-03-10 Ancestral 543.9154 449.0063 695.4239 0 -#> 4: 2021-03-11 Ancestral 531.7709 426.7716 652.3356 0 -#> 5: 2021-03-12 Ancestral 529.0004 426.9940 653.2677 0 -#> 6: 2021-03-13 Ancestral 546.2597 447.0206 679.0612 0 +#> calendar_day titre_type me lo hi time_shift +#> <IDat> <char> <num> <num> <num> <num> +#> 1: 2021-03-08 Alpha 1159.083 882.2681 1626.342 0 +#> 2: 2021-03-09 Alpha 1149.733 904.7969 1455.563 0 +#> 3: 2021-03-10 Alpha 1183.414 923.2380 1553.093 0 +#> 4: 2021-03-11 Alpha 1159.733 918.8463 1537.259 0 +#> 5: 2021-03-12 Alpha 1152.698 901.3702 1592.818 0 +#> 6: 2021-03-13 Alpha 1194.493 912.0854 1596.470 0

See data for a definition of all the returned columns. Figure 5 A plots the derived population trajectories. Here we replicate a portion of the graph from the paper, from the minimum date @@ -277,8 +277,8 @@

Figure 5dat$wave <- "Delta" plot_data <- merge( res, dat[, .( - min_date = min(date), max_date = max(date)), by = wave])[ - , .SD[calendar_date >= min_date & calendar_date <= date_ba2], by = wave] + min_date = min(day), max_date = max(day)), by = wave])[ + , .SD[calendar_day >= min_date & calendar_day <= date_ba2], by = wave] plot_data[, titre_type := forcats::fct_relevel( titre_type, @@ -286,14 +286,14 @@

Figure 5 ggplot() + geom_line( data = plot_data, - aes(x = calendar_date, + aes(x = calendar_day, y = me, group = interaction(titre_type, wave), colour = titre_type), alpha = 0.2) + geom_ribbon( data = plot_data, - aes(x = calendar_date, + aes(x = calendar_day, ymin = lo, ymax = hi, group = interaction(titre_type, wave) @@ -309,10 +309,10 @@

Figure 5 values = custom_palette) + scale_x_date( date_labels = "%b %Y", - limits = c(min(dat$date), date_ba2)) + + limits = c(min(dat$day), date_ba2)) + geom_smooth( data = plot_data, - aes(x = calendar_date, + aes(x = calendar_day, y = me, fill = titre_type, colour = titre_type, @@ -338,7 +338,7 @@

Figure 5combined_data <- data.table::data.table(data.table::rbindlist(results_list))

Plotting the median values:

-plot_data <- combined_data[calendar_date == date_delta]
+plot_data <- combined_data[calendar_day == date_delta]
 plot_data <- plot_data[, titre_type := forcats::fct_relevel(
     titre_type,
     c("Ancestral", "Alpha", "Delta"))]
diff --git a/articles/biokinetics_files/figure-html/unnamed-chunk-10-1.png b/articles/biokinetics_files/figure-html/unnamed-chunk-10-1.png
index aa669a5..5324e32 100644
Binary files a/articles/biokinetics_files/figure-html/unnamed-chunk-10-1.png and b/articles/biokinetics_files/figure-html/unnamed-chunk-10-1.png differ
diff --git a/articles/biokinetics_files/figure-html/unnamed-chunk-8-1.png b/articles/biokinetics_files/figure-html/unnamed-chunk-8-1.png
index 1627ab3..f973b80 100644
Binary files a/articles/biokinetics_files/figure-html/unnamed-chunk-8-1.png and b/articles/biokinetics_files/figure-html/unnamed-chunk-8-1.png differ
diff --git a/articles/data.html b/articles/data.html
index ae3faf2..762345e 100644
--- a/articles/data.html
+++ b/articles/data.html
@@ -86,37 +86,65 @@ 

A guide to model input and output data

Input data

-

The model requires a data table containing the following columns:

-
-

pid -

-

A unique numeric id to identify a person across observations

-
-
-

date -

-

The date of the observation

-
-
-

last_exp_date -

-

The last date on which the person was exposed

-
-
-

titre_type -

-

The name of the titre

-
-
-

value -

-

The value of the titre

-
-
-

censored -

-

Whether this observation should be censored: -1 for lower, 1 for -upper, 0 for none

+

The model requires time series data about individual titre readings, +along with last exposure times. Times can be relative (e.g. day of +study) or absolute (i.e. precise calendar dates). The full list of +required columns is as follows:

+ ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
nametypedescriptionrequired
pidnumeric or characterUnique identifier to identify a person across observationsT
dayinteger or dateThe day of the observation. Can be a date or an integer representing +a relative day of studyT
last_exp_dayinteger or dateThe most recent day on which the person was exposed. Must be of the +same type as the ‘day’ columnT
titre_typecharacterName of the titre or biomarkerT
valuenumericTitre valueT
censored-1, 0 or 1Optional column. Whether this observation should be treated as +censored: -1 for lower, 1 for upper, 0 for none.F

It can also contain further columns for any covariates to be included in the model. The data files installed with this package have additional columns infection_history, last_vax_type, and exp_num.

@@ -125,6 +153,28 @@

censoredcategorical variables; that is, converted to factors regardless of their input type.

+
+

Example +

+
+dat <- data.table::fread(system.file("delta_full.rds", package = "epikinetics"))
+head(dat)
+#>      pid        day last_exp_day titre_type    value censored infection_history
+#>    <int>     <IDat>       <IDat>     <char>    <num>    <int>            <char>
+#> 1:     1 2021-03-10   2021-03-08  Ancestral 175.9350        0   Infection naive
+#> 2:     1 2021-04-15   2021-03-08  Ancestral 607.5750        0   Infection naive
+#> 3:     1 2021-07-08   2021-03-08  Ancestral 179.0463        0   Infection naive
+#> 4:     1 2021-03-10   2021-03-08      Alpha   5.0000       -1   Infection naive
+#> 5:     1 2021-04-15   2021-03-08      Alpha 416.7905        0   Infection naive
+#> 6:     1 2021-07-08   2021-03-08      Alpha 103.5274        0   Infection naive
+#>    last_vax_type exp_num
+#>           <char>   <int>
+#> 1:      BNT162b2       2
+#> 2:      BNT162b2       2
+#> 3:      BNT162b2       2
+#> 4:      BNT162b2       2
+#> 5:      BNT162b2       2
+#> 6:      BNT162b2       2

@@ -154,26 +204,274 @@

simulate_population_trajectoriessummarise argument is TRUE or FALSE.

-
    -
  • -

    summarise = TRUE Returned columns are:

    -
      -
    • t:
    • -
    • p:
    • -
    • k:
    • -
    • me:
    • -
    • lo
    • -
    • hi
    • -
    • titre_type
    • -
    -

    There will also be a column for each covariate in the hierarchical +

    +

    summarise = TRUE +

    +

    Returned columns are

    + +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    nametypedescription
    time_since_last_expintegerNumber of days since last exposure
    menumericMedian titre value
    lonumericTitre value at the 0.025 quantile
    hinumericTitre value at the 0.975 quantile
    titre_typecharacterName of the titre or biomarker
    censored-1, 0 or 1Whether this observation should be treated as censored: -1 for +lower, 1 for upper, 0 for none
    +

    There will also be a column for each covariate in the regression model.

    -
  • -
  • summarise = FALSE Returned columns are t, p, k, -t0_pop, tp_pop, ts_pop, m1_pop, m2_pop, m3_pop, beta_t0, beta_tp, -beta_ts, beta_m1, beta_m2, beta_m3, mu .draw, titre_type and a column -for each covariate in the hierarchical model.

  • -
+

+
+

summarise = FALSE +

+

Returned columns are

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
nametypedescription
time_since_last_expintegerNumber of days since last exposure
t0_popnumeric
tp_popnumeric
ts_popnumeric
m1_popnumeric
m2_popnumeric
m3_popnumeric
beta_t0numeric
beta_tpnumeric
beta_tsnumeric
beta_m1numeric
beta_m2numeric
beta_t3numeric
munumericTitre value
.drawintegerDraw number
titre_typenumericName of the titre or biomarker
+

There will also be column for each covariate in the hierarchical +model.

+
+
+
+

simulate_individual_trajectories +

+

See the documentation for this function here. +There are 2 different output formats depending on whether the provided +summarise argument is TRUE or +FALSE.

+
+

summarise = FALSE +

+

Returned columns are

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
nametypedescription
pidcharacter or numericUnique person identifier as provided in input data
drawintegerWhich draw from the fits this is
time_since_last_expintegerNumber of days since last exposure
munumericTitre value
titre_typecharacterName of the titre or biomarker
exposure_dayintegerDay of this person’s last exposure
calendar_dayintegerDay of this titre value
time_shiftintegerThe number of days these exposures have been adjusted by, as +provided in function arguments
+

There will also be a column for each covariate in the regression +model.

+
+
+

summarise = TRUE +

+

Returned columns are

+ +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
nametypedescription
menumericMedian titre value
lonumericTitre value at the 0.025 quantile
hinumericTitre value at the 0.075 quantile
titre_typecharacterName of the titre or biomarker
calendar_dayintegerDay of this titre value
time_shiftintegerThe number of days the exposures were adjusted by, as provided in +function arguments
+
diff --git a/authors.html b/authors.html index f10dad4..a19c9bb 100644 --- a/authors.html +++ b/authors.html @@ -60,7 +60,7 @@

Authors and Citation

  • -

    Alex Hill. Contributor, maintainer. +

    Alex Hill. Author, maintainer.

  • @@ -72,13 +72,13 @@

    Citation

    -

    Russell T (2024). -epikinetics: Antibody and Cycle Threshold Kinetics Modelling. +

    Russell T, Hill A (2024). +epikinetics: Biomarker Kinetics Modelling. R package version 0.0.0.9000.

    @Manual{,
    -  title = {epikinetics: Antibody and Cycle Threshold Kinetics Modelling},
    -  author = {Timothy Russell},
    +  title = {epikinetics: Biomarker Kinetics Modelling},
    +  author = {Timothy Russell and Alex Hill},
       year = {2024},
       note = {R package version 0.0.0.9000},
     }
    diff --git a/index.html b/index.html index 9ed6a70..bc1ea8d 100644 --- a/index.html +++ b/index.html @@ -5,14 +5,14 @@ -Antibody and Cycle Threshold Kinetics Modelling • epikinetics +Biomarker Kinetics Modelling • epikinetics - - + + Combine titre data and infection data into biokinetics input format. — add_exposure_data • epikinetics + + +
    +
    + + + +
    +
    + + +
    +

    The biokinetics class requires a single data table with titre readings +and last exposure times for all individuals. If you have exposure times and titre readings for the same +set of individuals in separate files, this function will combine them into a single data.table.

    +
    + +
    +
    add_exposure_data(dat_sero, dat_inf, exposure_column = "day")
    +
    + +
    +

    Arguments

    + + +
    dat_sero
    +

    data.table containing titre values in the format required by biokinetics. See data vignette: vignette("data", package = "epikinetics").

    + + +
    dat_inf
    +

    data.table containing exposure days and person ids corresponding to those in dat_sero. By default the exposure days are expected in a column called 'day'.

    + + +
    exposure_column
    +

    Default 'day'. The name of the column containing exposure days. These can be integers or dates.

    + +
    +
    +

    Value

    +

    A data.table with all columns required by the biokinetics model.

    +
    + +
    + +
    + + +
    + +
    +

    Site built with pkgdown 2.1.1.

    +
    + +
    + + + + + + + + diff --git a/reference/biokinetics.html b/reference/biokinetics.html index 543e229..496a15c 100644 --- a/reference/biokinetics.html +++ b/reference/biokinetics.html @@ -85,8 +85,7 @@

    Usage

    data = NULL, file_path = NULL, covariate_formula = ~0, - preds_sd = 0.25, - time_type = "relative" + preds_sd = 0.25 )

    @@ -114,10 +113,6 @@

    Arguments @@ -222,7 +217,6 @@

    Method simulate_populati

    Process the model results into a data table of titre values over time.

    Usage

    biokinetics$simulate_population_trajectories(
    -  time_type = "relative",
       t_max = 150,
       summarise = TRUE,
       n_draws = 2500
    @@ -231,11 +225,7 @@ 

    Usage

    Arguments

    -

    time_type
    -

    One of 'relative' or 'absolute'. Default 'relative'.

    - - -
    t_max
    +

    t_max

    Integer. Maximum number of time points to include.

    @@ -253,9 +243,9 @@

    Arguments

    Returns

    -

    A data.table containing titre values at time points. If summarise = TRUE, columns are t, me, lo, hi, -titre_type, and a column for each covariate in the hierarchical model. If summarise = FALSE, columns are t, .draw -t0_pop, tp_pop, ts_pop, m1_pop, m2_pop, m3_pop, beta_t0, beta_tp, beta_ts, beta_m1, beta_m2, beta_m3, mu +

    A data.table containing titre values at time points. If summarise = TRUE, columns are time_since_last_exp, +me, lo, hi, titre_type, and a column for each covariate in the hierarchical model. If summarise = FALSE, columns are +time_since_last_exp, .draw, t0_pop, tp_pop, ts_pop, m1_pop, m2_pop, m3_pop, beta_t0, beta_tp, beta_ts, beta_m1, beta_m2, beta_m3, mu titre_type and a column for each covariate in the hierarchical model. See the data vignette for details: vignette("data", package = "epikinetics")

    @@ -307,7 +297,7 @@

    ArgumentsArguments

    Returns

    A data.table. If summarise = TRUE columns are calendar_date, titre_type, me, lo, hi, time_shift. -If summarise = FALSE, columns are pid, draw, t, mu, titre_type, exposure_date, calendar_date, time_shift -and a column for each covariate in the hierarchical model. See the data vignette for details: +If summarise = FALSE, columns are pid, draw, time_since_last_exp, mu, titre_type, exposure_day, calendar_day, time_shift +and a column for each covariate in the regression model. See the data vignette for details: vignette("data", package = "epikinetics").

    diff --git a/reference/epikinetics-package.html b/reference/epikinetics-package.html index 3b5a848..c5b7a3b 100644 --- a/reference/epikinetics-package.html +++ b/reference/epikinetics-package.html @@ -1,5 +1,5 @@ -epikinetics: Antibody and Cycle Threshold Kinetics Modelling — epikinetics-package • epikineticsepikinetics: Biomarker Kinetics Modelling — epikinetics-package • epikinetics @@ -50,19 +50,19 @@
    -

    What the package does (one paragraph).

    +

    Fit kinetic curves to biomarker data, using a Bayesian hierarchical model

    Author

    -

    Maintainer: Alex Hill alex.hill@gmail.com [contributor]

    +

    Maintainer: Alex Hill alex.hill@gmail.com

    Authors:

    diff --git a/reference/index.html b/reference/index.html index becdf94..d0ed389 100644 --- a/reference/index.html +++ b/reference/index.html @@ -58,6 +58,10 @@

    All functions

    +

    add_exposure_data()

    + +

    Combine titre data and infection data into biokinetics input format.

    +

    biokinetics

    Biomarker Kinetics Model

    diff --git a/sitemap.xml b/sitemap.xml index 5b5dd96..ff39ca8 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -7,6 +7,7 @@ /articles/model.html /authors.html /index.html +/reference/add_exposure_data.html /reference/biokinetics.html /reference/biokinetics_priors.html /reference/convert_log_scale_inverse.html