Error Bar & Confidence Interval

From Augix' Wiki

Jump to: navigation, search

ref: http://www.cyclismo.org/tutorial/R/confidence.html

  • Calculating a 95% Confidence Interval from a t Distribution
values = iris$Sepal.Length
 
n = length(values)
m = mean(values)
s = sd(values)
 
error = qt(0.975,df=n-1)*s/sqrt(n)
lower_limit = m - error
upper_limit = m + error
 
plot(density(values))
abline( v = c(lower_limit, upper_limit), col="red" )
  • Calculating a 95% Confidence Interval from a Normal Distribution
values = iris$Sepal.Length
 
n = length(values)
m = mean(values)
s = sd(values)
 
error = qnorm(0.975)*s/sqrt(n)
lower_limit = m - error
upper_limit = m + error
 
plot(density(values))
abline( v = c(lower_limit, upper_limit), col="red" )


  • How to Calculate Confidence Interval from a Normal distribution
95% C. I. = M ± (1.96 * SE)
  • How to plot Error Bars
bardata <- 1:3 # create some data
bar <- barplot(bardata, ylim = c(0,4)) # store location of bars in bar, and
                                       # plot the barplot. ylim is used to
                                       # make room for the error bar later
error <- c(.2,.4,.7) # create imaginary standard error
arrows(bar, bardata + error, bar, bardata - error,
       length = 0.10, # width of the arrowhead
       angle = 90, # angle of the arrowhead
       code = 3 # arrowhead in both ends
)
Personal tools