# Error Bars question and suggestion

3 messages
Open this post in threaded view
|

## Error Bars question and suggestion

 Hello statistics people, I would like to know the most common way to use error bars in a plot. In our lab, we use error bars by subdividing a scatter plot into a number of bins, and then display the 95% confidence of each bin a an error bar.   The macro below simulates such a plot, and shows bin#2 as a green box with its statistics in the Log window. For calculating an error bar, we use the equation:         e = 2* stDev/sqrt(n-1), where "2* stDev" corresponds to ~95% confidence and "n" is the number of dots in the bin. We are not interested whether the curve follows any polynomial or other fit, but whether two curves (partially) differ significantly. Question 1: is this the most common way to use error bars? Question 2: is it better to replace the equation above by the Student's test, which would result in larger error bars for very small count n? (Michael Schmid made me aware of this). This discussion started when I suggested to extend ImageJ's Plot commands with something like: Plot.add("error bars", xValues, yValues, options) where the options define start, stop, number of bins and confidence. Best regards, Norbert macro "Simulated Error Bars"{         close("Error Bars");         random("seed", 1);         nPoints = 500;         xValues = newArray(nPoints);         yValues = newArray(nPoints);         for(jj = 0; jj < nPoints; jj++){                 x = random;                 y= 1 + sqrt(x) + (random - 0.5) * sqrt(random);                 xValues[jj] = x;                 yValues[jj] = y;         }                 nBins = 10;         start = 0;         stop = 1;         eX = newArray(nBins);         eY = newArray(nBins);         eBar = newArray(nBins);                 for(bin = 0; bin < nBins; bin++){                 binWidth = (stop - start)/nBins;                 left = bin * binWidth;                 right = left + binWidth;                 binContent = newArray(nPoints);                 count = 0;                 for(jj = 0; jj < nPoints; jj++){                         x = xValues[jj];                         y = yValues[jj];                         if(x >= left && x < right){                                 binContent[count++] = y;                         }                 }                 binContent = Array.trim(binContent, count);                 Array.getStatistics(binContent, min, max, mean, stdDev);                 eX[bin] = (left + right)/2;                 eY[bin] = mean;                 eBar[bin] = 2 * stdDev/sqrt(count-1);                 if(bin== 2){                         print("\\Clear");                         print("Green Bin:");                         print("left=" , left);                         print("right=" , right);                         print("mean=" , mean);                         print("stDev=" , stdDev);                         print("count=" , count);                         print("error=" , eBar[bin]);                                         }         }         Plot.create("Error Bars", "Age", "Y");         Plot.setLimits(0, 1, 0, 3);         Plot.setColor("gray");         Plot.add("+", xValues, yValues);         Plot.setColor("red");         Plot.setLineWidth(2);         Plot.add("line", eX, eY);         Plot.add("error bars", eBar);         Plot.show;         Plot.freeze();         greenBinX = newArray(0.2, 0.3, 0.3, 0.2);         greenBinY = newArray(0, 0, 3, 3);         toUnscaled(greenBinX, greenBinY);         makeSelection("polygon", greenBinX, greenBinY);         changeValues(0xffffff, 0xffffff, 0xaaffaa);         run("Select None"); } Output: ======= Green Bin: left= 0.2 right= 0.3 mean= 1.5106 stDev= 0.2031 count= 40 error= 0.06506 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html