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

Issue #221: Add marginal model #426

Merged
merged 62 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
0d0be9f
Add cohort model template
athowes Nov 7, 2024
810423a
Fix to previous commit (name as cohort_model)
athowes Nov 11, 2024
8f4c34a
Generate simulated cohort data
athowes Nov 11, 2024
8bcfbe7
Add unweighted and weighted direct models
athowes Nov 11, 2024
e95316a
Thinking about custom family for pcd function
athowes Nov 11, 2024
2165646
functions component of stanvars
athowes Nov 12, 2024
602f015
Add transformed parameters for cohort model
athowes Nov 12, 2024
8d4c737
Progress on implementing PCD model
athowes Nov 12, 2024
5590a0f
Set q as vector
athowes Nov 12, 2024
d005cba
Get rid of params input
athowes Nov 13, 2024
31c3736
This would work, apart from it's the CDF. For the PMF need to import …
athowes Nov 13, 2024
b4b71a0
Almost working with "import all functions" strategy
athowes Nov 13, 2024
a107c2e
Wrap up on attempt
athowes Nov 13, 2024
4a0b5c5
Rename to marginal model
athowes Nov 14, 2024
6bf8479
Move towards single wrap function with others imported
athowes Nov 15, 2024
c56adf7
Just running into some C++ errors..
athowes Nov 15, 2024
419cb44
This doesn't change anything
athowes Nov 15, 2024
cff3176
Move to marginal model name and lint
athowes Nov 22, 2024
0a3e5ae
Create aggregate data inside model conversion function for now
athowes Nov 22, 2024
a9c5f64
First draft on moving marginal_model into functions
athowes Nov 22, 2024
b560ecd
Run document
athowes Nov 22, 2024
4d3990b
Tests working up to valid Stan code
athowes Nov 22, 2024
e5c7f96
Regex version of marginal model
athowes Nov 25, 2024
29b0e2c
Use prep_marginal_obs
athowes Nov 25, 2024
08f477e
Improve assert for marginal model
athowes Nov 25, 2024
944c455
Add pkgdown and document
athowes Nov 25, 2024
d545f82
Clean up scratch implementation
athowes Nov 27, 2024
2ef2b59
remove scratch file
seabbs Nov 29, 2024
cee62ac
update data format, formula, and family
seabbs Nov 29, 2024
cb32195
update stan code
seabbs Nov 29, 2024
67cd715
basic working version
seabbs Nov 29, 2024
371ed9c
add transformm data methods
seabbs Nov 29, 2024
eb37884
start exploring the ebola example
seabbs Nov 29, 2024
0adba0e
add a helper to find meaningful relative_obs_times
seabbs Dec 2, 2024
7c6f8f8
get the full ebola vignette working with new variable requirements
seabbs Dec 2, 2024
85c690c
improve return messages
seabbs Dec 2, 2024
099278b
update approx vignette
seabbs Dec 2, 2024
4d98a7b
get ebole vignette passing by checking pp and related inputs
seabbs Dec 2, 2024
7c97226
add marginal model integration tests
seabbs Dec 2, 2024
dd3831a
expand post processing tests
seabbs Dec 2, 2024
817738f
add marginal model
seabbs Dec 2, 2024
4024aba
use the right transform data keyword
seabbs Dec 2, 2024
ef042d3
add ... pass through to make constructors correct
seabbs Dec 2, 2024
c2d46ee
fix .summarise_n_by_formula test so error message is as expected
seabbs Dec 2, 2024
6464e95
drop not required .row_id
seabbs Dec 2, 2024
f42a182
check using ... properly
seabbs Dec 2, 2024
dfc73e0
make the progress messages prettier for reducing data complexit:
seabbs Dec 2, 2024
6c529f1
check post process tests again
seabbs Dec 2, 2024
9c0d9a2
add a test for the specific transform data method
seabbs Dec 2, 2024
0712992
add some tests for the generic transform data method
seabbs Dec 2, 2024
2aabfd7
put transform data tests in the correct folder
seabbs Dec 2, 2024
ff89e3b
add a news update
seabbs Dec 3, 2024
3a3aed2
change vignette language to talk about marginal model
seabbs Dec 3, 2024
2d1aef4
update the FAQ to use the marginal variables
seabbs Dec 3, 2024
2a61182
call it transformed_data not trans_data
seabbs Dec 3, 2024
4f080c4
change the error message to make it clear its a epidist limitation
seabbs Dec 3, 2024
6293762
update stan docs
seabbs Dec 3, 2024
7062e52
Update NEWS.md
seabbs Dec 3, 2024
79f0a88
Update NEWS.md
seabbs Dec 3, 2024
292cfb3
Update NEWS.md
seabbs Dec 3, 2024
ef17a1a
Update inst/stan/latent_model/functions.stan
seabbs Dec 3, 2024
0ce7617
Update setup.R
seabbs Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
^pkgdown$
^vignettes/approx-inference\.Rmd$
^vignettes/ebola\.Rmd$
^vignettes/faq\.Rmd$
^\.lintr$
16 changes: 16 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,34 @@ S3method(add_mean_sd,lognormal_samples)
S3method(as_epidist_latent_model,epidist_linelist_data)
S3method(as_epidist_linelist_data,data.frame)
S3method(as_epidist_linelist_data,default)
S3method(as_epidist_marginal_model,epidist_linelist_data)
S3method(as_epidist_naive_model,epidist_linelist_data)
S3method(assert_epidist,default)
S3method(assert_epidist,epidist_latent_model)
S3method(assert_epidist,epidist_linelist_data)
S3method(assert_epidist,epidist_marginal_model)
S3method(assert_epidist,epidist_naive_model)
S3method(epidist_family_model,default)
S3method(epidist_family_model,epidist_latent_model)
S3method(epidist_family_model,epidist_marginal_model)
S3method(epidist_family_param,default)
S3method(epidist_family_prior,default)
S3method(epidist_family_prior,lognormal)
S3method(epidist_formula_model,default)
S3method(epidist_formula_model,epidist_latent_model)
S3method(epidist_formula_model,epidist_marginal_model)
S3method(epidist_model_prior,default)
S3method(epidist_model_prior,epidist_latent_model)
S3method(epidist_stancode,default)
S3method(epidist_stancode,epidist_latent_model)
S3method(epidist_stancode,epidist_marginal_model)
S3method(epidist_transform_data_model,default)
S3method(epidist_transform_data_model,epidist_marginal_model)
export(Gamma)
export(add_mean_sd)
export(as_epidist_latent_model)
export(as_epidist_linelist_data)
export(as_epidist_marginal_model)
export(as_epidist_naive_model)
export(assert_epidist)
export(bf)
Expand All @@ -42,12 +50,16 @@ export(epidist_gen_posterior_predict)
export(epidist_model_prior)
export(epidist_prior)
export(epidist_stancode)
export(epidist_transform_data)
export(epidist_transform_data_model)
export(is_epidist_latent_model)
export(is_epidist_linelist_data)
export(is_epidist_marginal_model)
export(is_epidist_naive_model)
export(lognormal)
export(new_epidist_latent_model)
export(new_epidist_linelist_data)
export(new_epidist_marginal_model)
export(new_epidist_naive_model)
export(predict_delay_parameters)
export(predict_dpar)
Expand Down Expand Up @@ -78,14 +90,18 @@ importFrom(cli,cli_abort)
importFrom(cli,cli_alert_info)
importFrom(cli,cli_inform)
importFrom(cli,cli_warn)
importFrom(dplyr,across)
importFrom(dplyr,bind_cols)
importFrom(dplyr,bind_rows)
importFrom(dplyr,filter)
importFrom(dplyr,full_join)
importFrom(dplyr,group_by)
importFrom(dplyr,mutate)
importFrom(dplyr,select)
importFrom(dplyr,summarise)
importFrom(lubridate,days)
importFrom(lubridate,is.timepoint)
importFrom(purrr,map_chr)
importFrom(purrr,map_dbl)
importFrom(stats,Gamma)
importFrom(stats,as.formula)
Expand Down
11 changes: 9 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@

