Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visualization of pre/post matching balance statistics using dotplot

To visually display the covariate balance before and after the matching procedure I have written the following code:

library(lattice)
library(gridExtra)

StandBias.df= data.frame(
  Category= rep(c("A", "B", "C", "D", "E", "F"), 2),
  Groups = factor(c(rep("0", 6), rep("1", 6))),
  Values = c(0.26, 0.4, 0.3, 0.21, 0.6, 0.14, 0.12, -0.04, -0.23, 0.08, 0.14, -0.27))

d1<-dotplot(Category ~Values, data = StandBias.df, groups = Groups,
            main = "Standardized Mean Differences", col = c("black", "grey50"), pch=c(22,15), xlab=NULL,
            key=list(text=list(c("Pre-Matching", "Post-Matching")),
                     points=list(col = c("black", "grey50"), pch=c(22,15)), 
                     space="bottom", border=T))

Ttest.df = data.frame(
  Category= rep(c("A", "B", "C", "D", "E", "F"), 2),
  Groups = factor(c(rep("0", 6), rep("1", 6))),
  Values = c(0.12, 0.02, 0.69, 0.19, 0.05, 0.01, 0.62, 0.77, 0.54, 0.24, 0.92, 0.51))


d2<-dotplot(Category ~Values, data = Ttest.df, groups = Groups,
            main = "p-values", col = c("black", "grey50"), pch=c(22,15), xlab=NULL,
            key=list(text=list(c("Pre-Matching", "Post-Matching")),
                     points=list(col = c("black", "grey50"), pch=c(22,15)), 
                     space="bottom", border=T))

grid.arrange(d1,d2,nrow=1)

PROBLEM: I would like to add vertical lines at 0.1 for the p-values (d2) and at [-0.25; 0.25] for the standardized mean values (d1) so that we have a visual cutoff for balanced/not balanced.

This it what I tried: For d1, I added the following lines after the last line, i.e.

...

space ="bottom", border=T),

panel=function(...){
    panel.abline(v=0.25)
    panel.abline(v=-0.25)}
)

The modified code produces a plot with the requested vertical line(s) but no data points.

Any ideas are highly welcome!

Many thanks.

like image 730
TiF Avatar asked Oct 07 '22 18:10

TiF


1 Answers

You are almost there. When writing a custom panel, you need to include the original panel code, otherwise nothing gets plotted.

So, the panel function should look like this (add panel.dotplot(...) to your code):

panel=function(...){
              panel.dotplot(...)
              panel.abline(v=0.25)
              panel.abline(v=-0.25)
              }

The full code:

d1<-dotplot(Category ~Values, data = StandBias.df, groups = Groups,
            main = "Standardized Mean Differences", col = c("black", "grey50"), pch=c(22,15), xlab=NULL,
            key=list(text=list(c("Pre-Matching", "Post-Matching")),
                     points=list(col = c("black", "grey50"), pch=c(22,15)), 
                     space="bottom", border=T),
            panel=function(...){
              panel.dotplot(...)
              panel.abline(v=0.25)
              panel.abline(v=-0.25)
              }
)

Ttest.df = data.frame(
  Category= rep(c("A", "B", "C", "D", "E", "F"), 2),
  Groups = factor(c(rep("0", 6), rep("1", 6))),
  Values = c(0.12, 0.02, 0.69, 0.19, 0.05, 0.01, 0.62, 0.77, 0.54, 0.24, 0.92, 0.51))


d2<-dotplot(Category ~Values, data = Ttest.df, groups = Groups,
            main = "p-values", col = c("black", "grey50"), pch=c(22,15), xlab=NULL,
            key=list(text=list(c("Pre-Matching", "Post-Matching")),
                     points=list(col = c("black", "grey50"), pch=c(22,15)), 
                     space="bottom", border=T),
          panel=function(...){
            panel.dotplot(...)
            panel.abline(v=0.25)
            panel.abline(v=-0.25)
          }
)

grid.arrange(d1,d2,nrow=1)

enter image description here

like image 119
Andrie Avatar answered Oct 12 '22 23:10

Andrie