Hi George,
To get the numbers of matched, etc. you can use code like I show below. But I will add that in the propensity score world a match is not necessarily "successful" even if they were matched; the real measure of success are the balance measures that we print out in the summary() command. i.e., you might technically get a match but maybe their propensity scores were actually quite far apart (e.g., if you don't impose a caliper). But perhaps you have a different purpose.
To get the numbers matched, unmatched, etc. you can use code like:
> m.out <- matchit(treat ~ re74+re75+age+educ, data=lalonde)
> m.out
Call:
matchit(formula = treat ~ re74 + re75 + age + educ, data = lalonde)
Sample sizes:
Control Treated
All 429 185
Matched 185 185
Unmatched 244 0
Discarded 0 0
> sum(m.out$discarded[m.out$treat==1])
[1] 0
> sum(m.out$weights[m.out$treat==1]!=0)
[1] 185
> sum(m.out$weights[m.out$treat==0]!=0)
[1] 185
> sum(m.out$weights[m.out$treat==0]==0)
[1] 244
So that should help with your first issue.
I am sorry about the other problem you are having but unfortunately do not have a quick solution. I do recall that there was a workaround suggested on the listserv; perhaps you could use that approach? Otherwise it might take us a little while to be able to fix this other problem, especially given summer travel schedules, and it may be that fixing that would not be a minor fix but rather would require a larger rewrite of the structure of the program.
Thanks,
Liz
On 8/4/10 10:49 AM, "George Baah" <baah(a)cc.gatech.edu> wrote:
Hi Elizabeth,
What I meant was some kind of a return code that indicated whether there was
a match or not. In the scientific application we are building
we would like to automate many things instead of forcing the user to manually inspect
thousands of matchit results using summary commands.
For example, we were hoping to have access to variables that contain the number
of matched treatments, controls, and discarded etc. I can see the information
with the summary command but can't figure out how to access the information.
Maybe I am missing something.
Also there is a problem with match.data(). It works fine on the command line but fails
to work in a function. This is another big problem we are facing. It looks like there is a
namespace bug with match.data(). I searched the list and a similar problem was
reported more than a year ago but the developers never fixed it.
Thank you very much for your time.
George
On Aug 3, 2010, at 8:42 PM, Stuart, Elizabeth A. wrote:
Hi George,
Could you clarify what you mean by "successful"? If you don't get any error messages then the matching has completed successfully (i.e., will have created matches). You can check that by then printing out the matchit object or by using the summary() command on the matchit object. If you do get an error message because there was some problem in the matching procedure then hopefully it will be fairly clear what the problem is--we tried to put in easy to understand error messages for most of the common problems people come across when running the matchit command (e.g., matching without replacement with more treated than control subjects).
However, if by "successful" you mean whether it was successful at improving the balanced between the treated and control groups, that is what the diagnostics the summary() and plot() commands print out are for (e.g., comparing the standardized mean differences). That is a harder to thing to just judge with a single variable which is why we print out a variety of diagnostic tools for the user to look at.
I hope this helps, but I may be misunderstanding your question.
Liz
On 8/2/10 7:43 PM, "georgebaah" <gtg498n(a)mail.gatech.edu> wrote:
Hi All,
I am new to this list and MatchIt. I am writing a program that uses
MatchIt to
match some units so I can compute treatment effects. Depending whether
matching was successful or not the program processes some other
information.
Question:
--------------
Is there a way (either through a variable) that MatchIt can tell me if
the matching was successful or not?
Right now MatchIt outputs a bunch of messages and then stops the
program if matching is not successful.
Thanks.
George
--
MatchIt mailing list served by Harvard-MIT Data Center
List Address: matchit(a)lists.gking.harvard.edu
Subscribe/Unsubscribe: http://lists.gking.harvard.edu/?info=matchit
MatchIt Software and Documentation: http://gking.harvard.edu/matchit/
Browse/Search List Archive: http://lists.hmdc.harvard.edu/lists/matchit/
Hi All,
I am not sure what is going on but the following code works
fine on the R command line but fails in the function.
cm = function(obs_data){
m.out = matchit(treat ~ x + y, data = obs_data, method="nearest",
distance="logit");
mdata = match.data(m.out); #generates the error
cm = zelig(outcome ~ treat + x + y, data = mdata, model="ls");
}
I found out that it was the match.data statement generating this error:
Error in eval(expr, envir, enclos) : object 'obs_data' not found
Will someone please tell me what is going on? Thanks.
George
I found the bug.
Why in the world would .onAttach set the global digits option? This is
really bad coding practice.
.onAttach <- function(...) {
mylib <- dirname(system.file(package = "MatchIt"))
ver <- packageDescription("MatchIt", lib = mylib)$Version
builddate <- packageDescription("MatchIt", lib = mylib)$Date
cat(paste("## \n## MatchIt (Version ", ver, ", built: ", builddate, ")\n",
sep = ""))
cat("## Please refer to http://gking.harvard.edu/matchit for full
documentation \n",
"## or help.matchit() for help with commands supported by MatchIt.\n##\n",
sep="")
options(digits = 4)
}
Hey George,
I think I have a pretty simple (if silly) solution. Let's look at some code:
library(MatchIt)
x<-rnorm(100)
y<-rnorm(100)
treat<-rbinom(100,size=1,prob=.3)
data.frame(treat,x,y)->obs_data
cm = function(obs.data){
m.out = matchit(treat ~ x + y, data = obs.data, method="nearest",
distance="logit");
m.out$call$data<-obs.data #added!
mdata = match.data(m.out); #generates the error
cm = zelig(outcome ~ treat + x + y, data = mdata, model="ls");
}
cm(obs_data)->out
I added the second line in the function. You can get the error by
commenting it out, but I think you get what you want by using this
simple tweak.
Ben
On Wed, Aug 4, 2010 at 9:39 AM, George Baah <baah(a)cc.gatech.edu> wrote:
> Hi Ben,
> I have seen your solution but I am wondering how you integrated
> your solution into matchit. I am kind of an R newbie :-). Thanks.
>
> George
> On Aug 3, 2010, at 7:30 PM, Ben Domingue wrote:
>
>> That's true. I sent a second email to the list regarding this on
>> 3/12/09 that may offer more concise advice about how to get around the
>> problem. If memory serves me correctly, there's a namespace issue
>> that leads to problems when matchit gets called from within a
>> function.
>>
>> Ben
>>
>> On Tue, Aug 3, 2010 at 5:26 PM, georgebaah <gtg498n(a)mail.gatech.edu>
>> wrote:
>>>
>>> Hi Ben,
>>> I read the post but no solution was ever provided by the developers of
>>> MatchIt.
>>>
>>> George
>>> On Aug 3, 2010, at 7:19 PM, Ben Domingue wrote:
>>>
>>>> George,
>>>> I'm not positive, but I think there may be a work around contained in
>>>> an email sent to the group on 11/15/08 (it began "I am using boot() to
>>>> compute standard errors for a matching estimator.").
>>>>
>>>> Ben
>>>>
>>>> On Tue, Aug 3, 2010 at 5:00 PM, georgebaah <gtg498n(a)mail.gatech.edu>
>>>> wrote:
>>>>>
>>>>> Hi All,
>>>>> I am not sure what is going on but the following code works
>>>>> fine on the R command line but fails in the function.
>>>>> cm = function(obs_data){
>>>>> m.out = matchit(treat ~ x + y, data = obs_data, method="nearest",
>>>>> distance="logit");
>>>>> mdata = match.data(m.out); #generates the error
>>>>> cm = zelig(outcome ~ treat + x + y, data = mdata, model="ls");
>>>>> }
>>>>> I found out that it was the match.data statement generating this error:
>>>>> Error in eval(expr, envir, enclos) : object 'obs_data' not found
>>>>> Will someone please tell me what is going on? Thanks.
>>>>> George
>>>>>
>>>>>
>>>
>>>
>
>
--
MatchIt mailing list served by Harvard-MIT Data Center
List Address: matchit(a)lists.gking.harvard.edu
Subscribe/Unsubscribe: http://lists.gking.harvard.edu/?info=matchit
MatchIt Software and Documentation: http://gking.harvard.edu/matchit/
Browse/Search List Archive: http://lists.hmdc.harvard.edu/lists/matchit/
Hi All,
I am new to this list and MatchIt. I am writing a program that uses
MatchIt to
match some units so I can compute treatment effects. Depending whether
matching was successful or not the program processes some other
information.
Question:
--------------
Is there a way (either through a variable) that MatchIt can tell me if
the matching was successful or not?
Right now MatchIt outputs a bunch of messages and then stops the
program if matching is not successful.
Thanks.
George
--
MatchIt mailing list served by Harvard-MIT Data Center
List Address: matchit(a)lists.gking.harvard.edu
Subscribe/Unsubscribe: http://lists.gking.harvard.edu/?info=matchit
MatchIt Software and Documentation: http://gking.harvard.edu/matchit/
Browse/Search List Archive: http://lists.hmdc.harvard.edu/lists/matchit/