Produce a barplot with error bars, annotated by Kruskal-Wallis or ANOVA p-value.
verboseBarplot(x, g,
main = "", xlab = NA, ylab = NA,
cex = 1, cex.axis = 1.5, cex.lab = 1.5, cex.main = 1.5,
color = "grey", numberStandardErrors = 1,
KruskalTest = TRUE, AnovaTest = FALSE, two.sided = TRUE,
addCellCounts=FALSE, horiz = FALSE, ylim = NULL, ...,
addScatterplot = FALSE,
pt.cex = 0.8, pch = 21, pt.col = "blue", pt.bg = "skyblue",
randomSeed = 31425, jitter = 0.6,
pointLabels = NULL,
label.cex = 0.8,
label.offs = 0.06,
adjustYLim = TRUE)
numerical or binary vector of data whose group means are to be plotted
a factor or a an object coercible to a factor giving the groups whose means are to be calculated.
main title for the plot.
label for the x-axis.
label for the y-axis.
character expansion factor for plot annotations.
character expansion factor for axis annotations.
character expansion factor for axis labels.
character expansion factor for the main title.
a vector giving the colors of the bars in the barplot.
size of the error bars in terms of standard errors. See details.
logical: should Kruskal-Wallis test be performed? See details.
logical: should ANOVA be performed? See details.
logical: should the printed p-value be two-sided? See details.
logical: should counts be printed above each bar?
logical: should the bars be drawn horizontally?
optional specification of the limits for the y axis. If not given, they will be determined automatically.
other parameters to function barplot
.
logical: should a scatterplot of the data be overlaid?
character expansion factor for the points.
shape code for the points.
color for the points.
background color for the points.
integer random seed to make plots reproducible.
amount of random jitter to add to the position of the points along the x axis.
Optional text labels for the points displayed using the scatterplot. If given, should be a character
vector of the same length as x. See labelPoints
.
Character expansion (size) factor for pointLabels
.
Offset for pointLabels
, as a fraction of the plot width.
logical: should the limits of the y axis be set so as to accomodate the individual points?
The adjustment is only carried out if input ylim
is NULL
and addScatterplot
is
TRUE
. In particular, if the user supplies ylim
, it is not touched.
None.
This function creates a barplot of a numeric variable (input x
) across the levels of a grouping
variable (input g
). The height of the bars equals the mean value of x
across the
observations with a given level of g
. By default, the barplot also shows plus/minus one standard
error. If you want only plus one standard error (not minus) choose two.sided=TRUE
. But the number
of standard errors can be determined with the input numberStandardErrors
. For example, if you want
a 95% confidence interval around the mean, choose numberStandardErrors=2
. If you don't want any
standard errors set numberStandardErrors=-1
. The function also outputs the p-value of a Kruskal
Wallis test (Fisher test for binary input data),
which is a non-parametric multi group comparison test. Alternatively, one can use Analysis
of Variance (Anova) to compute a p-value by setting AnovaTest=TRUE
. Anova is a generalization of
the Student t-test to multiple groups. In case of two groups, the Anova p-value equals the Student t-test
p-value. Anova should only be used if x
follows a normal distribution. Anova also assumes
homoscedasticity (equal variances). The Kruskal Wallis test is often advantageous since it makes no
distributional assumptions. Since the Kruskal Wallis test is based on the ranks of x
, it is more
robust with regard to outliers. All p-values are two-sided.
# NOT RUN {
group=sample(c(1,2),100,replace=TRUE)
height=rnorm(100,mean=group)
par(mfrow=c(2,2))
verboseBarplot(height,group, main="1 SE, Kruskal Test")
verboseBarplot(height,group,numberStandardErrors=2,
main="2 SE, Kruskal Test")
verboseBarplot(height,group,numberStandardErrors=2,AnovaTest=TRUE,
main="2 SE, Anova")
verboseBarplot(height,group,numberStandardErrors=2,AnovaTest=TRUE,
main="2 SE, Anova, only plus SE", two.sided=FALSE)
# }
Run the code above in your browser using DataLab