This function performs Levene's test for homogeneity of variance across two or more independent groups including a plot showing violins and boxplots representing the distribution of the outcome variable for each group.
test.levene(formula, data, method = c("median", "mean"), conf.level = 0.95,
hypo = TRUE, descript = TRUE, digits = 2, p.digits = 3, as.na = NULL,
plot = FALSE, violin = TRUE, box = TRUE, jitter = FALSE,
violin.alpha = 0.3, violin.trim = FALSE, box.alpha = 0.2,
box.width = 0.2, jitter.size = 1.25, jitter.width = 0.05,
jitter.height = 0, jitter.alpha = 0.2, gray = FALSE, start = 0.9,
end = 0.4, color = NULL, xlab = NULL, ylab = NULL, ylim = NULL,
ybreaks = ggplot2::waiver(), title = "", subtitle = "",
filename = NULL, width = NA, height = NA,
units = c("in", "cm", "mm", "px"), dpi = 600, write = NULL,
append = TRUE, check = TRUE, output = TRUE)Returns an object of class misty.object, which is a list with following
entries:
callfunction call
typetype of analysis
datadata frame specified in data
formulaformula of the current analysis
argsspecification of function arguments
plotggplot2 object for plotting the results
resultlist with result tables, i.e., descript for
descriptive statistics and test for the ANOVA
table
a formula of the form y ~ group where y is
a numeric variable giving the data values and group
a numeric variable, character variable or factor with two
or more than two values or factor levels giving the
corresponding groups.
a matrix or data frame containing the variables in the
formula formula.
a character string specifying the method to compute the
center of each group, i.e. method = "median" (default)
to compute the Levene's test based on the median (aka
Brown-Forsythe test) or method = "mean" to compute
the Levene's test based on the arithmetic mean.
a numeric value between 0 and 1 indicating the confidence level of the interval.
logical: if TRUE (default), null and alternative hypothesis
are shown on the console.
logical: if TRUE (default), descriptive statistics are shown
on the console.
an integer value indicating the number of decimal places to be used for displaying results.
an integer value indicating the number of decimal places to be used for displaying the p-value.
a numeric vector indicating user-defined missing values,
i.e. these values are converted to NA before
conducting the analysis.
logical: if TRUE, a plot showing violins with
boxplots is drawn.
logical: if TRUE (default), violins are drawn.
logical: if TRUE (default), boxplots are drawn.
logical: if TRUE (default), jittered data points
are drawn.
a numeric value between 0 and 1 for specifying the
alpha argument in the geom_violin
function for controlling the opacity of the violins.
logical: if TRUE, the tails of the violins to the
range of the data is trimmed.
a numeric value between 0 and 1 for specifying the
alpha argument in the geom_boxplot
function for controlling the opacity of the boxplots.
a numeric value indicating the width of the boxplots.
a numeric value indicating the size aesthetic
for the jittered data points.
a numeric value indicating the amount of horizontal jitter.
a numeric value indicating the amount of vertical jitter.
a numeric value between 0 and 1 for specifying the
alpha argument in the geom_jitter
function for controlling the opacity of the jittered
data points.
logical: if TRUE, the plot is drawn in gray scale.
a numeric value between 0 and 1, graphical parameter to specify the gray value at the low end of the palette.
a numeric value between 0 and 1, graphical parameter to specify the gray value at the high end of the palette.
a character vector, indicating the color of the violins and the boxes. By default, default ggplot2 colors are used.
a character string specifying the labels for the x-axis.
a character string specifying the labels for the y-axis.
a numeric vector of length two specifying limits of the limits of the y-axis.
a numeric vector specifying the points at which tick-marks are drawn at the y-axis.
a character string specifying the text for the title for the plot.
a character string specifying the text for the subtitle for the plot.
a character string indicating the filename argument (default is "NA_Pattern.pdf") including
the file extension for the ggsave function. Note that one of ".eps", ".ps",
".tex", ".pdf" (default), ".jpeg", ".tiff", ".png", ".bmp",
".svg" or ".wmf" needs to be specified as file extension in the file argument.
a numeric value indicating the width argument (default is the
size of the current graphics device) for the ggsave function.
a numeric value indicating the height argument
(default is the size of the current graphics device) for the ggsave function.
a character string indicating the units argument
(default is in) for the ggsave function.
a numeric value indicating the dpi argument
(default is 600) for the ggsave function.
a character string naming a text file with file extension
".txt" (e.g., "Output.txt") for writing the
output into a text file.
logical: if TRUE (default), output will be appended
to an existing text file with extension .txt specified
in write, if FALSE existing text file will be
overwritten.
logical: if TRUE (default), argument specification is checked.
logical: if TRUE (default), output is shown.
Takuya Yanagida takuya.yanagida@univie.ac.at
Levene's test is equivalent to a one-way analysis of variance (ANOVA) with the
absolute deviations of observations from the mean of each group as dependent
variable (center = "mean"). Brown and Forsythe (1974) modified the
Levene's test by using the absolute deviations of observations from the median
(center = "median"). By default, the Levene's test uses the absolute
deviations of observations from the median.
Brown, M. B., & Forsythe, A. B. (1974). Robust tests for the equality of variances. Journal of the American Statistical Association, 69, 364-367.
Rasch, D., Kubinger, K. D., & Yanagida, T. (2011). Statistics in psychology - Using R and SPSS. John Wiley & Sons.
aov.b, test.t, test.welch
# Example 1: Levene's test based on the median
test.levene(mpg ~ gear, data = mtcars)
# Example 2: Levene's test based on the arithmetic mean
test.levene(mpg ~ gear, data = mtcars, method = "mean")
# Example 3: Levene's test based on the median, plot results
test.levene(mpg ~ gear, data = mtcars, plot = TRUE)
if (FALSE) {
# Example 4: Write results into a text file
test.levene(mpg ~ gear, data = mtcars, write = "Levene.txt")
# Example 5: Levene's test based on the median, save plot
test.levene(mpg ~ gear, data = mtcars, plot = TRUE,
filename = "Levene-test.png", dpi = 600, width = 6, height = 5)
}
Run the code above in your browser using DataLab