#! /usr/bin/Rscript options(verbose=FALSE, warn=-1) library(reshape) library(ggplot2) failure.probs = c(0.5, 0.2, 0.1, 0.05, 0.02, 0.01) trials = 1:1000 results = matrix(0, nrow=length(trials), ncol=length(failure.probs)) colnames(results) = failure.probs for (i in seq_along(failure.probs)) for (j in trials) results[j,i] = 1 - binom.test(c(j, 0), p=1-failure.probs[i], alternative='greater')$p.value # trim results to make the graph tidier results[results > 0.9999] = NA results.long = melt(results) colnames(results.long) = c('trials', 'p.failure', 'p.fixed') results.long$p.failure = ordered(results.long$p.failure) # there *is* a more elegant way to do this but i can't find it right now xbreaks = c(1,2,5,10,20,50,100,200,500,1000) xlabels = as.character(xbreaks) ybreaks = c(0.5, 0.75, 0.9, 0.95, 0.99, 1) ylabels = c('0.5 ', '0.75', '0.9 ', '0.95', '0.99', '1 ') graph = ggplot(results.long, aes(x=trials, y=p.fixed, colour=p.failure)) + geom_step() + scale_x_log10(name='Test runs after fix', breaks=xbreaks, labels=xlabels) + scale_y_continuous(name=expression(Pr(fixed)), limits=c(0.5, 1), breaks=ybreaks, labels=ylabels) + scale_colour_discrete(name=expression(Pr(failure))) png(filename="intermittent-failures.png", width=800, height=700) print(graph) dev.off()