Skip to content

Commit 68eb93c

Browse files
authored
Issue 12: Add package website (#19)
* Add basic roxygen2 families to functions * Switch to using enwtheme (I think this is a shortcut for what was written here anyway, but good to use it) * Add function group descriptions * Add docs to gitignore * Add pkgdown to Rbuildignore * Drop Sam Abbott related content from yml * Add newline to end of yml Former-commit-id: ff88f93 Former-commit-id: d93904d1ead1ad620a9fd6045469852fc98efacd
1 parent 636eed2 commit 68eb93c

11 files changed

+119
-14
lines changed

.Rbuildignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
^docs$
1111
^data-raw$
1212
^CITATION\.cff$
13+
^pkgdown$

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ test_*.png
2121
data/models/*doublecensor
2222
data/models/*full
2323
data/models/*integrate
24-
data/models/*reparam
24+
data/models/*reparam
25+
docs

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Description: Understanding and accurately estimating epidemiological delay
2121
License: MIT + file LICENSE
2222
Encoding: UTF-8
2323
Roxygen: list(markdown = TRUE)
24-
RoxygenNote: 7.2.3
24+
RoxygenNote: 7.3.1
2525
Imports:
2626
brms,
2727
cmdstanr,

R/fitting-and-postprocessing.R

+20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#' Sample from the posterior of a model with additional diagnositics
2+
#'
3+
#' @family postprocess
24
#' @export
35
sample_model <- function(model, data, scenario = data.table::data.table(id = 1),
46
diagnostics = TRUE, ...) {
@@ -48,6 +50,8 @@ sample_model <- function(model, data, scenario = data.table::data.table(id = 1),
4850
}
4951

5052
#' Sample from the posterior of an epinowcast model with additional diagnositics
53+
#'
54+
#' @family postprocess
5155
#' @export
5256
sample_epinowcast_model <- function(
5357
model, data, scenario = data.table::data.table(id = 1),
@@ -115,6 +119,8 @@ sample_epinowcast_model <- function(
115119
}
116120

117121
#' Add natural scale summary parameters for a lognormal distribution
122+
#'
123+
#' @family postprocess
118124
#' @export
119125
add_natural_scale_mean_sd <- function(dt) {
120126
nat_dt <- data.table::copy(dt)
@@ -127,6 +133,8 @@ add_natural_scale_mean_sd <- function(dt) {
127133
}
128134

129135
#' Extract posterior samples for a lognormal brms model
136+
#'
137+
#' @family postprocess
130138
#' @export
131139
#' @importFrom posterior as_draws_df
132140
extract_lognormal_draws <- function(
@@ -164,6 +172,8 @@ extract_lognormal_draws <- function(
164172
}
165173

166174
#' Extract posterior samples for a lognormal epinowcast model
175+
#'
176+
#' @family postprocess
167177
#' @export
168178
extract_epinowcast_draws <- function(
169179
data, id_vars, from_dt = FALSE
@@ -199,6 +209,8 @@ extract_epinowcast_draws <- function(
199209
}
200210

201211
#' Primary event bias correction
212+
#'
213+
#' @family postprocess
202214
#' @export
203215
primary_censoring_bias_correction <- function(draws) {
204216
draws <- data.table::copy(draws)
@@ -210,6 +222,8 @@ primary_censoring_bias_correction <- function(draws) {
210222
}
211223

212224
#' Convert posterior lognormal samples to long format
225+
#'
226+
#' @family postprocess
213227
#' @export
214228
draws_to_long <- function(draws) {
215229
long_draws <- data.table::melt(
@@ -221,6 +235,8 @@ draws_to_long <- function(draws) {
221235
}
222236

223237
#' Make posterior lognormal samples relative to true values
238+
#'
239+
#' @family postprocess
224240
#' @export
225241
make_relative_to_truth <- function(draws, secondary_dist, by = "parameter") {
226242
draws <- merge(
@@ -238,6 +254,8 @@ make_relative_to_truth <- function(draws, secondary_dist, by = "parameter") {
238254
#' @param not_by A vector of columns to exclude from the grouping
239255
#' This will be overridden if by is specified.
240256
#' @inheritParams summarise_variable
257+
#'
258+
#' @family postprocess
241259
#' @export
242260
summarise_draws <- function(draws, sf, not_by = "value", by) {
243261
if (missing(by)) {
@@ -280,6 +298,8 @@ summarise_draws <- function(draws, sf, not_by = "value", by) {
280298
#' @param sf The number of significant figures to use
281299
#' @param variable The variable to summarise
282300
#' @param by A vector of columns to group by
301+
#'
302+
#' @family postprocess
283303
#' @export
284304
summarise_variable <- function(draws, variable, sf = 6, by = c()) {
285305
if (missing(variable)) {

R/models.R

+20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#' Estimate delays naively
2+
#'
3+
#' @family model
24
#' @export
35
naive_delay <- function(formula = brms::bf(delay_daily ~ 1, sigma ~ 1), data,
46
fn = brms::brm, family = "lognormal", ...) {
@@ -10,6 +12,8 @@ naive_delay <- function(formula = brms::bf(delay_daily ~ 1, sigma ~ 1), data,
1012
}
1113

1214
#' Estimate delays with filtering of the most recent data
15+
#'
16+
#' @family model
1317
#' @export
1418
filtered_naive_delay <- function(
1519
formula = brms::bf(delay_daily ~ 1, sigma ~ 1), data, fn = brms::brm,
@@ -26,6 +30,8 @@ filtered_naive_delay <- function(
2630
}
2731

2832
#' Estimate delays adjusted for censoring
33+
#'
34+
#' @family model
2935
#' @export
3036
censoring_adjusted_delay <- function(
3137
formula = brms::bf(
@@ -39,6 +45,8 @@ censoring_adjusted_delay <- function(
3945

4046
#' Estimate delays adjusted forcensoring using a
4147
#' latent model
48+
#'
49+
#' @family model
4250
#' @export
4351
latent_censoring_adjusted_delay <- function(
4452
formula = brms::bf(
@@ -103,6 +111,8 @@ latent_censoring_adjusted_delay <- function(
103111

104112
#' Estimate delays with filtering of the most recent data and
105113
#' censoring adjustment
114+
#'
115+
#' @family model
106116
#' @export
107117
filtered_censoring_adjusted_delay <- function(
108118
formula = brms::bf(
@@ -120,6 +130,8 @@ filtered_censoring_adjusted_delay <- function(
120130
}
121131

122132
#' Estimate delays adjusted for right truncation
133+
#'
134+
#' @family model
123135
#' @export
124136
truncation_adjusted_delay <- function(
125137
formula = brms::bf(
@@ -134,6 +146,8 @@ truncation_adjusted_delay <- function(
134146
}
135147

136148
#' Estimate delays adjusted for censoring and right truncation
149+
#'
150+
#' @family model
137151
#' @export
138152
truncation_censoring_adjusted_delay <- function(
139153
formula = brms::bf(
@@ -151,6 +165,8 @@ truncation_censoring_adjusted_delay <- function(
151165

152166
#' Estimate delays adjusted for right truncation and censoring using a
153167
#' latent model
168+
#'
169+
#' @family model
154170
#' @export
155171
latent_truncation_censoring_adjusted_delay <- function(
156172
formula = brms::bf(
@@ -256,6 +272,8 @@ latent_truncation_censoring_adjusted_delay <- function(
256272
#' Estimate delays from the backward delay distribution + brms
257273
#' @param data_cases data frame consisting of integer time column and incidence
258274
#' column
275+
#'
276+
#' @family model
259277
#' @export
260278
dynamical_censoring_adjusted_delay <- function(
261279
formula = brms::bf(
@@ -407,11 +425,13 @@ dynamical_censoring_adjusted_delay <- function(
407425
return(fit)
408426
}
409427

428+
#' @family model
410429
#' @export
411430
dynamical_censoring_adjusted_delay_wrapper <- function(data, data_cases, ...) {
412431
dynamical_censoring_adjusted_delay(data = data, ...)
413432
}
414433

434+
#' @family model
415435
#' @export
416436
epinowcast_delay <- function(formula = ~ 1, data, by = c(),
417437
family = "lognormal", max_delay = 30,

R/observe.R

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#' Observation process for primary and secondary events
2+
#'
3+
#' @family observe
24
#' @export
35
observe_process <- function(linelist) {
46
clinelist <- data.table::copy(linelist)
@@ -23,6 +25,8 @@ observe_process <- function(linelist) {
2325
}
2426

2527
#' Filter observations based on a observation time of secondary events
28+
#'
29+
#' @family observe
2630
#' @export
2731
filter_obs_by_obs_time <- function(linelist, obs_time) {
2832
truncated_linelist <- data.table::copy(linelist)
@@ -36,6 +40,8 @@ filter_obs_by_obs_time <- function(linelist, obs_time) {
3640
}
3741

3842
#' Filter observations based on the observation time of primary events
43+
#'
44+
#' @family observe
3945
#' @export
4046
filter_obs_by_ptime <- function(linelist, obs_time,
4147
obs_at = c("obs_secondary", "max_secondary")) {
@@ -67,6 +73,8 @@ filter_obs_by_ptime <- function(linelist, obs_time,
6773
}
6874

6975
#' Pad zero observations as unstable in a lognormal distribution
76+
#'
77+
#' @family observe
7078
#' @export
7179
pad_zero <- function(data, pad = 1e-3) {
7280
data <- data.table::copy(data)
@@ -79,6 +87,8 @@ pad_zero <- function(data, pad = 1e-3) {
7987
}
8088

8189
#' Drop zero observations as unstable in a lognormal distribution
90+
#'
91+
#' @family observe
8292
#' @export
8393
drop_zero <- function(data) {
8494
data <- data.table::copy(data)

R/plot-helpers.R

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#' Calculate the cohort-based or cumulative mean
2+
#'
3+
#' @family plot
24
#' @export
35
calculate_cohort_mean <- function(data, type = c("cohort", "cumulative"),
46
by = c(), obs_at) {
@@ -24,6 +26,8 @@ calculate_cohort_mean <- function(data, type = c("cohort", "cumulative"),
2426
}
2527

2628
#' Calculate the truncated mean by observation horizon
29+
#'
30+
#' @family plot
2731
#' @export
2832
calculate_truncated_means <- function(draws, obs_at, ptime,
2933
distribution = function(x, y, z) {

R/plot.R

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#' Plot the posterior estimates as densities
2+
#'
3+
#' @family plot
24
#' @export
35
plot_recovery <- function(data, alpha = 0.8,
46
quantiles = c(0.05, 0.35, 0.65, 0.95), ...) {
@@ -13,6 +15,8 @@ plot_recovery <- function(data, alpha = 0.8,
1315
}
1416

1517
#' Plot the relative difference between true values and posterior estimates
18+
#'
19+
#' @family plot
1620
#' @export
1721
plot_relative_recovery <- function(relative_data, alpha = 0.8,
1822
quantiles = c(0.05, 0.35, 0.65, 0.95), ...) {
@@ -26,6 +30,8 @@ plot_relative_recovery <- function(relative_data, alpha = 0.8,
2630
}
2731

2832
#' Plot cases by observation window
33+
#'
34+
#' @family plot
2935
#' @export
3036
plot_cases_by_obs_window <- function(cases) {
3137
cases[case_type == "primary"] |>
@@ -50,6 +56,8 @@ plot_cases_by_obs_window <- function(cases) {
5056
}
5157

5258
#' Plot the empirical delay distribution
59+
#'
60+
#' @family plot
5361
#' @export
5462
plot_empirical_delay <- function(cases, meanlog, sdlog) {
5563
plot <- cases |>
@@ -80,6 +88,8 @@ plot_empirical_delay <- function(cases, meanlog, sdlog) {
8088
}
8189

8290
#' Plot the mean difference between continuous and discrete event time
91+
#'
92+
#' @family plot
8393
#' @export
8494
plot_censor_delay <- function(censor_delay) {
8595
ggplot(censor_delay) +
@@ -94,6 +104,7 @@ plot_censor_delay <- function(censor_delay) {
94104
}
95105

96106
#' plot empirical cohort-based or cumulative mean vs posterior mean
107+
#'
97108
#' @param summarised_mean Summarised mean as produced by [summarise_variable()]
98109
#' @param data data used for object fitting
99110
#' @param truncate account for truncation?
@@ -103,6 +114,8 @@ plot_censor_delay <- function(censor_delay) {
103114
#' @param ribbon_bounds Bounds of the quantile ribbon. Defaults to
104115
#' `c(0.05, 0.95)` which corresponds to the 90% credible interval.
105116
#' @param ... Additional arguments passed to [ggplot2::aes()].
117+
#'
118+
#' @family plot
106119
#' @export
107120
plot_mean_posterior_pred <- function(summarised_mean, obs_mean,
108121
alpha = 0.3, mean = FALSE, ribbon = TRUE,
@@ -149,6 +162,8 @@ make_ribbon_bound <- function(quantile) {
149162
}
150163

151164
#' Plot empirical cohort-based or cumulative mean
165+
#'
166+
#' @family plot
152167
#' @export
153168
plot_cohort_mean <- function(data) {
154169
gplot <- ggplot(data) +

R/preprocess.R

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#' For a target variable convert from individual data to counts
2+
#'
3+
#' @family preprocess
24
#' @export
35
linelist_to_counts <- function(linelist, target_time = "ptime_daily",
46
additional_by = c(), pad_zeros = FALSE) {
@@ -22,6 +24,8 @@ linelist_to_counts <- function(linelist, target_time = "ptime_daily",
2224
}
2325

2426
#' Convert primary and secondary observations to counts in long format
27+
#'
28+
#' @family preprocess
2529
#' @export
2630
linelist_to_cases <- function(linelist) {
2731
primary_cases <- linelist_to_counts(linelist)
@@ -42,6 +46,8 @@ linelist_to_cases <- function(linelist) {
4246
}
4347

4448
#' For the observation observed at variable reverse the factor ordering
49+
#'
50+
#' @family preprocess
4551
#' @export
4652
reverse_obs_at <- function(dt) {
4753
dt_rev <- data.table::copy(dt)
@@ -53,6 +59,8 @@ reverse_obs_at <- function(dt) {
5359
}
5460

5561
#' Construct case counts by observation window based on secondary observations
62+
#'
63+
#' @family preprocess
5664
#' @export
5765
construct_cases_by_obs_window <- function(linelist, windows = c(25, 45),
5866
obs_type = c("stime", "ptime"), upper_window = max(linelist$stime_daily)) {
@@ -94,6 +102,8 @@ construct_cases_by_obs_window <- function(linelist, windows = c(25, 45),
94102
}
95103

96104
#' Combine truncated and fully observed observations
105+
#'
106+
#' @family preprocess
97107
#' @export
98108
combine_obs <- function(truncated_obs, obs) {
99109
cobs <- rbind(
@@ -105,6 +115,8 @@ combine_obs <- function(truncated_obs, obs) {
105115
}
106116

107117
#' Calculate the mean difference between continuous and discrete event time
118+
#'
119+
#' @family preprocess
108120
#' @export
109121
calculate_censor_delay <- function(truncated_obs, additional_by = c()) {
110122
truncated_obs_psumm <- data.table::copy(truncated_obs)
@@ -137,6 +149,8 @@ calculate_censor_delay <- function(truncated_obs, additional_by = c()) {
137149
}
138150

139151
#' Convert from event based to incidence based data
152+
#'
153+
#' @family preprocess
140154
#' @export
141155
event_to_incidence <- function(data, by = c()) {
142156
dd <- data.table::copy(data)

0 commit comments

Comments
 (0)