Skip to content

Commit

Permalink
Merge pull request #37 from bips-hb/rarf_default_n
Browse files Browse the repository at this point in the history
n_synth default with given evidence
  • Loading branch information
mnwright authored Feb 12, 2025
2 parents f9074b8 + dbea66d commit fb3f063
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/forde.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ forde <- function(
dt[NA_share == 1, c('min', 'max') := .(fifelse(is.infinite(min), min_emp, min),
fifelse(is.infinite(max), max_emp, max))]
dt[, c("min_emp", "max_emp") := NULL]
dt[NA_share == 1, mu := (max - min) / 2]
dt[NA_share == 1, mu := (max + min) / 2]
dt[is.na(sigma), sigma := 0]
if (any(dt[, sigma == 0])) {
dt[, new_min := fifelse(!is.finite(min), min(value, na.rm = TRUE), min), by = variable]
Expand Down
17 changes: 14 additions & 3 deletions R/shortcut_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ darf <- function(x, query = NULL, ...) {
#'
#' @param x Input data. Integer variables are recoded as ordered factors with
#' a warning. See Details.
#' @param n_synth Number of synthetic samples to generate. Is set to \code{nrow(x)} if
#' \code{NULL}.
#' @param n_synth Number of synthetic samples to generate for unconditional
#' generation with no \code{evidence} given.
#' Number of synthetic samples to generate per \code{evidence} row if \code{evidence}
#' is provided.
#' If \code{NULL}, defaults to \code{nrow(x)} if no \code{evidence} is provided and to
#' \code{1} otherwise.
#' @param ... Extra parameters to be passed to \code{adversarial_rf}, \code{forde}
#' and \code{forge}.
#'
Expand Down Expand Up @@ -122,7 +126,14 @@ rarf <- function(x, n_synth = NULL, ...) {

if (!("params" %in% names(forde_args))) params <- do.call(forde, c(arf = list(arf), x = list(x), forde_args))

if(is.null(n_synth)) n_synth <- nrow(x)
if(is.null(n_synth)) {
if (is.null(forge_args$evidence))
n_synth <- nrow(x)
else {
n_synth <- 1
}
}

do.call(forge, c(params = list(params),
n_synth = list(n_synth),
forge_args))
Expand Down
8 changes: 6 additions & 2 deletions man/rarf.Rd

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

0 comments on commit fb3f063

Please sign in to comment.