describe
. Alternatively, plots of means +/- one standard deviation may be drawn.error.bars(x,stats=NULL, ylab = "Dependent Variable",xlab="Independent Variable",
main=NULL,eyes=TRUE, ylim = NULL, xlim=NULL,alpha=.05,sd=FALSE, labels = NULL,
pos = NULL, arrow.len = 0.05,arrow.col="black", add = FALSE,bars=FALSE,within=FALSE,
...)
If within=TRUE, the error bars are corrected for the correlation with the other variables by reducing the variance by a factor of (1-smc). This allows for comparisons between variables.
The error bars are normally calculated from the data using the describe function. If, alternatively, a matrix of statistics is provided with column headings of values, means, and se, then those values will be used for the plot (using the stats option). However, in this case, the error bars will be one s.e. rather than a function of the alpha level.
If sd is TRUE, then the error bars will represent one standard deviation from the mean rather than be a function of alpha and the standard errors.
error.crosses
for two way error bars, error.bars.by
for error bars for different groupsIn addition, as pointed out by Jim Lemon on the R-help news group, error bars or confidence intervals may be drawn using
For advice why not to draw bar graphs with error bars, see
x <- replicate(20,rnorm(50))
boxplot(x,notch=TRUE,main="Notched boxplot with error bars")
error.bars(x,add=TRUE)
abline(h=0)
error.bars(attitude,alpha=.5,main="50 percent confidence limits") #another example
error.bars(attitude,bar=TRUE) #show the use of bar graphs
#combine with a strip chart and boxplot
stripchart(attitude,vertical=TRUE,method="jitter",jitter=.1,pch=19,
main="Stripchart with 95 percent confidence limits")
boxplot(attitude,add=TRUE)
error.bars(attitude,add=TRUE,arrow.len=.2)
#use statistics from somewhere else
my.stats <- data.frame(values=c(1,4,8),mean=c(10,12,18),se=c(2,3,5))
error.bars(stats=my.stats,type="b",main="data with confidence intervals")
#note that in this case, the error bars are 1 s.e. To modify that, change the s.e.
#Consider the case where we get stats from describe
temp <- describe(attitude)
error.bars(stats=temp)
#these error bars will be just one s.e.
#adjust the s.e. to vary by alpha level
alpha <- .05
temp[,"se"] <- temp[,"se"] * qt(1-alpha/2,temp[,"n"])
error.bars(stats=temp)
#show these do not differ from the other way by overlaying the two
error.bars(attitude,add=TRUE)
Run the code above in your browser using DataLab