R/matchfailed.R

Defines functions subproblemSuccess matchfailed

Documented in matchfailed subproblemSuccess

#' @export
#' @rdname matched
matchfailed <- function(x) {
  failed <- !subproblemSuccess(x)
  grps <- attr(x, "subproblem")
  levels(grps) <- failed
  return(as.logical(grps))
}

#' (Internal) Report successful subproblems.
#'
#' \code{\link{fullmatch}} can break up a large matching problem into smaller
#' subproblems (for example, using strata defined by \code{\link{exactMatch}}).
#' This function lists the subproblems in a match and list whether at least on
#' treated unit was matched in subproblem. Subproblems that have no matched
#' treated units are said to have "failed."
#'
#' @param x The result of \code{\link{fullmatch}} or \code{\link{pairmatch}}.
#' @return A named logical vector indicating either success or failure for each subproblem.
#' @keywords internal
subproblemSuccess <- function(x) {
  grps <- attr(x, "subproblem")
  failed <- vapply(split(x, grps), function(x) {
    all(is.na(x) | grepl("\\.NA$", x))
  }, logical(1))
  return(!failed)
}

Try the optmatch package in your browser

Any scripts or data that you put into this service are public.

optmatch documentation built on Sept. 19, 2024, 9:06 a.m.