I've got some data that has this basic shape (using R):
df <- data.frame(group=sample(LETTERS, 500, T, log(2:27)), type=sample(c("x","y"), 500, T, c(.4,.6)), value=sample(0:20, 500, T))
I want to investigate the ratios between
y within each group.
One way would be to first compute the mean of
y within each group, then use the
compressed.ratio function I wrote (does it have a name? I just made it up) to map the ratio between the means from the interval [0,Inf] onto the interval [-1,1] so that it can be plotted symmetrically in
compressed.ratio <- function(x, y) (x-y)/(x+y) df.means <- ddply(df, .(group,type), function(df) data.frame(mean=mean(df$value),n=nrow(df))) with(df.means, plot(unique(group), compressed.ratio(mean[type=="x"], mean[type=="y"]), ylim=c(-1,1)))
In addition to this, I'd like to show something that gets at the amount of variation within each group, and also shows where there might be problems with very small numbers of samples in a given group.
But I haven't thought of a good way to do these - the obvious way to show uncertainty due to sample size would be to use standard-error bars, but I'm not sure how to compute the standard-error of a ratio between two groups of quantities. Would it be appropriate to compute the ratios of each
mean(y), and then
mean(x) to each
y, and treat those as
x+y separate measurements? Or maybe to do some kind of random simulation, doing draws from the
y pools and taking their ratios?
Finally, does anyone know some kind of visual standard way to show both the standard-deviation and standard-error in the same graph? Maybe a thick error bar and thin whiskers?