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 80: Default generic for epidist method #89

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(epidist,epidist_ltcad)
S3method(epidist,default)
S3method(epidist_family,epidist_ltcad)
S3method(epidist_formula,epidist_ltcad)
S3method(epidist_prepare,default)
Expand Down
20 changes: 0 additions & 20 deletions R/ltcad.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,27 @@
epidist_stancode.epidist_ltcad <- function(data,
family = epidist_family(data)) {
stanvars_version <- epidist_version_stanvar()

Check warning on line 77 in R/ltcad.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/ltcad.R,line=77,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
stanvars_functions <- brms::stanvar(
block = "functions", scode = epidist_stan_chunk("functions.stan")
)

Check warning on line 81 in R/ltcad.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/ltcad.R,line=81,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
family_name <- gsub("latent_", "", family$name)

Check warning on line 83 in R/ltcad.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/ltcad.R,line=83,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
stanvars_functions[[1]]$scode <- gsub(
"family", family_name, stanvars_functions[[1]]$scode
)

Check warning on line 87 in R/ltcad.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/ltcad.R,line=87,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
stanvars_data <- brms::stanvar(
block = "data",
scode = "int wN;",
x = nrow(data[woverlap > 0]),

Check warning on line 91 in R/ltcad.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/ltcad.R,line=91,col=19,[object_usage_linter] no visible binding for global variable 'woverlap'

Check warning on line 91 in R/ltcad.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/ltcad.R,line=91,col=19,[object_usage_linter] no visible binding for global variable 'woverlap'

Check warning on line 91 in R/ltcad.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/ltcad.R,line=91,col=19,[object_usage_linter] no visible binding for global variable 'woverlap'
name = "wN"
) +
brms::stanvar(
block = "data",
scode = "array[N - wN] int noverlap;",
x = data[woverlap == 0][, row_id],

Check warning on line 97 in R/ltcad.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/ltcad.R,line=97,col=33,[object_usage_linter] no visible binding for global variable 'row_id'

Check warning on line 97 in R/ltcad.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/ltcad.R,line=97,col=33,[object_usage_linter] no visible binding for global variable 'row_id'
name = "noverlap"
) +
brms::stanvar(
Expand All @@ -103,7 +103,7 @@
x = data[woverlap > 0][, row_id],
name = "woverlap"
)

Check warning on line 106 in R/ltcad.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/ltcad.R,line=106,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
stanvars_parameters <- brms::stanvar(
block = "parameters", scode = epidist_stan_chunk("parameters.stan")
)
Expand All @@ -119,23 +119,3 @@
stanvars_all <- stanvars_version + stanvars_functions + stanvars_data +
stanvars_parameters + stanvars_tparameters + stanvars_priors
}

#' @method epidist epidist_ltcad
#' @family ltcad
#' @export
epidist.epidist_ltcad <- function(data, formula = epidist_formula(data),
family = epidist_family(data),
priors = epidist_priors(data),
stancode = epidist_stancode(data),
fn = brms::brm,
...) {

fit <- fn(
formula = formula, family = family, stanvars = stancode,
backend = "cmdstanr", data = data, ...
)

class(fit) <- c(class(fit), "epidist_fit")

return(fit)
}
23 changes: 23 additions & 0 deletions R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,26 @@ epidist_stancode <- function(data, ...) {
epidist <- function(data, formula, family, priors, custom_stancode, fn, ...) {
UseMethod("epidist")
}

#' Default method used for interface using `brms`
#'
#' @inheritParams epidist
#' @rdname epidist
#' @method epidist default
#' @family methods
#' @export
epidist.default <- function(data, formula = epidist_formula(data),
family = epidist_family(data),
priors = epidist_priors(data),
stancode = epidist_stancode(data), fn = brms::brm,
...) {

fit <- fn(
formula = formula, family = family, stanvars = stancode,
backend = "cmdstanr", data = data, ...
)

class(fit) <- c(class(fit), "epidist_fit")

return(fit)
}
20 changes: 20 additions & 0 deletions man/epidist.Rd

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

Loading