Seydou GORO
Seydou GORO

Reputation: 1285

Problems with function MatchIt::matchit

Hi I'd like to do a logistical regression by adjusting on the propensity score. But first I'd like to match treaty and non-treaty according to propensity scores. Here's my first script:

mod_match<-matchit(Treatment~Prop.score, method = "nearest", data = Epidemio.prop,caliper = 0.05)

Here are the error messages

Error in matchit(Treatment~Prop.score, method = "nearest", data = Epidemio.prop, : Missing values exist in the data

I have therefore removed from the model all other variables except the two variables of interest that have no missing data.

mod_match<-matchit(Treatment~Prop.score, 
method = "nearest",  data = Epidemio.prop[c("Treatment","Prop.score")],
caliper = 0.1)

I still have error messages.

Error in weights.matrix(match.matrix, treat, discarded) : No units were matched In addition: Warning messages:

1: In max(pscore[treat == 0]) : no non-missing arguments to max; returning -Inf

2: In max(pscore[treat == 1]) : no non-missing arguments to max; returning -Inf

3: In min(pscore[treat == 0]) : no non-missing arguments to min; returning Inf

4: In min(pscore[treat == 1]) : no non-missing arguments to min; returning Inf

Upvotes: 1

Views: 7120

Answers (1)

Tomas Capretto
Tomas Capretto

Reputation: 741

The problem is that you are not giving any variables to be used in the propensity score calculation (i.e., you are only giving Treatment and Prop.score, whose meaning is not clear to me). You need to pass a set of auxiliary variables that are going to be used to fit the model predicting propensity scores.

Also, from my experience using MatchIt, it will throw an error related to missing values no matter the missingness is not related to the variables included in the model.

I recommend you create an auxiliary data frame with the variables you want to use in the model, and delete (or impute) any of the observations with missing values in any of those variables.

Something like this:

vars_to_keep <- c("Treatment", "x1", "x2", "x3", ... )
aux_df <- df[vars_to_keep]

# Select only complete cases (i.e. drop observations with at least one missing)
aux_df <- aux_df[complete.cases(aux_df), ]

mod_match <- matchit(Treatment ~ x1 + x2 + x3 + ..., method = "nearest", data = aux_df) 

Nevertheless, this tutorial is a much more comprehensive help. I recommend having a look at it.

Good luck!

Upvotes: 4

Related Questions