Development version of `epidist`.

## Models

- Added a marginalised likelihood model based on `primarycensored`. This can be specified using `as_epidist_marginal_model()`. This is currently limited to Weibull, log-normal, and gamma distributions with uniform primary censoring but this will be generalised in future releases. See #426.
- Added user settable primary event priors to the latent model. See #474.
- Added a marginalised likelihood to the latent model. See #474.

## Package

- Remove the default method for `epidist()`. See #473.
- Added `enforce_presence` argument to `epidist_prior()` to allow for priors to be
specified if they do not match existing parameters. See #474.
- Added a `merge` argument to `epidist_prior()` to allow for not merging user and package priors. See #474.
- Added user settable primary event priors to the latent model. See #474.
- Added a marginalised likelihood to the latent model. See #474.
- Generalised the stan reparametrisation feature to work across all distributions without manual specification by generating stan code with `brms` and then extracting the reparameterisation. See #474.
- Added a `transform_data` S3 method to allow for data to be transformed for specific models. This is specifically useful for the marginal model at the moment as it allows reducing the data to its unique strata. See #474.

## Documentation

- Brings the README into line with `epinowcast` standards. See #467.
- Switched over to using the marginal model as default in documentation. See #426.
- Added helper functions for new variables to avoid code duplication in vignettes. See #426.

