diff --git a/NAMESPACE b/NAMESPACE index 83cc4fcb4..c7d355347 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,11 +23,13 @@ S3method(epidist_formula_model,epidist_latent_model) S3method(epidist_model_prior,default) S3method(epidist_stancode,default) S3method(epidist_stancode,epidist_latent_model) +export(Gamma) export(add_mean_sd) export(as_epidist_latent_model) export(as_epidist_linelist_data) export(as_epidist_naive_model) export(assert_epidist) +export(bf) export(epidist) export(epidist_diagnostics) export(epidist_family) @@ -42,6 +44,7 @@ export(epidist_stancode) export(is_epidist_latent_model) export(is_epidist_linelist_data) export(is_epidist_naive_model) +export(lognormal) export(new_epidist_latent_model) export(new_epidist_linelist_data) export(new_epidist_naive_model) @@ -52,10 +55,13 @@ export(simulate_exponential_cases) export(simulate_gillespie) export(simulate_secondary) export(simulate_uniform_cases) +export(weibull) import(ggplot2) importFrom(brms,bf) +importFrom(brms,lognormal) importFrom(brms,prior) importFrom(brms,stanvar) +importFrom(brms,weibull) importFrom(checkmate,assert_class) importFrom(checkmate,assert_data_frame) importFrom(checkmate,assert_date) @@ -75,6 +81,7 @@ importFrom(dplyr,mutate) importFrom(dplyr,select) importFrom(lubridate,days) importFrom(lubridate,is.timepoint) +importFrom(stats,Gamma) importFrom(stats,as.formula) importFrom(stats,setNames) importFrom(tibble,tibble) diff --git a/R/epidist.R b/R/epidist.R index 74c1632e1..c7d5035ae 100644 --- a/R/epidist.R +++ b/R/epidist.R @@ -9,8 +9,9 @@ #' @param family A description of the response distribution and link function to #' be used in the model. Every family function has a link argument allowing #' users to specify the link function to be applied on the response variable. -#' If not specified, default links are used. For details of supported families -#' see [brmsfamily()]. +#' If not specified, default links are used. For details of all supported +#' families see [brmsfamily()]. Commonly used, such as [lognormal()], are also +#' reexported as part of `epidist`. #' @param prior One or more `brmsprior` objects created by [brms::set_prior()] #' or related functions. These priors are passed to [epidist_prior()] in the #' `prior` argument. @@ -34,7 +35,7 @@ epidist <- function(data, formula, family, prior, fn, ...) { #' @family fit #' @export epidist.default <- function(data, formula = mu ~ 1, - family = "lognormal", prior = NULL, + family = lognormal(), prior = NULL, fn = brms::brm, ...) { assert_epidist(data) epidist_family <- epidist_family(data, family) diff --git a/R/family.R b/R/family.R index a3758f45b..9512b9019 100644 --- a/R/family.R +++ b/R/family.R @@ -8,7 +8,7 @@ #' @inheritParams epidist #' @family family #' @export -epidist_family <- function(data, family = "lognormal", ...) { +epidist_family <- function(data, family = lognormal(), ...) { assert_epidist(data) family <- brms:::validate_family(family) # nolint class(family) <- c(family$family, class(family)) diff --git a/R/reexports.R b/R/reexports.R new file mode 100644 index 000000000..d4a60e421 --- /dev/null +++ b/R/reexports.R @@ -0,0 +1,15 @@ +#' @importFrom brms lognormal +#' @export +brms::lognormal + +#' @importFrom brms weibull +#' @export +brms::weibull + +#' @importFrom stats Gamma +#' @export +stats::Gamma + +#' @importFrom brms bf +#' @export +brms::bf diff --git a/_pkgdown.yml b/_pkgdown.yml index a371ea562..7d0e1cf9c 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -84,3 +84,6 @@ reference: - title: Diagnostic functions contents: - has_concept("diagnostics") +- title: Reexported functions + contents: + - reexports diff --git a/man/dot-add_dpar_info.Rd b/man/dot-add_dpar_info.Rd index 444cbbc75..ac4460d66 100644 --- a/man/dot-add_dpar_info.Rd +++ b/man/dot-add_dpar_info.Rd @@ -10,8 +10,9 @@ \item{family}{A description of the response distribution and link function to be used in the model. Every family function has a link argument allowing users to specify the link function to be applied on the response variable. -If not specified, default links are used. For details of supported families -see \code{\link[=brmsfamily]{brmsfamily()}}.} +If not specified, default links are used. For details of all supported +families see \code{\link[=brmsfamily]{brmsfamily()}}. Commonly used, such as \code{\link[=lognormal]{lognormal()}}, are also +reexported as part of \code{epidist}.} } \description{ Includes additional information (link functions and parameter bound) about diff --git a/man/epidist.Rd b/man/epidist.Rd index f6663d66c..a9a4ab7c0 100644 --- a/man/epidist.Rd +++ b/man/epidist.Rd @@ -18,8 +18,9 @@ parameters.} \item{family}{A description of the response distribution and link function to be used in the model. Every family function has a link argument allowing users to specify the link function to be applied on the response variable. -If not specified, default links are used. For details of supported families -see \code{\link[=brmsfamily]{brmsfamily()}}.} +If not specified, default links are used. For details of all supported +families see \code{\link[=brmsfamily]{brmsfamily()}}. Commonly used, such as \code{\link[=lognormal]{lognormal()}}, are also +reexported as part of \code{epidist}.} \item{prior}{One or more \code{brmsprior} objects created by \code{\link[brms:set_prior]{brms::set_prior()}} or related functions. These priors are passed to \code{\link[=epidist_prior]{epidist_prior()}} in the diff --git a/man/epidist.default.Rd b/man/epidist.default.Rd index 18353ca08..3de4f4b8f 100644 --- a/man/epidist.default.Rd +++ b/man/epidist.default.Rd @@ -7,7 +7,7 @@ \method{epidist}{default}( data, formula = mu ~ 1, - family = "lognormal", + family = lognormal(), prior = NULL, fn = brms::brm, ... @@ -25,8 +25,9 @@ parameters.} \item{family}{A description of the response distribution and link function to be used in the model. Every family function has a link argument allowing users to specify the link function to be applied on the response variable. -If not specified, default links are used. For details of supported families -see \code{\link[=brmsfamily]{brmsfamily()}}.} +If not specified, default links are used. For details of all supported +families see \code{\link[=brmsfamily]{brmsfamily()}}. Commonly used, such as \code{\link[=lognormal]{lognormal()}}, are also +reexported as part of \code{epidist}.} \item{prior}{One or more \code{brmsprior} objects created by \code{\link[brms:set_prior]{brms::set_prior()}} or related functions. These priors are passed to \code{\link[=epidist_prior]{epidist_prior()}} in the diff --git a/man/epidist_family.Rd b/man/epidist_family.Rd index bb4bdc615..ba7960fc7 100644 --- a/man/epidist_family.Rd +++ b/man/epidist_family.Rd @@ -4,7 +4,7 @@ \alias{epidist_family} \title{Define \code{epidist} family} \usage{ -epidist_family(data, family = "lognormal", ...) +epidist_family(data, family = lognormal(), ...) } \arguments{ \item{data}{A \code{data.frame} containing line list data.} @@ -12,8 +12,9 @@ epidist_family(data, family = "lognormal", ...) \item{family}{A description of the response distribution and link function to be used in the model. Every family function has a link argument allowing users to specify the link function to be applied on the response variable. -If not specified, default links are used. For details of supported families -see \code{\link[=brmsfamily]{brmsfamily()}}.} +If not specified, default links are used. For details of all supported +families see \code{\link[=brmsfamily]{brmsfamily()}}. Commonly used, such as \code{\link[=lognormal]{lognormal()}}, are also +reexported as part of \code{epidist}.} \item{...}{Additional arguments passed to \code{fn} method.} } diff --git a/man/epidist_family_prior.Rd b/man/epidist_family_prior.Rd index 82ce122dd..48344ce2b 100644 --- a/man/epidist_family_prior.Rd +++ b/man/epidist_family_prior.Rd @@ -10,8 +10,9 @@ epidist_family_prior(family, ...) \item{family}{A description of the response distribution and link function to be used in the model. Every family function has a link argument allowing users to specify the link function to be applied on the response variable. -If not specified, default links are used. For details of supported families -see \code{\link[=brmsfamily]{brmsfamily()}}.} +If not specified, default links are used. For details of all supported +families see \code{\link[=brmsfamily]{brmsfamily()}}. Commonly used, such as \code{\link[=lognormal]{lognormal()}}, are also +reexported as part of \code{epidist}.} \item{...}{Additional arguments passed to \code{fn} method.} } diff --git a/man/epidist_family_prior.default.Rd b/man/epidist_family_prior.default.Rd index eb2677626..3139ac0a4 100644 --- a/man/epidist_family_prior.default.Rd +++ b/man/epidist_family_prior.default.Rd @@ -10,8 +10,9 @@ \item{family}{A description of the response distribution and link function to be used in the model. Every family function has a link argument allowing users to specify the link function to be applied on the response variable. -If not specified, default links are used. For details of supported families -see \code{\link[=brmsfamily]{brmsfamily()}}.} +If not specified, default links are used. For details of all supported +families see \code{\link[=brmsfamily]{brmsfamily()}}. Commonly used, such as \code{\link[=lognormal]{lognormal()}}, are also +reexported as part of \code{epidist}.} \item{formula}{An object of class \link[stats:formula]{stats::formula} or \link[brms:brmsformula]{brms::brmsformula} (or one that can be coerced to those classes). A symbolic description of the diff --git a/man/epidist_family_prior.lognormal.Rd b/man/epidist_family_prior.lognormal.Rd index 2708ba9ff..2830dd82e 100644 --- a/man/epidist_family_prior.lognormal.Rd +++ b/man/epidist_family_prior.lognormal.Rd @@ -10,8 +10,9 @@ \item{family}{A description of the response distribution and link function to be used in the model. Every family function has a link argument allowing users to specify the link function to be applied on the response variable. -If not specified, default links are used. For details of supported families -see \code{\link[=brmsfamily]{brmsfamily()}}.} +If not specified, default links are used. For details of all supported +families see \code{\link[=brmsfamily]{brmsfamily()}}. Commonly used, such as \code{\link[=lognormal]{lognormal()}}, are also +reexported as part of \code{epidist}.} \item{formula}{An object of class \link[stats:formula]{stats::formula} or \link[brms:brmsformula]{brms::brmsformula} (or one that can be coerced to those classes). A symbolic description of the diff --git a/man/epidist_family_reparam.Rd b/man/epidist_family_reparam.Rd index 27ecba0a4..13a39547b 100644 --- a/man/epidist_family_reparam.Rd +++ b/man/epidist_family_reparam.Rd @@ -10,8 +10,9 @@ epidist_family_reparam(family, ...) \item{family}{A description of the response distribution and link function to be used in the model. Every family function has a link argument allowing users to specify the link function to be applied on the response variable. -If not specified, default links are used. For details of supported families -see \code{\link[=brmsfamily]{brmsfamily()}}.} +If not specified, default links are used. For details of all supported +families see \code{\link[=brmsfamily]{brmsfamily()}}. Commonly used, such as \code{\link[=lognormal]{lognormal()}}, are also +reexported as part of \code{epidist}.} \item{...}{Additional arguments passed to \code{fn} method.} } diff --git a/man/epidist_family_reparam.default.Rd b/man/epidist_family_reparam.default.Rd index 4fc4531de..8ab4d39ce 100644 --- a/man/epidist_family_reparam.default.Rd +++ b/man/epidist_family_reparam.default.Rd @@ -10,8 +10,9 @@ \item{family}{A description of the response distribution and link function to be used in the model. Every family function has a link argument allowing users to specify the link function to be applied on the response variable. -If not specified, default links are used. For details of supported families -see \code{\link[=brmsfamily]{brmsfamily()}}.} +If not specified, default links are used. For details of all supported +families see \code{\link[=brmsfamily]{brmsfamily()}}. Commonly used, such as \code{\link[=lognormal]{lognormal()}}, are also +reexported as part of \code{epidist}.} \item{...}{Additional arguments passed to \code{fn} method.} } diff --git a/man/epidist_family_reparam.gamma.Rd b/man/epidist_family_reparam.gamma.Rd index 70acfa454..090cae603 100644 --- a/man/epidist_family_reparam.gamma.Rd +++ b/man/epidist_family_reparam.gamma.Rd @@ -10,8 +10,9 @@ \item{family}{A description of the response distribution and link function to be used in the model. Every family function has a link argument allowing users to specify the link function to be applied on the response variable. -If not specified, default links are used. For details of supported families -see \code{\link[=brmsfamily]{brmsfamily()}}.} +If not specified, default links are used. For details of all supported +families see \code{\link[=brmsfamily]{brmsfamily()}}. Commonly used, such as \code{\link[=lognormal]{lognormal()}}, are also +reexported as part of \code{epidist}.} \item{...}{Additional arguments passed to \code{fn} method.} } diff --git a/man/reexports.Rd b/man/reexports.Rd new file mode 100644 index 000000000..afd1c9f79 --- /dev/null +++ b/man/reexports.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/reexports.R +\docType{import} +\name{reexports} +\alias{reexports} +\alias{lognormal} +\alias{weibull} +\alias{Gamma} +\alias{bf} +\title{Objects exported from other packages} +\keyword{internal} +\description{ +These objects are imported from other packages. Follow the links +below to see their documentation. + +\describe{ + \item{brms}{\code{\link[brms:brmsformula]{bf}}, \code{\link[brms:brmsfamily]{lognormal}}, \code{\link[brms:brmsfamily]{weibull}}} + + \item{stats}{\code{\link[stats:family]{Gamma}}} +}} + diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 0ce7a4f78..1d638f3a9 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -112,14 +112,14 @@ if (not_on_cran()) { ) fit_gamma <- epidist( - data = prep_obs_gamma, family = stats::Gamma(link = "log"), + data = prep_obs_gamma, family = Gamma(link = "log"), seed = 1, chains = 2, cores = 2, silent = 2, refresh = 0, backend = "cmdstanr" ) fit_sex <- epidist( data = prep_obs_sex, - formula = brms::bf(mu ~ 1 + sex, sigma ~ 1 + sex), + formula = bf(mu ~ 1 + sex, sigma ~ 1 + sex), seed = 1, silent = 2, refresh = 0, cores = 2, chains = 2, backend = "cmdstanr" ) diff --git a/tests/testthat/test-family.R b/tests/testthat/test-family.R index 8fb1f0f46..adeb50443 100644 --- a/tests/testthat/test-family.R +++ b/tests/testthat/test-family.R @@ -11,7 +11,7 @@ test_that("epidist_family gives an error when passed inappropriate family input" }) test_that("the family argument in epidist_family passes as expected for brms and stats family objects, as well as strings", { # nolint: line_length_linter. - family_lognormal <- epidist_family(prep_obs, family = brms::lognormal()) + family_lognormal <- epidist_family(prep_obs, family = lognormal()) expect_identical(family_lognormal$name, "latent_lognormal") family_gamma <- epidist_family(prep_obs, family = Gamma(link = "log")) expect_identical(family_gamma$name, "latent_gamma") diff --git a/tests/testthat/test-formula.R b/tests/testthat/test-formula.R index f2ceeb9ba..c93f8f829 100644 --- a/tests/testthat/test-formula.R +++ b/tests/testthat/test-formula.R @@ -1,6 +1,6 @@ prep_obs_gamma <- as_epidist_latent_model(sim_obs_gamma) -family_lognormal <- epidist_family(prep_obs, family = brms::lognormal()) +family_lognormal <- epidist_family(prep_obs, family = lognormal()) test_that("epidist_formula with default settings produces a brmsformula with the correct intercept only formula", { # nolint: line_length_linter. form <- epidist_formula( @@ -18,7 +18,7 @@ test_that("epidist_formula with default settings produces a brmsformula with the ) form_explicit <- epidist_formula( prep_obs, - family = family_lognormal, formula = brms::bf(mu ~ 1, sigma ~ 1) + family = family_lognormal, formula = bf(mu ~ 1, sigma ~ 1) ) attr(form$pforms$sigma, ".Environment") <- NULL attr(form_explicit$pforms$sigma, ".Environment") <- NULL @@ -30,7 +30,7 @@ test_that("epidist_formula with custom formulas produces a brmsformula with corr form_sex <- epidist_formula( prep_obs, family = family_lognormal, - formula = brms::bf(mu ~ 1 + sex, sigma ~ 1 + sex) + formula = bf(mu ~ 1 + sex, sigma ~ 1 + sex) ) expect_s3_class(form_sex, "brmsformula") expect_identical( @@ -48,28 +48,28 @@ test_that("epidist_formula with custom formulas errors for incorrect custom form epidist_formula( prep_obs, family = family_lognormal, - formula = brms::bf(mu ~ 1 + age, sigma ~ 1) + formula = bf(mu ~ 1 + age, sigma ~ 1) ) ) expect_error( epidist_formula( prep_obs, family = family_lognormal, - formula = brms::bf(mu ~ 1, sigma ~ 1 + age) + formula = bf(mu ~ 1, sigma ~ 1 + age) ) ) expect_error( epidist_formula( prep_obs, family = family_lognormal, - formula = brms::bf(list(), sigma ~ 1) + formula = bf(list(), sigma ~ 1) ) ) expect_error( epidist_formula( prep_obs, family = family_lognormal, - formula = brms::bf(mu ~ 1, shape ~ 1) + formula = bf(mu ~ 1, shape ~ 1) ) ) }) diff --git a/tests/testthat/test-int-latent_model.R b/tests/testthat/test-int-latent_model.R index db269ffe1..5f8cc3842 100644 --- a/tests/testthat/test-int-latent_model.R +++ b/tests/testthat/test-int-latent_model.R @@ -29,7 +29,7 @@ test_that("epidist.epidist_latent_model samples from the prior according to marg cores = 2 ) pred <- predict_delay_parameters(prior_samples) - family <- brms::lognormal() + family <- lognormal() epidist_family <- epidist_family(data = prep_obs, family = family) epidist_formula <- epidist_formula( data = prep_obs, @@ -45,7 +45,7 @@ test_that("epidist.epidist_latent_model samples from the prior according to marg param1 <- extract_normal_parameters_brms(epidist_prior[1, ]) param2 <- extract_normal_parameters_brms(epidist_prior[2, ]) samples1 <- rnorm(1000, mean = param1$mean, sd = param1$sd) - samples2 <- rnorm(1000, mean = param2$mean, sd = param2$sd) + samples2 <- exp(rnorm(1000, mean = param2$mean, sd = param2$sd)) # suppressWarnings here used to prevent warnings about ties ks1 <- suppressWarnings(stats::ks.test(pred$mu, samples1)) ks2 <- suppressWarnings(stats::ks.test(pred$sigma, samples2)) @@ -67,7 +67,7 @@ test_that("epidist.epidist_latent_model fits, the MCMC converges, and the draws set.seed(1) fit_constant <- epidist( data = prep_obs, - formula = brms::bf(mu ~ 1, sigma = 1), + formula = bf(mu ~ 1, sigma = 1), seed = 1, silent = 2, refresh = 0, cores = 2, @@ -86,7 +86,7 @@ test_that("epidist.epidist_latent_model Stan code has no syntax errors", { # nol set.seed(1) stancode_string <- epidist( data = prep_obs, - family = "lognormal", + family = lognormal(), seed = 1, silent = 2, refresh = 0, fn = brms::make_stancode @@ -111,7 +111,7 @@ test_that("epidist.epidist_latent_model Stan code has no syntax errors and compi skip_on_cran() stancode_gamma <- epidist( data = prep_obs_gamma, - family = stats::Gamma(link = "log"), + family = Gamma(link = "log"), formula = mu ~ 1, cores = 2, fn = brms::make_stancode @@ -153,7 +153,7 @@ test_that("epidist.epidist_latent_model Stan code has no syntax errors for an al skip_on_cran() stancode_sex <- epidist( data = prep_obs_sex, - formula = brms::bf(mu ~ 1 + sex, sigma ~ 1 + sex), + formula = bf(mu ~ 1 + sex, sigma ~ 1 + sex), fn = brms::make_stancode, cores = 2 ) @@ -168,8 +168,17 @@ test_that("epidist.epidist_latent_model recovers a sex effect", { # nolint: line skip_on_cran() set.seed(1) draws <- posterior::as_draws_df(fit_sex$fit) - expect_equal(mean(draws$b_sex), -0.73, tolerance = 0.2) - expect_equal(mean(draws$b_sigma_sex), 0.43, tolerance = 0.2) + expect_equal(mean(draws$b_Intercept), meanlog_m, tolerance = 0.1) + expect_equal( + mean(draws$b_Intercept + draws$b_sex), meanlog_f, + tolerance = 0.1 + ) + expect_equal(mean(exp(draws$b_sigma_Intercept)), sdlog_m, tolerance = 0.1) + expect_equal( + mean(exp(draws$b_sigma_Intercept + draws$b_sigma_sex)), + sdlog_f, + tolerance = 0.1 + ) expect_s3_class(fit_sex, "brmsfit") expect_s3_class(fit_sex, "epidist_fit") expect_convergence(fit_sex) diff --git a/tests/testthat/test-latent_model.R b/tests/testthat/test-latent_model.R index 357008fde..579af69fc 100644 --- a/tests/testthat/test-latent_model.R +++ b/tests/testthat/test-latent_model.R @@ -10,7 +10,7 @@ test_that("as_epidist_latent_model.epidist_linelist_data errors when passed inco }) # Make this data available for other tests -family_lognormal <- epidist_family(prep_obs, family = brms::lognormal()) +family_lognormal <- epidist_family(prep_obs, family = lognormal()) test_that("is_epidist_latent_model returns TRUE for correct input", { # nolint: line_length_linter. expect_true(is_epidist_latent_model(prep_obs)) @@ -48,7 +48,7 @@ test_that("epidist_stancode.epidist_latent_model produces valid stanvars", { # n epidist_family <- epidist_family(prep_obs) epidist_formula <- epidist_formula( prep_obs, epidist_family, - formula = brms::bf(mu ~ 1) + formula = bf(mu ~ 1) ) stancode <- epidist_stancode( prep_obs, diff --git a/tests/testthat/test-naive_model.R b/tests/testthat/test-naive_model.R index b63c95865..de691d49a 100644 --- a/tests/testthat/test-naive_model.R +++ b/tests/testthat/test-naive_model.R @@ -10,7 +10,7 @@ test_that("as_epidist_naive_model.data.frame errors when passed incorrect inputs }) # Make this data available for other tests -family_lognormal <- epidist_family(sim_obs, family = brms::lognormal()) +family_lognormal <- epidist_family(sim_obs, family = lognormal()) test_that("is_epidist_naive_model returns TRUE for correct input", { # nolint: line_length_linter. expect_true(is_epidist_naive_model(prep_naive_obs)) diff --git a/tests/testthat/test-prior.R b/tests/testthat/test-prior.R index fa77fba4e..aab1d08f8 100644 --- a/tests/testthat/test-prior.R +++ b/tests/testthat/test-prior.R @@ -1,7 +1,7 @@ test_that("epidist_prior with default settings produces an object of the right class", { # nolint: line_length_linter. data <- as_epidist_latent_model(sim_obs) - family <- brms::lognormal() - formula <- brms::bf(mu ~ 1, sigma ~ 1) + family <- lognormal() + formula <- bf(mu ~ 1, sigma ~ 1) epidist_family <- epidist_family(data, family) epidist_formula <- epidist_formula( data = data, family = epidist_family, formula = formula diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index e7b602a75..f0012d6ed 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -30,25 +30,25 @@ cli::test_that_cli(".replace_prior errors when passed a new prior without a matc }) test_that(".add_dpar_info works as expected for the lognormal and gamma families", { # nolint: line_length_linter. - lognormal_extra <- .add_dpar_info(brms::lognormal()) + lognormal_extra <- .add_dpar_info(lognormal()) expect_identical(lognormal_extra$other_links, "log") expect_identical(lognormal_extra$other_bounds, list(list(lb = "0", ub = ""))) - gamma_extra <- .add_dpar_info(brms:::validate_family(stats::Gamma())) # nolint + gamma_extra <- .add_dpar_info(brms:::validate_family(Gamma())) # nolint expect_null(gamma_extra$other_links) expect_identical(gamma_extra$other_bounds, list(list(lb = "0", ub = ""))) }) test_that(".make_intercepts_explicit creates a formula which is the same as if it had been explicitly created", { # nolint: line_length_linter. prep_obs <- as_epidist_latent_model(sim_obs) - epidist_family <- epidist_family(prep_obs, family = "lognormal") + epidist_family <- epidist_family(prep_obs, family = lognormal()) formula <- brms:::validate_formula( # nolint - formula = brms::bf(mu ~ 1), + formula = bf(mu ~ 1), data = prep_obs, family = epidist_family ) formula <- .make_intercepts_explicit(formula) formula_explicit <- brms:::validate_formula( # nolint - formula = brms::bf(mu ~ 1, sigma ~ 1), + formula = bf(mu ~ 1, sigma ~ 1), data = prep_obs, family = epidist_family ) @@ -59,9 +59,9 @@ test_that(".make_intercepts_explicit creates a formula which is the same as if i test_that(".make_intercepts_explicit does not add an intercept if the distributional parameter is set to be fixed", { # nolint: line_length_linter. prep_obs <- as_epidist_latent_model(sim_obs) - epidist_family <- epidist_family(prep_obs, family = "lognormal") + epidist_family <- epidist_family(prep_obs, family = lognormal()) formula <- brms:::validate_formula( # nolint - formula = brms::bf(mu ~ 1, sigma = 1), + formula = bf(mu ~ 1, sigma = 1), data = prep_obs, family = epidist_family ) diff --git a/vignettes/faq.Rmd b/vignettes/faq.Rmd index 5a9a9e08f..8121f0355 100644 --- a/vignettes/faq.Rmd +++ b/vignettes/faq.Rmd @@ -112,12 +112,14 @@ Instead, we used [prior predictive checking](https://mc-stan.org/docs/stan-users For example, for the `brms::lognormal()` latent individual model, we suggest the following prior distributions for the `brms` `mu` and `sigma` intercept parameters: ```{r} -family <- "lognormal" +# Note that we export lognormal() as part of epidist hence no need for brms:: +family <- lognormal() epidist_family <- epidist_family(data, family) epidist_formula <- epidist_formula( data, - family = epidist_family, formula = mu ~ 1 + family = epidist_family, + formula = mu ~ 1 ) # NULL here means no replacing priors from the user! @@ -140,7 +142,7 @@ set.seed(1) fit_ppc <- epidist( data = data, formula = mu ~ 1, - family = "lognormal", + family = lognormal(), sample_prior = "only", seed = 1 )