Skip to content

Commit

Permalink
deal with review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs committed Nov 21, 2024
1 parent 57fb924 commit 2e6cd34
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 26 deletions.
14 changes: 7 additions & 7 deletions R/gen.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#'
#' This function creates a function that draws from the posterior predictive
#' distribution for a latent model using [primarycensored::rpcens()] to handle
#' censoring and truncation. The returned function takes a prep argument from
#' censoring and truncation. The returned function takes a `prep` argument from
#' `brms` and returns posterior predictions. This is used internally by
#' [brms::posterior_predict()] to generate predictions for latent models.
#'
#' @inheritParams epidist_family_model
#' @inheritParams epidist_family
#'
#' @return A function that takes a prep argument from brms and returns a matrix
#' of posterior predictions, with one row per posterior draw and one column
#' per observation. The prep object must have the following variables:
#' @return A function that takes a `prep` argument from brms and returns a
#' matrix of posterior predictions, with one row per posterior draw and one
#' column per observation. The `prep` object must have the following variables:
#' * `vreal1`: relative observation time
#' * `vreal2`: primary event window
#' * `vreal3`: secondary event window
Expand Down Expand Up @@ -53,11 +53,11 @@ epidist_gen_posterior_predict <- function(family) {
#'
#' This function creates a function that calculates the expected value of the
#' posterior predictive distribution for a latent model. The returned function
#' takes a prep argument (from brms) and returns posterior expected values.
#' takes a `prep` argument (from brms) and returns posterior expected values.
#' This is used internally by [brms::posterior_epred()] to calculate expected
#' values for latent models.
#'
#' @inheritParams epidist_family_model
#' @inheritParams epidist_family
#'
#' @return A function that takes a prep argument from brms and returns a matrix
#' of posterior expected values, with one row per posterior draw and one column
Expand Down
2 changes: 1 addition & 1 deletion R/latent_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ epidist_family_model.epidist_latent_model <- function(
#'
#' @seealso [brms::log_lik()] for details on the brms log likelihood interface.
#'
#' @inheritParams epidist_family_model
#' @inheritParams epidist_family
#'
#' @return A function that calculates the log likelihood for a single
#' observation. The prep object must have the following variables:
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
#' @param prefix Character string prefix of the brms function to get (e.g.
#' "log_lik")
#'
#' @param family A brms family object
#' @inheritParams epidist_family
#' @return The requested brms function
#' @keywords internal
.get_brms_fn <- function(prefix, family) {
Expand Down
7 changes: 6 additions & 1 deletion man/dot-get_brms_fn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions man/epidist_gen_log_lik_latent.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions man/epidist_gen_posterior_epred.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions man/epidist_gen_posterior_predict.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vignettes/ebola.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ ranef(fit_sex_district)

To go further than summaries of the fitted model, we recommend using the `tidybayes` package.
For example, to obtain the posterior expectation of the delay distribution, under no censoring or truncation, we may use the `modelr::data_grid()` function in combination with the `tidybayes::add_epred_draws()` function.
The `tidybayes::add_epred_draws()` function uses the (internal) `posterior_epred_latent_lognormal()` function implemented in `epidist` for the `latent_lognormal` custom `brms` family.
The `tidybayes::add_epred_draws()` function uses the `epidist_gen_posterior_predict()` function to generate a posterior prediction function for the `lognormal()` distribution.

In Figure \@ref(fig:epred) we show the posterior expectation of the delay distribution for each of the three fitted models.
Figure \@ref(fig:epred)B illustrates the higher mean of men as compared with women.
Expand Down
8 changes: 4 additions & 4 deletions vignettes/epidist.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ fit <- epidist(
)
```

**Note that here we use the default `rstan` backend but we generally recommend using the `cmdstanr` backend for faster sampling and additional features.**
**This can be set using `backend = "cmdstanr"` after following the installing CmdStan instructions in the README.**

The `fit` object is a `brmsfit` object containing MCMC samples from each of the parameters in the model, shown in the table below.
Many of these parameters (e.g. `swindow` and `pwindow`) are the so called latent variables, and have lengths corresponding to the `sample_size`.

Expand All @@ -307,9 +310,6 @@ data.frame(
Users familiar with Stan and `brms`, can work with `fit` directly.
Any tool that supports `brms` fitted model objects will be compatible with `fit`.

**Note that here we use the default `rstan` backend but we generally recommend using the `cmdstanr` backend for faster sampling and additional features.**
**This can be set using `backend = "cmdstanr"` after following the installing CmdStan instructions in the README.**

For example, we can use the built in `summary()` function

```{r}
Expand Down Expand Up @@ -341,7 +341,7 @@ ggplot() +
data = data.frame(x = c(0, 30)),
aes(x = x),
fun = dlnorm,
linewidth = 2,
linewidth = 1.5,
args = list(
meanlog = secondary_dist[["mu"]],
sdlog = secondary_dist[["sigma"]]
Expand Down

0 comments on commit 2e6cd34

Please sign in to comment.