From 947a0b885bbf19a55c4292dba91695b87d2ea34f Mon Sep 17 00:00:00 2001 From: Noah Greifer Date: Fri, 19 Jan 2024 10:46:20 -0500 Subject: [PATCH] Fixed issue with tibble dataset, discard, and optimal/full matching (#185) --- DESCRIPTION | 2 +- MatchIt.Rproj | 1 + NEWS.md | 4 ++++ R/matchit2full.R | 2 +- R/matchit2optimal.R | 4 ++-- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3a9c907e..17606cf5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: MatchIt -Version: 4.5.5 +Version: 4.5.5.9000 Title: Nonparametric Preprocessing for Parametric Causal Inference Description: Selects matched samples of the original treated and control groups with similar covariate distributions -- can be diff --git a/MatchIt.Rproj b/MatchIt.Rproj index 6291372e..f30c4eca 100644 --- a/MatchIt.Rproj +++ b/MatchIt.Rproj @@ -18,3 +18,4 @@ BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source PackageCheckArgs: --as-cran +PackageRoxygenize: rd,collate,namespace diff --git a/NEWS.md b/NEWS.md index e47a1717..f6817261 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,10 @@ output: `MatchIt` News and Updates ====== +# MatchIt (development version) + +* Fixed a bug when using `method = "optimal"` or `method = "full"` with `discard` specified and `data` given as a tibble (`tbl_df` object). (#185) + # MatchIt 4.5.5 * When using `method = "cardinality"`, a new solver, HiGHS, can be requested by setting `solver = "highs"`, which relies on the `highs` package. This is much faster and more reliable than GLPK and is free and easy to install as a regular R package with no additional requirements. diff --git a/R/matchit2full.R b/R/matchit2full.R index 4bc10f02..8da98e25 100644 --- a/R/matchit2full.R +++ b/R/matchit2full.R @@ -303,7 +303,7 @@ matchit2full <- function(treat, formula, data, distance, discarded, mo <- mo[!discarded[treat == focal], !discarded[treat != focal], drop = FALSE] dimnames(mo) <- list(names(treat_)[treat_ == 1], names(treat_)[treat_ == 0]) - mo <- optmatch::match_on(mo, data = data[!discarded,, drop = FALSE]) + mo <- optmatch::match_on(mo, data = as.data.frame(data)[!discarded,, drop = FALSE]) mo <- optmatch::as.InfinitySparseMatrix(mo) #Process antiexact diff --git a/R/matchit2optimal.R b/R/matchit2optimal.R index 415e5857..89c63b7a 100644 --- a/R/matchit2optimal.R +++ b/R/matchit2optimal.R @@ -244,7 +244,7 @@ matchit2optimal <- function(treat, formula, data, distance, discarded, ratio = 1, s.weights = NULL, caliper = NULL, mahvars = NULL, exact = NULL, estimand = "ATT", verbose = FALSE, - is.full.mahalanobis, antiexact = NULL, ...) { + is.full.mahalanobis, antiexact = NULL, ...) { rlang::check_installed("optmatch") @@ -360,7 +360,7 @@ matchit2optimal <- function(treat, formula, data, distance, discarded, mo <- mo[!discarded[treat == focal], !discarded[treat != focal], drop = FALSE] dimnames(mo) <- list(names(treat_)[treat_ == 1], names(treat_)[treat_ == 0]) - mo <- optmatch::match_on(mo, data = data[!discarded,, drop = FALSE]) + mo <- optmatch::match_on(mo, data = as.data.frame(data)[!discarded,, drop = FALSE]) mo <- optmatch::as.InfinitySparseMatrix(mo) #Process antiexact