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)
}
Hello,
If I were directly calling glm to create a propensity score, I would weight
the observations with a 1 for the treatment group and (# treatments/#
controls) for the control group. I am doing this especially when # of
treated observations is much less than the potential number of controls
because I don't want to overfit to the controls. In my current project, I
have a few hundred treated observations and 10,000's of possible matches.
Does MatchIt perform this weighting internally when doing nearest matching
when the exact option is not NULL? I don't want to provide this weight
directly via distance.options() because I think MatchIt is solving a
different glm for each exact strata and the weights would be wrong for any
specific strata.
Any ideas?
Thanks,
Hi Nikolaus,
Well, that is more of a "data manipulation in R" question rather than about MatchIt per se, but code like this should work for you:
data(lalonde)
m.out <- matchit(treat ~ age + educ + re74 + re75, data=lalonde, method="nearest")
m.out$match.matrix[1:10]
treated <- row.names(lalonde)[lalonde$treat==1]
subclasses <- rep(NA, length(lalonde$treat))
names(subclasses) <- rownames(lalonde)
j <- 0
for (i in treated) {
j <- j+1
subclasses[i] <- j
subclasses[m.out$match.matrix[rownames(m.out$match.matrix)==i]] <- j
}
print(subclasses[names(subclasses)%in%c("NSW1", "NSW2", "NSW3",
"PSID261", "PSID187", "PSID388")])
print(table(subclasses))
Liz
On 6/21/10 2:20 AM, "Nikolaus Viertl" <viertl(a)gmail.com> wrote:
Hi Liz!
Thanks for your fast reply.
In fact i read the "how_can_i". However, i need to use stratified analysis within R, by something like
coxph(Surv(survtime,event) ~ treat + strata(pair.id <http://pair.id/> ))
But for this i actually need a variable like "pair.id" - where i dont see an easy way how to get it out of the match.matrix.
And i hope there is an easy way - since many people probably need this way to analyse the data.
Thanks again,
Nikolaus.
On 20.06.2010, at 18:39, Stuart, Elizabeth A. wrote:
Dear Nikolaus,
Thanks for your note.
The match.matrix output that is included in the MatchIt output tells you who was matched to whom. See this FAQ for a bit more detail on getting the matched pair outcomes:
http://gking.harvard.edu/matchit/docs/How_Can_I.html
Thanks,
Liz
On 6/20/10 4:49 AM, "Nikolaus Viertl" <viertl(a)gmail.com <x-msg://3/viertl@gmail.com> > wrote:
Dear authors of the MathIt package!
First let me thank you and for the mathit package.
However, i have on question: Is there a way to easily get out the match procedures a variable which actually encodes the strata as defined by the matched pairs?
Many statisticians recommend to use paired (stratified) analysis of the matched samples - and therefore one needs the strata.
Thanks in advance,
Nikolaus Viertl.
Begin forwarded message:
From: Nikolaus Viertl <viertl(a)gmail.com <x-msg://3/viertl@gmail.com> >
Date: 20. Juni 2010 10:46:50 MESZ
To: dho(a)law.stanford.edu <x-msg://3/dho@law.stanford.edu>
Subject: MatchIt Package R
Dear Mr. Ho!
First let me thank you and for the mathit package.
However, i have on question: Is there a way to easily get out the match procedures a variable which actually encodes the strata as defined by the matched pairs?
Many statisticians recommend to use paired (stratified) analysis of the matched samples - and therefore one needs the strata.
Thanks in advance,
Nikolaus Viertl.
Dear Nikolaus,
Thanks for your note.
The match.matrix output that is included in the MatchIt output tells you who was matched to whom. See this FAQ for a bit more detail on getting the matched pair outcomes:
http://gking.harvard.edu/matchit/docs/How_Can_I.html
Thanks,
Liz
On 6/20/10 4:49 AM, "Nikolaus Viertl" <viertl(a)gmail.com> wrote:
Dear authors of the MathIt package!
First let me thank you and for the mathit package.
However, i have on question: Is there a way to easily get out the match procedures a variable which actually encodes the strata as defined by the matched pairs?
Many statisticians recommend to use paired (stratified) analysis of the matched samples - and therefore one needs the strata.
Thanks in advance,
Nikolaus Viertl.
Begin forwarded message:
From: Nikolaus Viertl <viertl(a)gmail.com>
Date: 20. Juni 2010 10:46:50 MESZ
To: dho(a)law.stanford.edu
Subject: MatchIt Package R
Dear Mr. Ho!
First let me thank you and for the mathit package.
However, i have on question: Is there a way to easily get out the match procedures a variable which actually encodes the strata as defined by the matched pairs?
Many statisticians recommend to use paired (stratified) analysis of the matched samples - and therefore one needs the strata.
Thanks in advance,
Nikolaus Viertl.