6
$\begingroup$

I have conducted an analysis in which I start with a set of informed prior parameter distributions, and then conduct sequential analyses that constrain the distributions with data.

I am currently using density plots to visualize these results, but I am wondering how I can most effectively convey the process of parameter constraint to a non-bayesian audience.

Questions

Is there a more effective way to visualize the sequential constraint of parameter uncertainty?

Specifically:

  • is there a way to I indicate the progression within the plot?
  • would an alternative approach, such as a boxplot, be more effective in communicating the change in range and central tendency?
  • would it help to offset the density=0 line so that the lines are not overlapping?
  • would it be effective to use sparklines, e.g. with the 95%CI and medians indicated by a point and a value?
  • is it appropriate to exclude the y-axis density scale since the area = 1?

I have included two parameters here, although I will actually be plotting between six and fifteen.

Examples

Here are some example data:

n = 10000; set.seed(0)
prior       <- data.frame(theta1 = rnorm(n, 10, 3),
                          theta2 = rnorm(n, 20, 1.5))
posterior1  <- data.frame(theta1 = rnorm(n, 11, 0.5),
                          theta2 = rnorm(n, 22, 1))
posterior2  <- data.frame(theta1 = rnorm(n, 10.5, 0.3),
                          theta2 = rnorm(n, 23, 0.8))

My current approach is along the lines of plotting the densities increasingly dark grey to black:

for(i in 1:2){
 plot(density(posterior2[,i]), main = colnames(prior)[i], 
      xlim = c(0,20*i), xlab = '', ylab = '', col = 'red)
 lines(density(posterior1[,i]), col = 'darkgrey')
 lines(density(prior[,i]), col = 'grey')
}

These figures are from the above example code:

enter image description here

Here is some of the actual data, with the x-axis scaled to focus on posteriors rather than priors, but at this scale the priors, despite being informed, look fairly flat. (These figures also illustrate that the posteriors are from mcmc chains rather than standard densities as in the example above).

enter image description here

$\endgroup$

3 Answers 3

5
$\begingroup$

One option would be to use color to show the progression, specifically by highlighting the final result in red - inspired by sparklines, including those on p. 51 of Beautiful Evidence.

Tufte's sparklines:

enter image description here

Translation as a probability distribution:

enter image description here

Tufte might suggest reducing the height to make the posterior angles approach 45 degrees.

$\endgroup$
2
$\begingroup$

Personally, I kind of like the facet_grid() from ggplot for showing how elements change over different experiments - especially if there's a visually noticeable progression. Here's an example using some of your numbers:

library(ggplot2)    
n = 10000; set.seed(0)
x <- data.frame(theta1 = rnorm(n, 10, 3),
    theta2 = rnorm(n, 20, 1.5),
    theta3 = rnorm(n, 11, 0.5),
    theta4 = rnorm(n, 22, 1),
    theta5 = rnorm(n, 10.5, 0.3),
    theta6 = rnorm(n, 23, 0.8))


x <- melt(x)

x$plots <- c(rep(1,20000),rep(2,20000),rep(3,20000))
ggplot(x, aes(value, fill=variable)) + geom_density() + facet_grid(~plots)
`# use fill or colour, at your discretion`
$\endgroup$
3
  • $\begingroup$ this is a good suggestion, except that it would be easier to compare the medians and upper/lower quantiles when the distributions being compared are on the same axes. $\endgroup$ Commented Aug 23, 2011 at 17:45
  • $\begingroup$ ggplot(x, aes(value, fill=variable)) + geom_density() like that? $\endgroup$ Commented Aug 23, 2011 at 17:57
  • $\begingroup$ yes, much nicer. thanks. except that in my application, I would put the parameter sets in different plots since there are so many, and because the scales and units are all different. +1 for the helpful code, but my question is really more about visualizing the progression than how to overlap density plots. My updated figure is still my favorite (showing progression with color), but perhaps a more effective alternative exists. $\endgroup$ Commented Aug 23, 2011 at 18:37
2
$\begingroup$

Another possibility is animating the graphics building one on top of the other. This is really just for shits and giggles though, not sure how it would fly for a stats heavy crowd or on paper...

library(ggplot2)
library(animation)
n = 10000; set.seed(0)
x <- data.frame(theta1 = rnorm(n, 10, 3),
    theta2 = rnorm(n, 20, 1.5),
    theta3 = rnorm(n, 11, 0.5),
    theta4 = rnorm(n, 22, 1),
    theta5 = rnorm(n, 10.5, 0.3),
    theta6 = rnorm(n, 23, 0.8))


x <- melt(x)
plots <- list()
x$plots <- c(rep(1,20000),rep(2,20000),rep(3,20000))
plots$p1 <- ggplot(droplevels(subset(x, variable == "theta1")), aes(value, color=variable)) + geom_density() + scale_x_continuous(limits=c(0,30)) + scale_y_continuous(limits=c(0,1))
plots$p2 <- ggplot(droplevels(subset(x, variable == "theta1" | variable == "theta2")), aes(value, color=variable)) + geom_density() + scale_x_continuous(limits=c(0,30)) + scale_y_continuous(limits=c(0,1))
plots$p3 <- ggplot(droplevels(subset(x, variable == "theta1" | variable == "theta2" | variable == "theta3")), aes(value, color=variable)) + geom_density() + scale_x_continuous(limits=c(0,30)) + scale_y_continuous(limits=c(0,1))
plots$p4 <- ggplot(droplevels(subset(x, variable == "theta1" | variable == "theta2" | variable == "theta3" | variable == "theta4")), aes(value, color=variable)) + geom_density() + scale_x_continuous(limits=c(0,30)) + scale_y_continuous(limits=c(0,1))
saveGIF(lapply(plots, print),clean=TRUE)
$\endgroup$
1
  • $\begingroup$ nice! I like the approach, thanks for introducing me to this package. $\endgroup$ Commented Aug 24, 2011 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.