# epidist 0.1.0

Expand Down
10 changes: 7 additions & 3 deletions R/epidist.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,20 @@ epidist <- function(data, formula = mu ~ 1,
epidist_formula <- epidist_formula(
data = data, family = epidist_family, formula = formula
)
transformed_data <- epidist_transform_data(
data, epidist_family, epidist_formula
)
epidist_prior <- epidist_prior(
data = data, family = epidist_family, formula = epidist_formula, prior,
data = transformed_data, family = epidist_family,
formula = epidist_formula, prior,
merge = merge_priors
)
epidist_stancode <- epidist_stancode(
data = data, family = epidist_family, formula = epidist_formula
data = transformed_data, family = epidist_family, formula = epidist_formula
)
fit <- fn(
formula = epidist_formula, family = epidist_family, prior = epidist_prior,
stanvars = epidist_stancode, data = data, ...
stanvars = epidist_stancode, data = transformed_data, ...
)
class(fit) <- c(class(fit), "epidist_fit")
return(fit)
Expand Down
9 changes: 6 additions & 3 deletions R/latent_model.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#' Convert an object to an `epidist_latent_model` object
#'
#' @param data An object to be converted to the class `epidist_latent_model`
#' @param ... Additional arguments passed to methods.
#' @family latent_model
#' @export
as_epidist_latent_model <- function(data) {
as_epidist_latent_model <- function(data, ...) {
UseMethod("as_epidist_latent_model")
}


#' The latent model method for `epidist_linelist_data` objects
#'
#' @param data An `epidist_linelist_data` object
#' @param ... Not used in this method.
#' @method as_epidist_latent_model epidist_linelist_data
#' @family latent_model
#' @autoglobal
#' @export
as_epidist_latent_model.epidist_linelist_data <- function(data) {
as_epidist_latent_model.epidist_linelist_data <- function(data, ...) {
assert_epidist(data)
data <- data |>
mutate(
Expand All @@ -38,10 +40,11 @@ as_epidist_latent_model.epidist_linelist_data <- function(data) {
#' Class constructor for `epidist_latent_model` objects
#'
#' @param data An object to be set with the class `epidist_latent_model`
#' @param ... Additional arguments passed to methods.
#' @returns An object of class `epidist_latent_model`
#' @family latent_model
#' @export
new_epidist_latent_model <- function(data) {
new_epidist_latent_model <- function(data, ...) {
class(data) <- c("epidist_latent_model", class(data))
return(data)
}
Expand Down
Loading
Loading