kosukeimai / MatchIt

R package MatchIt
205 stars 43 forks source link

Error when including a numeric variable in formula using cem #160

Open jfhelmer opened 1 year ago

jfhelmer commented 1 year ago

When I try to include a numeric variable with a range of 18 to 96 (ages in years) in my matchit formula (on the righthand side), I get this error: Error in seq.default(min(X[[i]]), max(X[[i]]), length = bins + 1) : 'from' must be a finite number

I've checked the data to make sure there aren't any NAs. Any ideas? If I omit the variable, matchit runs without errors. If I only include that one variable, it throws the same error. I've tried different cutpoints (sturges, q5, and 5). All give the same error.

ngreifer commented 1 year ago

Can you show me the output of the call summary() when used on that variable? Are you able to sue that variable in other forms of matching?

jfhelmer commented 1 year ago

summary(CMES.cem.complete$P26A) 1 2 5226 2288

I haven't tried matching other than CEM. However, since I posted the error, I was able to run the matching with that variable included when setting cutpoints = 0.

Jesse

Jesse Helmer 226-268-7536

On Sat, Apr 8 2023 at 7:55 PM, Noah Greifer @.***> wrote:

Can you show me the output of the call summary() when used on that variable? Are you able to sue that variable in other forms of matching?

— Reply to this email directly, view it on GitHub https://github.com/kosukeimai/MatchIt/issues/160#issuecomment-1501000042, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQNVKLZQYFOOOHQHHGT64DXAH3FXANCNFSM6AAAAAAWXUTYSU . You are receiving this because you authored the thread.Message ID: @.***>

ngreifer commented 1 year ago

You said the variable was age in years with a range from 18 to 96, but you showed me the summary of a binary factor variable. Is that an mistake?

jfhelmer commented 1 year ago

The mistake was me sending you the summary call for the treatment variable rather than the control variable that is an issue. Sorry about that! Here's the correct summary call output:

summary(CMES.cem.complete$S2.mod) Min. 1st Qu. Median Mean 3rd Qu. Max. 18.00 41.00 57.00 54.48 67.00 96.00

Jesse

Jesse Helmer 226-268-7536

On Mon, Apr 10, 2023 at 10:12 AM, Noah Greifer @.***> wrote:

You said the variable was age in years with a range from 18 to 96, but you showed me the summary of a binary factor variable. Is that an mistake?

— Reply to this email directly, view it on GitHub https://github.com/kosukeimai/MatchIt/issues/160#issuecomment-1501865983, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQNVKK4IA3YUBE6LXZZDWTXAQIOFANCNFSM6AAAAAAWXUTYSU . You are receiving this because you authored the thread.Message ID: @.***>

ngreifer commented 1 year ago

Hi Jesse, I'm not sure what the problem is. It would be helpful if you could send me your dataset with just the treatment variable and the problematic variable. If you can't do that, would you mind installing the development version of MatchIt using remotes::install_github("ngreifer/MatchIt"), restarting R, and seeing if the bug has been fixed? Thanks.

jfhelmer commented 1 year ago

Hi Noah:

I think the issue may be related to a correlation between variables I was trying to use in the match. I was also attempting to match on place of birth (inside or outside Canada). A one-way ANOVA between place of birth and age returns a p-value of 0.00249. When I drop place of birth from the matching, it works as I initially expected.

Jesse

Jesse Helmer 226-268-7536

On Mon, Apr 10, 2023 at 12:51 PM, Noah Greifer @.***> wrote:

Hi Jesse, I'm not sure what the problem is. It would be helpful if you could send me your dataset with just the treatment variable and the problematic variable. If you can't do that, would you mind installing the development version of MatchIt using remotes::install_github("ngreifer/MatchIt"), restarting R, and seeing if the bug has been fixed? Thanks.

— Reply to this email directly, view it on GitHub https://github.com/kosukeimai/MatchIt/issues/160#issuecomment-1502050538, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQNVKMML3LZMODR6DHPNF3XAQ3CNANCNFSM6AAAAAAWXUTYSU . You are receiving this because you authored the thread.Message ID: @.***>

ngreifer commented 1 year ago

Interesting. Unfortunately that doesn't help me solve the problem because the error occurs in a part of the code where each variable is considered separately from the others. I'm still wondering if you could send me a reproducible example to help me debug it.

jfhelmer commented 1 year ago

Here's a dataframe of the two variables. Jesse

Jesse Helmer 226-268-7536

On Tue, Apr 11, 2023 at 3:15 PM, Noah Greifer @.***> wrote:

Interesting. Unfortunately that doesn't help me solve the problem because the error occurs in a part of the code where each variable is considered separately from the others. I'm still wondering if you could send me a reproducible example to help me debug it.

— Reply to this email directly, view it on GitHub https://github.com/kosukeimai/MatchIt/issues/160#issuecomment-1503966327, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQNVKJYFSFNKXAX5MIZ43TXAWUWNANCNFSM6AAAAAAWXUTYSU . You are receiving this because you authored the thread.Message ID: @.***>

ngreifer commented 1 year ago

Hi Jesse, unfortunately email attachments don't work on GitHub issues, so I can't see the dataset. But actually, it's okay; I'm pretty sure I solved the problem.