Hi Derek,
Here is some code that I had modified (from the original matchit code) to do a weighted
jitter plot.
Liz
library(MatchIt)
data(lalonde)
m.out <- matchit(treat ~ re74 + re75 + age + educ + married + hispan + black +
nodegree,
data=lalonde, method="subclass")
m.data <- match.data(m.out)
# ATE weights
pdf("WeightsIPTW.pdf")
m.data$weights.iptw <- ifelse(m.data$treat==1, 1/m.data$distance,
1/(1-m.data$distance))
weights <- m.data$weights.iptw
matched <- weights!=0
pscore <- m.data$distance
treat <- m.data$treat
jitp <-
jitter(rep(1,length(treat)),factor=6)+(treat==1)*(weights==0)-(treat==0)-(weights==0)*(treat==0)
cwt <- sqrt(weights)
minp <- min(pscore,na.rm=T)
maxp <- max(pscore,na.rm=T)
plot(pscore,xlim=c(minp,maxp+0.1*(maxp-minp)),ylim=c(-1.5,2.5),
type="n",ylab="",xlab="Propensity Score",
axes=F,main="Distribution of Propensity Scores")
points(pscore[treat==1&weights!=0],jitp[treat==1&weights!=0],
pch=18,cex=cwt[treat==1&weights!=0])
points(pscore[treat==1&weights==0],jitp[treat==1&weights==0],
pch=5,col="grey",cex=0.5)
points(pscore[treat==0&weights!=0],jitp[treat==0&weights!=0],
pch=18,cex=cwt[treat==0&weights!=0])
points(pscore[treat==0&weights==0],jitp[treat==0&weights==0],
pch=5,col="grey",cex=0.5)
axis(1)
text(sum(range(na.omit(pscore)))/2,2.5,"Unmatched Treatment Units")
text(sum(range(na.omit(pscore)))/2,1.5,"Matched Treatment Units")
text(sum(range(na.omit(pscore)))/2,0.5,"Matched Control Units")
text(sum(range(na.omit(pscore)))/2,-0.5,"Unmatched Control Units")
box()
dev.off()
pdf("WeightsOdds.pdf")
m.data$weights.odds <- ifelse(m.data$treat==1, 1, m.data$distance/(1-m.data$distance))
weights <- m.data$weights.odds
matched <- weights!=0
pscore <- m.data$distance
treat <- m.data$treat
jitp <-
jitter(rep(1,length(treat)),factor=6)+(treat==1)*(weights==0)-(treat==0)-(weights==0)*(treat==0)
cwt <- sqrt(weights)
minp <- min(pscore,na.rm=T)
maxp <- max(pscore,na.rm=T)
plot(pscore,xlim=c(minp,maxp+0.1*(maxp-minp)),ylim=c(-1.5,2.5),
type="n",ylab="",xlab="Propensity Score",
axes=F,main="Distribution of Propensity Scores")
points(pscore[treat==1&weights!=0],jitp[treat==1&weights!=0],
pch=18,cex=cwt[treat==1&weights!=0])
points(pscore[treat==1&weights==0],jitp[treat==1&weights==0],
pch=5,col="grey",cex=0.5)
points(pscore[treat==0&weights!=0],jitp[treat==0&weights!=0],
pch=18,cex=cwt[treat==0&weights!=0])
points(pscore[treat==0&weights==0],jitp[treat==0&weights==0],
pch=5,col="grey",cex=0.5)
axis(1)
text(sum(range(na.omit(pscore)))/2,2.5,"Unmatched Treatment Units")
text(sum(range(na.omit(pscore)))/2,1.5,"Matched Treatment Units")
text(sum(range(na.omit(pscore)))/2,0.5,"Matched Control Units")
text(sum(range(na.omit(pscore)))/2,-0.5,"Unmatched Control Units")
box()
dev.off()
On 9/6/12 3:46 PM, "Derek Ng" <dng(a)jhsph.edu> wrote:
I would like to replicate the scaling factor of the dots in the matchit jitter
plot for data points that are weighted for a modified graph.
I am estimating the ATT, so all treated subjects are equal to cex=1.
In the documentation, it says "the size of each point is proportional to the
weight given to that unit".
Is the cex function the appropriate way to scale the size of each
point?
For example, if a control subject is matched with a weight of 2.2, would
that mean the appropriate point size is cex=2.2? Similarly, if the control
subject weight is 0.25, then the cex=0.25?
When I do this, it does not seem to be the same scaling factor as the MatchIt
jitter plot (the larger points look too big and the smaller points look too
small). I also could not find the source code that generates the standardized
jitter plot (is that available?).
Any help is very appreciated.
-
---
MatchIt mailing list served by HUIT
List Address: matchit(a)lists.gking.harvard.edu
Subscribe/Unsubscribe:
http://lists.gking.harvard.edu/mailman/listinfo/ei
MatchIt Software and Documentation:
http://gking.harvard.edu/matchit/
Browse/Search List Archive:
http://lists.gking.harvard.edu/mailman/private/matchit/
Matchit mailing list
Matchit(a)lists.gking.harvard.edu
https://lists.gking.harvard.edu/mailman/listinfo/matchit