1

I'm using R package matchit for propensity score matching analysis.

m.out3<-matchit(data=b4psm5, treat~high_school_gpa+male+pell+black+hispanic+asian+other+race_miss,method="nearest", ratio=1,exact=c("cohortid"), m.order="random", caliper=0.25)

All variables are in the data, but I'm getting this error message, which I think is related to the exact matching command.

Error in Ops.data.frame(exact[itert, k], exact[clabels, k]) : 
‘!=’ only defined for equally-sized data frames

Could you advise? I don't have a reproducible dataset.

Kaz
  • 37
  • 6
  • 2
    It might help to have a sample of your data. Can you edit your question and add the output from `dput(head(b4msm5))`? (It might be good to check that you get the error with that small sample. If you don't get an error with that, then find the row(s) that causes the error ... and you may see a problem yourself.) – r2evans Jul 27 '19 at 05:32
  • Hi, you need to make your question [reproducible](https://stackoverflow.com/a/5963610/6574038) for Stack Overflow, cheers. – jay.sf Jul 27 '19 at 06:08
  • Sorry it's taking a while to get back to this. – Kaz Jul 31 '19 at 02:26

1 Answers1

0

This is likely because you made an error in the syntax. If the formula (the part with the ~) is not the first argument, you need to label it with formula=. So, trying running the following code and see if you get the error:

m.out3 <- matchit(data = b4psm5, 
                  formula = treat ~ high_school_gpa + male + pell + 
                      black + hispanic + asian + other + race_miss,
                  method="nearest", ratio=1, exact=c("cohortid"), 
                  m.order="random", caliper=0.25)

Typically the formula is specified as the first argument and so doesn't need the formula= tag, but you specified it as the second argument, so R doesn't know that what you provided as the model formula goes into the formula argument.

Noah
  • 3,437
  • 1
  • 11
  • 27
  • Hmm, sorry, it didn't work. I got the same message. I will keep you informed if I find a solution. I tried to make a reproducible data, but with that the code did not produce an error. – Kaz Aug 02 '19 at 03:20