R · Uncategorized

A modest proposal- coloured confidence intervals

I am of the opinion that confidence intervals should be shown as a range, and coloured/ shaded bands are a good way to show it. They are a probability distribution after all (but you can’t make histogram because it disappears to invisibility after 3 sigma, so bands seems the best plan). Admittedly, I am trying to show things are a long way from 7 sigma.

poly_conf_int <- function(success, trials, aa, stepsize, sigma, colr){
 ci <- binom.confint(success, trials, method=c("wilson"), conf.level = sigma)
 lower <- ci[1,5] 
 upper <- ci[1,6] 
 a <- polygon(x=c(aa,aa+stepsize,aa+stepsize,aa), y=c(upper,upper,lower,lower),
 col=colr, border=NA)
}


plot7sig <- function(success, trials, aa, stepsize){
 library(binom)
 bands <- c('#ffffb2','#fed976','#feb24c','#fd8d3c','#fc4e2a','#e31a1c','#b10026')
 sigmas <- c(0.682689492137086,
 0.954499736103642,
 0.997300203936740,
 0.999936657516334,
 0.999999426696856,
 0.999999998026825,
 0.999999999997440)
 sapply(7:1, function(x){poly_conf_int(success, trials, aa, stepsize, sigmas[x], bands[x])})
}

plot(c(0,4), c(.48,.62), type="n", frame.plot=NA)
plot7sig(56246, 100279, 1, 1)
lines(c(1,2), c(56246/100279,56246/100279))
lines(c(0,1), c(.5,.5), lty=2, col="#777777")

lbls <- c("expected", "actual",
 "1 sigma CI", "2 sigma CI",
 "3 sigma CI", "4 sigma CI",
 "5 sigma CI", "6 sigma CI",
 "7 sigma CI")
typs <- c(2,1,1,1,1,1,1,1,1)
weights <- c(1,1,3,3,3,3,3,3,3)
clrs <- c("#000000", "#000000", '#ffffb2','#fed976','#feb24c','#fd8d3c','#fc4e2a','#e31a1c','#b10026')

legend("right", legend=lbls, lty=typs, lwd=weights, col=clrs, bty="n")

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s