Howdy,When matching some data using method="subclass", I noticed that the
assigned subclasses were 0,2,3,4,5 instead of 1,2,3,4,5. This wasn't what I
had expected, although I suppose it isn't necessarily a problem. After
digging around, I found this line of code in the matchit2subclass function:
q <- c(0,quantile(p1,probs=sprobs,na.rm=TRUE),1)
The problem is that I was using distance=linear.logit so 0 and 1 were not
the appropriate upper and lower bounds. When the code hit this later
chunk:
q1 <- q[i]
q2 <- q[i+1]
psclass <- psclass+i*as.numeric(distance<q2 & distance>=q1)
there was a problem. When i was 1, q2 would be negative and q1 would be 0.
So, even if distance<q2 was true, distance>=q1 would be false and
as.numeric() would return 0.
I modified that block of code to read as follows, look for #ADDED &
#DELETED:
## Settting Cut Points
if(length(subclass)!=1 | (length(subclass)==1 & all(subclass<1))) {
subclass <- sort(subclass)
if (subclass[1]==0)
subclass <- subclass[-1]
if (subclass[length(subclass)]==1)
subclass <- subclass[-length(subclass)]
if(sub.by=="treat")
q <- c(0,quantile(p1,probs=c(subclass)),1)
else if(sub.by=="control")
q <- c(0,quantile(p0,probs=c(subclass)),1)
else if(sub.by=="all")
q <- c(0,quantile(distance,probs=c(subclass)),1)
else
stop("Invalid input for sub.by")
}
else {
if(subclass<=0){stop("Subclass must be a positive vector",call.=FALSE)}
sprobs <- seq(0,1,length=(round(subclass)+1))
sprobs <- sprobs[2:(length(sprobs)-1)]
if(sub.by=="treat") {
q<-quantile(p1,probs=(0:subclass)/subclass) #ADDED!
#DELETED q <- c(0,quantile(p1,probs=sprobs,na.rm=TRUE),1)
} else if(sub.by=="control")
q <- c(0,quantile(p0,probs=sprobs,na.rm=TRUE),1)
else if(sub.by=="all")
q <- c(0,quantile(distance,probs=sprobs,na.rm=TRUE),1)
else
stop("Must specify a valid sub.by",call.=FALSE)
}
## Calculating Subclasses
qbins <- length(q)-1
psclass <- rep(0,n)
names(psclass) <- names(treat)
for (i in 1:qbins){
#DELETED q1 <- q[i]
#DELETED q2 <- q[i+1]
#DELETED psclass <- psclass+i*as.numeric(distance<q2 & distance>=q1)
if (i==1) psclass[distance<q[i+1]]<-i #ADDED
if (i==qbins) psclass[distance>=q[i]]<-i #ADDED
if (i!=1 & i!=qbins) psclass[distance<q[i+1] & distance>=q[i]]<-i #ADDED
}
I don't think this is an especially elegant way of doing things and I
obviously only fixed the issue for the default of sub.by="treat". I'm also
thinking that this could potentially be an issue in the other matchit2xxx
functions.
Ben
Hello,
Is there a way to extract the "sample sizes" matrix from the object
containing exact matching results? names(matchit.out) after exact matching
lists "subclass", "weights", "call", "formula", "treat", and "X" but no
object associated with sample size.
Thank you.
Andrew Stokes
I've uploaded it to CRAN too.
Kosuke
On Fri, 18 Jul 2008, Ben Domingue wrote:
> Will do. However, I'm going to have to wait for it to appear on the CRAN
> website. I'm having problems with both "install.packages("MatchIt", repos =
> "http://gking.harvard.edu")" and trying to do it from the gui. In both
> cases, I get an error message about not being able to access the index.
> Thanks,
> Ben
>
>
> On Fri, Jul 18, 2008 at 12:24 PM, Kosuke Imai <kimai(a)princeton.edu> wrote:
>
>> Can you try the new version? It's 2.4-4.
>>
>> Thanks,
>> Kosuke
>>
>>
>> On Fri, 18 Jul 2008, Ben Domingue wrote:
>>
>> Kosuke,I think I found another. In the matchit() function, there is this
>>> section of code:
>>>
>>> if (reestimate) {
>>> distance.options$data <- data[!discarded, ]
>>> tmp <- out1
>>> out1 <- do.call(fn1, distance.options)
>>> tmp$distance[!discarded] <- out1$distance
>>> out1$distance <- tmp$distance
>>> }
>>>
>>> I kept getting this error (with reestimate=T)
>>> Error in model.frame.default(formula = formula, data = data, weights =
>>> c(0.0372523210096819, :
>>> variable lengths differ (found for '(weights)')
>>>
>>> I think the problem is that when you are trimming distance.options$data,
>>> you
>>> don't also trim distance.options$weights. I modified the section to read:
>>>
>>> if (reestimate) {
>>> distance.options$data <- data[!discarded, ]
>>> distance.options$weights <- distance.options$weights[!discarded]
>>> #NEW!
>>> m tmp <- out1
>>> out1 <- do.call(fn1, distance.options)
>>> tmp$distance[!discarded] <- out1$distance
>>> out1$distance <- tmp$distance
>>> }
>>>
>>> and I *think* it works.
>>> Ben
>>>
>>>
>>>
>>> On Fri, Jul 18, 2008 at 7:57 AM, Kosuke Imai <kimai(a)princeton.edu> wrote:
>>>
>>> Dear Ben,
>>>>
>>>> Many thanks for finding a bug AND fixing it! I just released a new
>>>> version
>>>> which contains this bug fix. It's available through
>>>>
>>>> install.packages("MatchIt", repos = "http://gking.harvard.edu")
>>>>
>>>> and will appear at CRAN soon.
>>>>
>>>> Thanks again,
>>>> Kosuke
>>>>
>>>> ---------------------------------------------------------
>>>> Kosuke Imai Office: Corwin Hall 041
>>>> Assistant Professor Phone: 609-258-6601
>>>> Department of Politics eFax: 973-556-1929
>>>> Princeton University Email: kimai(a)Princeton.Edu
>>>> Princeton, NJ 08544-1012 http://imai.princeton.edu/
>>>> ---------------------------------------------------------
>>>>
>>>>
>>>> On Thu, 17 Jul 2008, Ben Domingue wrote:
>>>>
>>>> Howdy,I've been using (and enjoying!) matchit, but I recently had some
>>>>
>>>>> problems. I think some of the code in the matchit2full function is
>>>>> buggy,
>>>>> but maybe there is some other explanation. This only happens when you
>>>>> are
>>>>> trying to discard units.
>>>>> A portion of the original source for that function reads:
>>>>>
>>>>> ttt <- treat[!discarded]
>>>>>
>>>>> ddd <- distance[!discarded]
>>>>>
>>>>> n0 <- length(ttt[ttt==0])
>>>>>
>>>>> n1 <- length(ttt[ttt==1])
>>>>>
>>>>> d1 <- distance[ttt==1]
>>>>>
>>>>> d0 <- distance[ttt==0]
>>>>>
>>>>> d <- matrix(0, ncol=n0, nrow=n1)
>>>>>
>>>>> rownames(d) <- names(ttt[ttt==1])
>>>>>
>>>>> colnames(d) <- names(ttt[ttt==0])
>>>>>
>>>>> for (i in 1:n1)
>>>>>
>>>>> d[i,] <- abs(d1[i]-d0)
>>>>>
>>>>>
>>>>> I kept getting this error after the last command:
>>>>>
>>>>> Error in d[i, ] <- abs(d1[i] - d0) :
>>>>>
>>>>> number of items to replace is not a multiple of replacement length
>>>>>
>>>>> I think the root of the problem is the way d1 and d0 are being defined.
>>>>> As
>>>>> the code is written, distance and ttt could be of different lengths
>>>>> (they
>>>>> will be if units have been discarded). I altered the code to read:
>>>>>
>>>>>
>>>>> ttt <- treat[!discarded]
>>>>>
>>>>> ddd <- distance[!discarded]
>>>>>
>>>>> n0 <- length(ttt[ttt==0])
>>>>>
>>>>> n1 <- length(ttt[ttt==1])
>>>>>
>>>>> d1 <- ddd[ttt==1]
>>>>>
>>>>> d0 <- ddd[ttt==0]
>>>>>
>>>>> d <- matrix(0, ncol=n0, nrow=n1)
>>>>>
>>>>> rownames(d) <- names(ttt[ttt==1])
>>>>>
>>>>> colnames(d) <- names(ttt[ttt==0])
>>>>>
>>>>> for (i in 1:n1)
>>>>>
>>>>> d[i,] <- abs(d1[i]-d0)
>>>>>
>>>>>
>>>>> Now, if only I could figure out how to recompile the package...
>>>>>
>>>>> Ben
>>>>>
>>>>>
>>>>>
>>>
>
--
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/
Howdy,I've been using (and enjoying!) matchit, but I recently had some
problems. I think some of the code in the matchit2full function is buggy,
but maybe there is some other explanation. This only happens when you are
trying to discard units.
A portion of the original source for that function reads:
ttt <- treat[!discarded]
ddd <- distance[!discarded]
n0 <- length(ttt[ttt==0])
n1 <- length(ttt[ttt==1])
d1 <- distance[ttt==1]
d0 <- distance[ttt==0]
d <- matrix(0, ncol=n0, nrow=n1)
rownames(d) <- names(ttt[ttt==1])
colnames(d) <- names(ttt[ttt==0])
for (i in 1:n1)
d[i,] <- abs(d1[i]-d0)
I kept getting this error after the last command:
Error in d[i, ] <- abs(d1[i] - d0) :
number of items to replace is not a multiple of replacement length
I think the root of the problem is the way d1 and d0 are being defined. As
the code is written, distance and ttt could be of different lengths (they
will be if units have been discarded). I altered the code to read:
ttt <- treat[!discarded]
ddd <- distance[!discarded]
n0 <- length(ttt[ttt==0])
n1 <- length(ttt[ttt==1])
d1 <- ddd[ttt==1]
d0 <- ddd[ttt==0]
d <- matrix(0, ncol=n0, nrow=n1)
rownames(d) <- names(ttt[ttt==1])
colnames(d) <- names(ttt[ttt==0])
for (i in 1:n1)
d[i,] <- abs(d1[i]-d0)
Now, if only I could figure out how to recompile the package...
Ben
Hi,
I have used the following function to create a data set of my unmatched cases (unmatched.data <- lalonde[!row.names(lalonde)%in%row.names(match.data(m.out1)),]), however, when I do so, the distance variable is not included. I would like to be able to compare the propensity scores of my unmatched treatment and control cases with those of the matched treated and control cases. How would I go about making sure that this variable is included in my unmatched data set?
Thanks as always for your help!
Kerry
Kerry Richmond
Department of Criminology and Criminal Justice
University of Maryland, College Park
--
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/