Comments (14)
My guess is this is a bug, but I also guess the solution would be to remove the discard
option. I'll check on this tomorrow.
from matchit.
I'm still working on your other issue, but the problem with calipers and optimal matching is an issue with opmatch
, not Matchit
, so you should contact the optmatch
maintainers. Essentially, optmatch
functions fail if the matching is "infeasible" (not all treated units receive a matched control). I don't think there is a way around that using the algorithm they use, but you can check with them. If you want to use a caliper, just use nearest neighbor matching.
from matchit.
My guess is this is a bug, but I also guess the solution would be to remove the
discard
option. I'll check on this tomorrow.
Yes, you are correct, by removing discard option, the code worked. However, it's important for us to be able to use common support. Let me know if you need anything else from me to solve this issue. Thank you so much.
from matchit.
I've been looking into this and unfortunately I can't reproduce it. Can you send me a minimal reproducible example (e.g., a dataset with the minimum number of variables required to trigger the error)? If this is only happening with your specific dataset, you can send me a dataset with just the treatment variable, the propensity score, and the exact matching variable. That should be enough to reproduce the problem. Also please let me know which version of MatchIt
you are using. Thanks.
from matchit.
Sure, I attached the dataset as required. I use cov1 as treatment variable and cov2 as exact match variable for optimal matching.
also, I am using 4.5.5 version.
test.xlsx
from matchit.
I also read your response to other peoples' question regarding using caliper width with optimal matching. I tried it on my sample and received a warning message that 'The argument 'caliper' is not used with method = "optimal"
and will be ignored'. Is there a easy way to fix the 'caliper' issue?
R code :
match <- matchit(as.factor(treated) ~ age+ gender2+ ip_30dprior + ed_30dprior+
admits_b6+ er_visits_before6+ urgent_visits_before6+avoid_er_visits_jh_before6+
pcp_total_before6 + spec_total_before6 + telemed_visits_before6 +
mh_ip_before6 + mh_op_prof_before6 +
prs_score_int + hccs+ loh +loed+ cgi+
claimspmpm_total+
asthma_vs + copd_vs + depression_vs+ other_bh_vs + cad_vs +
chf_vs + hypertension_vs + ckd_vs + esrd_vs +malig_neo_vs + transplantpre +
cva_vs+ ra_vs +osteoporosis_vs+ hyperlipid_vs+ subabuse_vs+ diabetes_vs +
financial +lowincome+ lives_alone+ mobility+ housing+ socstability +socsupport+
aerialpresum + rec_score +tot_cci +in_footprint+attributionflag+
cardiology_bucket+ ophthalmology_bucket +gi_bucket + obgyn_bucket +hepatology_bucket+ neurology_bucket+
nephrology_bucket+ endocrinology_bucket + orthopedics_bucket,
data = clarity_r,
method = "optimal",
distance = "glm",
link = "logit",
estimand = "ATT",
#exact = ~claimspmpm_total_cat,
discard = "both",
caliper = 0.25,
standardization.scale = sd,
ratio = 1,
)
from matchit.
Hi, I'm sorry but I cannot reproduce your error using the dataset you sent me. See below.
dat <- xlsx::read.xlsx("~/Downloads/test.xlsx", 1)
library(MatchIt)
m <- matchit(cov1 ~ cov2, data = dat,
method = "optimal",
distance = dat$lps,
exact = ~cov2,
discard = "both")
#> Warning: Fewer control units than treated units in some `exact` strata; not all
#> treated units will get a match.
m
#> A matchit object
#> - method: 1:1 optimal pair matching
#> - distance: User-defined [common support]
#> - common support: units from both groups dropped
#> - number of obs.: 1782 (original), 576 (matched)
#> - target estimand: ATT
#> - covariates: cov2
Created on 2024-01-18 with reprex v2.1.0
This is using MatchIt
4.5.5. Do you get the error when running the same code? Note I tested the code on optmatch
0.10.6 and 0.10.7 and could not reproduce the error.
from matchit.
Thanks for reply. I am using the exactly same code as yours with optmatch 0.10.7 and matchit 4.5.5, and I am still receiving this error message.
> dat<- read_excel("/n01/data/entactin/EA_PredictiveAnalytics/Evaluation/Optimal Matching/otheroutput/test.xlsx",1)
> match <- matchit(cov1 ~ cov2,
+ data = dat,
+ method = "optimal",
+ distance = dat$lps,
+ exact = ~cov2,
+ discard = "both"
+ )
Error in subset.InfinitySparseMatrix(x, subset = subi, select = subj) :
Subset and select must be same length as rows and columns, respectively.
In addition: Warning message: Fewer control units than treated units in some `exact` strata; not all treated units will get a match.
> packageVersion("optmatch") [1] ‘0.10.7’
> packageVersion("MatchIt") [1] ‘4.5.5’
from matchit.
> table(dat$cov1, dat$cov2)
0 1 2 3 4 5
Engage 56 61 58 49 42 37
Target 236 226 267 287 228 235
In addition, by populating the number of treated and control units by cov2, control have more people in all exact strata, not sure why there's a warning message reads 'Fewer control units than treated units in some exact
strata; not all treated units will get a match'.
from matchit.
"Engage"
is treated as the control condition in this dataset. Recode the values to 0/1 to make sure they are correctly interpreted. When given as a character, the value that comes earlier in the alphabet will be treated as the control condition. Unless they are coded as 0/1, matchit()
has to make a guess about which group is treated and which is control, and that heuristic is as good as any.
from matchit.
I have tested the code on Mac and PC using those versions of MatchIt
and optmatch
, and I can't reproduce your problem. All I can suggest is to try restarting R/RStudio and try again, maybe reach out to the optmatch
maintainers, or use nearest neighbor matching instead (the results should be almost identical, anyway, and you can use a caliper, which works better than common support). Sorry I can't be of more help. If anyone else reading this can reproduce the error, please let me know.
from matchit.
Thanks for you continuous help on this issue. I think I found the causes for this error. When I use read_excel() to read in the dataset or use read_sas(clarity) to transfer SASdataset into R, I will receive the error from the following matchit() steps.
dat<- read_excel("/n01/data/entactin/EA_PredictiveAnalytics/Evaluation/Optimal Matching/otheroutput/test.xlsx",1)
clarity <- "/n01/data/entactin/EA_PredictiveAnalytics/Evaluation/Optimal Matching/sasouput/eval_clarity_section6_fnl_w_bin2.sas7bdat"
clarity <- read_sas(clarity)
However, by using read.xlsx() instead (from your code), I no longer receive the error from following matchit().
Could you please try to reproduce the error again by reading excel dataset with read_excel()?
dat<- read_excel("/n01/data/entactin/EA_PredictiveAnalytics/Evaluation/Optimal Matching/otheroutput/test.xlsx",1)
clarity_r <- dat %>% mutate(treated=ifelse(cov1=="Engage",1,0))
match <- matchit(treated ~ lps,
-
data = clarity_r,
-
method = "optimal",
-
distance = dat$lps,
-
exact = ~cov2,
-
discard = "both"
- )
Error in subset.InfinitySparseMatrix(x, subset = subi, select = subj) :
Subset and select must be same length as rows and columns, respectively.
dat<- xlsx::read.xlsx("/n01/data/entactin/EA_PredictiveAnalytics/Evaluation/Optimal Matching/otheroutput/test.xlsx",1)
clarity_r <- dat %>% mutate(treated=ifelse(cov1=="Engage",1,0))
match <- matchit(treated ~ lps,
-
data = clarity_r,
-
method = "optimal",
-
distance = dat$lps,
-
exact = ~cov2,
-
discard = "both"
- )
match
A matchit object
- method: 1:1 optimal pair matching
- distance: User-defined [common support]
- common support: units from both groups dropped
- number of obs.: 1782 (original), 576 (matched)
- target estimand: ATT
- covariates: lps, cov2
from matchit.
Thank you so much, this was able to help me figure out the issue. To solve it, run as.data.frame()
on your dataset before sending it to matchit()
. readxl::read_excel()
returns a tibble (tbl_df
object), which is slightly different from a data.frame. xlsx::read.xlsx()
returns a data.frame, which is why I could not recreate the error when using it. I have made a key edit to the code to be robust to this issue, but it probably won't make it to CRAN for a while.
This bug will be activated any time the discard
option is used with a tibble and with method = "optimal"
or method = "full"
. The solution for now is to always ensure the input to data
is a data.frame, not a tibble, which you can guarantee by running as.data.frame()
on the input. In future releases, this will be done internally by matchit()
.
from matchit.
Thank you very much for the help!
from matchit.
Related Issues (20)
- Sensitivity Analysis with a MatchIt Object - Suggestion HOT 1
- Cardinality matching doesnt work with HiGHS HOT 1
- Relation between Covariates for Matching and Variables for Treatment Effect Estimation HOT 1
- Data needs to be randomized before sending it to matchit. Is this desired behaviour? HOT 7
- Weights for t test, chi square test, and effective sample size of subgroups HOT 5
- Match selected samples from both control and treatment cohort HOT 4
- Can glm.nb be used after running matching with Matchit? HOT 1
- Large Dataset with MatchIT HOT 13
- Matching strategy for clusters that don't include both treatment groups - multilevel matching HOT 3
- Issue regarding the unit.id argument HOT 4
- ATT estimate in survival analysis HOT 2
- best way to estimate interactions? HOT 7
- dependency on optmatch HOT 3
- Error installing "MatchIt" HOT 1
- Cardinality matching fails when there is only one covariate
- Running tests fails: Error: could not find function "avg_comparisons", "boot.ci" HOT 3
- Obtaining odds ratios vs risk ratios using avg_comparisons() HOT 1
- Predetermined subsample size HOT 1
- K-nearest neighbor matching for ATE and missing match.matrix HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matchit.