Dear Guillaume
Have you found a solution to this issue with MDM? I have been recommended to
stay away from Propensity Score Matching and MDM is one of the alternatives
suggested to avoid assuming complete randomization. But this does not sound
too encouraging.
Best, Jonas
_____________________________________________________
Postdoctoral Research Fellow
Conservation Science Group
Department of Zoology
University of Cambridge
The David Attenborough Building
Pembroke Street, Cambridge, CB2 3QZ
Phone: +44 7412 885 112
Danish: +45 2990 5192
Skype: jgeldmann
Dear all,
I fixed the subscript out of bounds problem in matchit using a solution that I discovered 10 years ago and sent to the matchit mailing list.
Here is my post from 2007:
https://lists.gking.harvard.edu/pipermail/matchit/2007-September/000029.html
I have a dataset called Small without missing values. I get a subscript out of bounds error. When I create a new dataset that is exactly the same as the old dataset, matchit works. See the below code. The two data frames are the same data types, and they have the same row names. I do not know how they are different, but for some reason only the second one works.
I can’t give you this data to replicate the problem in for data confidentiality reasons, but perhaps someone else has data that creates this error.
> sum(apply(apply(Small, 1, is.na), 1, sum))
[1] 0
> model1<-matchit(formula= treatment ~ male, exact=c("black"), mahvars=c("age1"), data=Small, method="nearest", distance = "logit", caliper=0.25, replace=T, calclosest=T, ratio=3, verbose=T)
Nearest neighbor matching...
Matching Treated: Error in mahvars[pool, , drop = F] : subscript out of bounds
> dim(Small)
[1] 7756 8
>
> nrow(Small)
[1] 7756
> Small2=Small[1:nrow(Small),]
>
> model1<-matchit(formula= treatment ~ male, exact=c("black"), mahvars=c("age1"), data=Small2, method="nearest", distance = "logit", caliper=0.25, replace=T, calclosest=T, ratio=3, verbose=T)
Nearest neighbor matching...
Matching Treated: 10%...20%...30%...40%...50%...60%...70%...80%...90%...100%...Done
> is.data.frame(Small)
[1] TRUE
> is.data.frame(Small2)
[1] TRUE
> is.matrix(Small)
[1] FALSE
> is.matrix(Small2)
[1] FALSE
> rownames(Small)[1:4]
[1] "1" "2" "3" "4"
> rownames(Small2)[1:4]
[1] "1" "2" "3" “4”
Janet
Janet Rosenbaum, Ph.D.
Assistant Professor of Epidemiology
School of Public Health, SUNY Downstate Medical Center, Brooklyn, NY
janet(a)post.harvard.edu
Dear all,
I’m another person who gets the following error with the Mahalanobis matching option for matchit:
Error in mahvars[pool, , drop = F] : subscript out of bounds
I have done Mahalanobis matching a thousand times before without problems. Now I’ve exported a slightly different version of the data — slightly different sample size, slightly different set of variables. Running one matchit command with the first version of the data is fine. Running the exact same matchit command with the second version of the data gives the error; if I take out the mahvars option, the command runs fine. Which is unfortunate because Mahalanobis matching seems to work with the earlier version of the data.
An earlier poster said that the row names may be different, but in my case, I don’t have row names for either dataset. Both datasets are csv files exported from Stata with the same command, with only slight variations. Stata version is the same. I did upgrade R today from 3.4.0 to 3.4.1.
I replicated the problem by exporting a small version of my data file with only 8 variables: I can do nearest-neighbor matching without the mahvars option, but it doesn’t work if I specify the option. I can do full matching with this data. Any ideas how to proceed or how I can figure out what might be causing the problem? I tried debugging the data and looked at the variable pool noted in the error message, but I didn’t know where to go from there.
I recall having had a student in my class of 17 last spring who was the only student in the class who had this error, and I wasn’t able to help them either; the student just used full matching for their term paper.
> dim(Small)
[1] 7756 8
> names(Small)
[1] "treatment" "male" "age1" "black" "gonorrhea" "chlamydia" "tricho"
[8] "any_sti3"
> model1<-matchit(formula= treatment ~ male, exact=c("black"), mahvars=c("age1"), data=Small, method="nearest", distance = "logit", caliper=0.25, replace=T, calclosest=T, ratio=3, verbose=T)
Nearest neighbor matching...
Matching Treated: Error in mahvars[pool, , drop = F] : subscript out of bounds
> model0<-matchit(formula= treatment ~ male + age1, exact=c("black"), data=Small, method="nearest", distance = "logit", caliper=0.25, replace=T, calclosest=T, ratio=3, verbose=T)
Nearest neighbor matching...
Matching Treated: 10%...20%...30%...40%...50%...60%...70%...80%...90%...100%...Done
> model0
Call:
matchit(formula = treatment ~ male + age1, data = Small, method = "nearest",
distance = "logit", exact = c("black"), caliper = 0.25, replace = T,
calclosest = T, ratio = 3, verbose = T)
Sample sizes:
Control Treated
All 7375 381
Matched 1061 381
Unmatched 6314 0
Discarded 0 0
>
> model.full<-matchit(formula= treatment ~ male + priv_ah + black + age1, data=Small, method="full", verbose=T)
Error in eval(predvars, data, env) : object 'priv_ah' not found
> model.full
Call:
matchit(formula = suspended_lastyr2 ~ male + priv_ah + black +
age1, data = Small, method = "full", verbose = T)
Sample sizes:
Control Treated
All 7375 381
Matched 7375 381
Discarded 0 0
Thanks,
Janet
Janet Rosenbaum, Ph.D.
Assistant Professor of Epidemiology
School of Public Health, SUNY Downstate Medical Center, Brooklyn, NY
janet(a)post.harvard.edu
Will do.
Kosuke Imai
Professor, Department of Politics
Center for Statistics and Machine Learning
Princeton University
http://imai.princeton.edu
On Thu, Jun 22, 2017 at 6:08 PM, kgmacau <kgmacau(a)163.com> wrote:
>
> Dear Prof. Imai,
>
> Many thanks. The number of running sum(is.na(real_data)) is positive,
> which indicates a variable has missing values. However, I do not use this
> variable in matchit function but it actually has influence on this
> function. Is it possible to solve this limitation in your future update of
> this package.
>
> Thanks & Regards,
> Ning
>
>
>
>
> At 2017-06-22 13:49:33, "Kosuke Imai" <kimai(a)princeton.edu> wrote:
>
> Hi Ning,
>
> Please send your inquirty to the matchit mailing list, to which I'm
> forwarding your email. As for your question, can you try sum(is.na(real_data))?
> If you get a positive number, it does mean that you have missing data.
> "subclass" tells you which subclass each observation belongs to (after
> full matching).
>
> Good luck,
> Kosuke
>
> Kosuke Imai
> Professor, Department of Politics
> Center for Statistics and Machine Learning
> Princeton University
> http://imai.princeton.edu
>
> On Wed, Jun 21, 2017 at 1:17 AM, kgmacau <kgmacau(a)163.com> wrote:
>
>> Dear Prof. Ho and Imai,
>>
>> I am implementing the propensity scores matching method for my research
>> and came across below error when running the matchit function:
>>
>> library(MatchIt)
>> result <- matchit(group~sex+age+primary_disease
>> +kps+rpa+gpa+primary_control
>> +extracranial_metastasis
>> +extracranial_metastasis_control
>> +primary_treatment
>> +past_treatment
>> +N_brain_metastases,
>> data=real_data,
>> method = "full")
>>
>> Error in matchit(group ~ sex + age + primary_disease + kps + rpa + gpa +
>> :
>> Missing values exist in the data
>>
>> I checked my data and there is no missing value in my data and searched
>> the same error online but did not find any solution. So I do not know why
>> there occurred this error. I highly appreciate it if you can tell me how to
>> solve this error.
>>
>> Besides, we can present the matched results in data via
>> match.data(result), in which the argument "subclass" specifies the
>> variable name used to store the subclass indicator. Does this argument
>> indicate the matched information for subjects? If not, what argument in
>> what function can present the matched subject lists? Thank you very much
>> and look forward to your reply.
>>
>> Thanks & Regards,
>>
>> Ning Li
>> Programmer analyst
>> PPD Biostatistics Department, Beijing, China
>> Email: ning.li(a)ppdi.com
>> Tel: 86 17701386979
>>
>>
>>
>>
>>
>>
>
>
>
>
>
Hi Ning,
Please send your inquirty to the matchit mailing list, to which I'm
forwarding your email. As for your question, can you try
sum(is.na(real_data))?
If you get a positive number, it does mean that you have missing data.
"subclass" tells you which subclass each observation belongs to (after
full matching).
Good luck,
Kosuke
Kosuke Imai
Professor, Department of Politics
Center for Statistics and Machine Learning
Princeton University
http://imai.princeton.edu
On Wed, Jun 21, 2017 at 1:17 AM, kgmacau <kgmacau(a)163.com> wrote:
> Dear Prof. Ho and Imai,
>
> I am implementing the propensity scores matching method for my research
> and came across below error when running the matchit function:
>
> library(MatchIt)
> result <- matchit(group~sex+age+primary_disease
> +kps+rpa+gpa+primary_control
> +extracranial_metastasis
> +extracranial_metastasis_control
> +primary_treatment
> +past_treatment
> +N_brain_metastases,
> data=real_data,
> method = "full")
>
> Error in matchit(group ~ sex + age + primary_disease + kps + rpa + gpa +
> :
> Missing values exist in the data
>
> I checked my data and there is no missing value in my data and searched
> the same error online but did not find any solution. So I do not know why
> there occurred this error. I highly appreciate it if you can tell me how to
> solve this error.
>
> Besides, we can present the matched results in data via
> match.data(result), in which the argument "subclass" specifies the
> variable name used to store the subclass indicator. Does this argument
> indicate the matched information for subjects? If not, what argument in
> what function can present the matched subject lists? Thank you very much
> and look forward to your reply.
>
> Thanks & Regards,
>
> Ning Li
> Programmer analyst
> PPD Biostatistics Department, Beijing, China
> Email: ning.li(a)ppdi.com
> Tel: 86 17701386979
>
>
>
>
>
>
Dear mailing list
I have a question about the MatchIt that might be very naïve or simple, but
I am very new to the package.
I am matching on a series of variables some continues (e.g. temperature and
elevation) and some categorical (country and landcover class). As a result,
I need method = exactly for some variable (i.e. country) and method =
nearest, distance = logit for others (i.e. temperature).
I am not sure if I can specific different methods for different variables in
the same matchit call
Thank you in advance.
Sincerely, Jonas
_____________________________________________________
Postdoctoral Research Fellow
Conservation Science Group
Department of Zoology
University of Cambridge
Downing Street, Cambridge CB2 3EJ
Phone: +44 7412 885 112
Danish: +45 2990 5192
Skype: jgeldmann
Try creating larger strata.
Kosuke Imai
Professor, Department of Politics
Center for Statistics and Machine Learning
Princeton University
http://imai.princeton.edu
On Mon, May 15, 2017 at 12:30 PM, Guogen Shan <guogen.shan(a)unlv.edu> wrote:
> Dear Prof. Imai, Thanks for your prompt response. This strata approach
> works great when the control group has at least one subject having the same
> age as one subject from the treatment group. The control group in our study
> is not large enough to meet that assumption. Any comments? Thank you.
>
> Guogen
>
> On May 15, 2017 6:52 AM, "Kosuke Imai" <kimai(a)princeton.edu> wrote:
>
>> You can stratify the age variable and then do a matching with an extract
>> restriction on that strata.
>>
>> Kosuke Imai
>> Professor, Department of Politics
>> Center for Statistics and Machine Learning
>> Princeton University
>> http://imai.princeton.edu
>>
>> On Sun, May 14, 2017 at 11:58 PM, Guogen Shan <guogen.shan(a)unlv.edu>
>> wrote:
>>
>>> Dear Prof. Imai,
>>>
>>> Thanks for developing the MatchIt package. I have a data set from a
>>> treatment, and I want to match it with another data base (control), by age,
>>> race, education. Age is the primary match criteria, followed by race, and
>>> education. In other words, I want to give more weights to the age
>>> difference than those to race difference. Any suggestion how to use your
>>> package for this type of matching?
>>>
>>> Thank you.
>>>
>>> Guogen
>>>
>>
>>
You can stratify the age variable and then do a matching with an extract
restriction on that strata.
Kosuke Imai
Professor, Department of Politics
Center for Statistics and Machine Learning
Princeton University
http://imai.princeton.edu
On Sun, May 14, 2017 at 11:58 PM, Guogen Shan <guogen.shan(a)unlv.edu> wrote:
> Dear Prof. Imai,
>
> Thanks for developing the MatchIt package. I have a data set from a
> treatment, and I want to match it with another data base (control), by age,
> race, education. Age is the primary match criteria, followed by race, and
> education. In other words, I want to give more weights to the age
> difference than those to race difference. Any suggestion how to use your
> package for this type of matching?
>
> Thank you.
>
> Guogen
>
Dear all,
May I ask a question about package: MatchIt (version 2.4-22) in R(3.3.2)?
When I want to calculate ate by the code below, it doesn't work. Could you
help me solve the problem? Because when I run
> s.out1$qi$att.ev, it comes the error:
Error in s.out1$qi$att.ev : object of type 'closure' is not subsettable
I think it can not find qi object in s.out1 because it's a function? So I
can't call the object att.ev from qi? Do you have any suggestion for
calculating ate?
The code is below:
m.out1 <- matchit(treat ~ age + educ + black + hispan + nodegree +
married + re74 + re75, method = "nearest", data = lalonde)
z.out1 <- zelig(re78 ~ age + educ + black + hispan + nodegree +
married + re74 + re75, data = match.data(m.out1, "control"),
model = "ls")
x.out1 <- setx(z.out1, data = match.data(m.out1, "treat"), cond = TRUE)
s.out1 <- sim(z.out1, x = x.out1)
z.out2 <- zelig(re78 ~ age + educ + black + hispan + nodegree +
married + re74 + re75, data = match.data(m.out1, "treat"),
model = "ls")
x.out2 <- setx(z.out2, data = match.data(m.out1, "control"), cond = TRUE)
s.out2 <- sim(z.out2, x = x.out2)
ate.all <- c(s.out1$qi$att.ev, -s.out2$qi$att.ev)
Thank you so much
Best,
Wan-Yi,Chou
*Wan-Yi Chou (May Chou), Master*
*Management Science, **National Chiao Tung University*
*國立交通大學管理科學研究所 *
*周宛誼*|*Email mayritaspring(a)gmail.com <mayritaspring(a)gmail.com> *
--
*Wan-Yi Chou (May Chou), Master*
*Management Science, **National Chiao Tung University*
*國立交通大學管理科學研究所 *
*周宛誼*|*Email mayritaspring(a)gmail.com <mayritaspring(a)gmail.com> *