rmatchit

Am I following instructions correctly for this matching process using MatchIt?


I'm supposed to do the following:

Is this code correct?

library(MatchIt)

match_obj <- matchit(Cohort ~ Propensity_Score,
                     data = data, 
                     exact = c("HF"),
                     method = "nearest",
                     distance = "logit",
                     link = "linear.logit",
                     caliper = 0.005,
                     std.caliper = c(TRUE),
                     mahvars = ~ Propensity_Score + Continuous1 + Continuous2 + Continuous3)

Solution

  • Your code is close to what you describe, but unfortunately you can't do what you're asking in a single call. MatchIt doesn't allow you to both estimate the propensity score and use it in matching with other covariates at the same time. You have to estimate the propensity score in a separate step and then include it in the call to matchit(). Here is how it might look:

    #Estimate the PS
    ps <- glm(Cohort ~ Continuous1 + Continuous2 + Continuous3,
              data = data, family = binomial)$fitted
    
    #Take its logit
    data$ps_logit <- qlogis(ps)
    
    #MDM on PS logit + covariates with exact on HM and caliper on PS logit
    match_obj <- matchit(Cohort ~ ps_logit + Continuous1 + Continuous2 + Continuous3,
                         data = data, 
                         exact = ~HF,
                         method = "nearest",
                         distance = "mahalanobis",
                         caliper = c(ps_logit = 0.005),
                         std.caliper = TRUE)
    

    There are other ways of accomplishing the same task using mahvars but this syntax is a bit clearer and allows you to test whether Mahalanobis distance matching is better than matching on another distance matrix, like matching on the robust Mahalanobis distance or scaled Euclidean distance.

    For a question like this, I would recommend asking on the MatchIt issues page since it doesn't seem to meet SO's standards and is quite specific to MatchIt.