Using Shading in Coefficient Plots

Having recently discovered the R package denstrip, I was struck by intuitive it is to use shading to express uncertainty. If you need convincing, check out the paper by Jennifer Lundquist and Ken Lin linked below.

coefplot.fadeI wondered whether this would also work well for generic coefficient plots to examine regression results. The proof is in the pudding, so here’s some quickly thrown together code (also on Gist).

library(denstrip)
fade <- function(x, labels=names(coef(x)), expo=FALSE, xlab="", ylab="", bty="n", ...) {
# argument: a regression, additional arguments passed on to plot() and text()
coe <- summary(x)$coefficients[,1] # extract coefficients
cse <- summary(x)$coefficients[,2] # standard errors
len <- length(coe) # how many coefficients (without intercept)
if(expo == TRUE) { # exponential form
coe <- exp(coe)
cse <- exp(cse)
}
ran <- c(min(coe)- 3*max(cse), max(coe)+3*max(cse)) # range of values
plot(0, ylim=c(1.5,len+0.5), xlim=ran, xlab=xlab, ylab=ylab, bty=bty, type="n", ..., axes=FALSE) # empty plot
# title, xlab, ylab, etc. can be used here.
for(i in 2:len) {
dens <- rnorm(mean=coe[i], sd=cse[i], n=1000)
denstrip(dens, at=i) # passing arguments conflicts with plot()
text(ran[1],i, labels[i], adj = c(0,0), ...) # adj to left-align
# cex, col can be used here
}
axis(1)
}

Well, it does work (see figure above). If we add an abline(v=0, lty=3), we can easily highlight the zero line.

coefplot.armHowever, intuitive as it is, I’m not really convinced. Here’s the coefficient plot the arm package produces. While it doesn’t use shading, lines of different thickness are used to indicate the standard errors — nicely de-emphasizing the end-point. There’s more emphasis on the point estimate (i.e. the coefficient itself: the square), while my code hides this. I did try adding a white line at the point estimate (third figure, below), but this doesn’t resolve my biggest worry: the amount of ink that is used to convey the message… I’m just not convinced that the shading adds that much to the relatively simple coefficient plots in the package arm.

coefplot.mod

(There’s an argument width that could be added to line calling denstrip, like width=0.2, but it hasn’t convinced me enough.)

Jackson, Christopher H. 2008. “Displaying Uncertainty with Shading.” The American Statistician 62 (4): 340–47. doi:10.1198/000313008X370843.

Lundquist, Jennifer H., and Ken-Hou Lin. 2015. “Is Love (Color) Blind? The Economy of Race among Gay and Straight Daters.” Social Forces, March, sov008. doi:10.1093/sf/sov008.

Tables to Figures, well…

There are people more eloquent out there trying to convince researchers to use figures rather than tables in scientific publications. The only (real) reservation I could find so far is that figures only may be difficult for meta-analyses. Turns out there is one more…

coefplot1

I have recently received the following comment on a submitted paper:

“the graphical representation of the analysis does not offer enough (statistical) insights such as to evaluate the quality of the analysis done, nor to assess the validity of the conclusions drawn from it.”

To be fair to the reviewer, the other feedback I got was very constructive. I just wanted to use the opportunity to highlight that there is much more to do in terms of spreading the word about coefficient plots (above/to the right the kind of figure I used in the paper). The odd thing is that I even included tables in the appendix; in this day of online supplementary material there is no reason not to. Unfortunately, it seems that the reviewer overlooked them…

Creating Sparklines in MS Word

A few years back I’ve prepared a step-by-step guide to creating sparklines in SPSS and MS Word. I’ve come up with the idea long before learning about what is today widely known as sparklines from Edward Tufte (writing a physics lab report in high school). After a recent comment by a colleague (“you can do that in Word?”), I’ve decided to put this tutorial online.

The general principle applies to any software package to create the original graphs, including MS Excel. Continue reading