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

n_synth default with given evidence #37

Merged
merged 1 commit into from
Feb 12, 2025
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 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.

Loading