This function performs Levene's test for homogeneity of variance across two or more independent groups.
test.levene(formula, data, method = c("median", "mean"),
conf.level = 0.95, hypo = TRUE, descript = TRUE,
plot = TRUE, violin.alpha = 0.3, violin.trim = FALSE,
box = TRUE, box.alpha = 0.2, box.width = 0.2,
jitter = TRUE, jitter.size = 1.25, jitter.width = 0.05, jitter.alpha = 0.2,
gray = FALSE, start = 0.9, end = 0.4, color = NULL,
xlab = NULL, ylab = NULL, ylim = NULL, breaks = ggplot2::waiver(),
title = "", subtitle = "", digits = 2, p.digits = 3, as.na = NULL,
check = TRUE, output = TRUE)
Returns an object of class misty.object
, which is a list with following entries:
function call (call
), type of analysis type
, formula (formula
), data frame with
the outcome and grouping variable, (data
), specification of function arguments (args
),
and a list with descriptive statistics including confidence interval and an object of class
"anova"
(result
).
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
, null and alternative hypothesis are shown on the console.
logical: if TRUE
, descriptive statistics are shown on the console.
logical: if TRUE
, a plot showing violin plots with boxplots is drawn.
a numeric value indicating the opacity of the violins.
logical: if TRUE
, the tails of the violins to the range of the data is trimmed.
logical: if TRUE
(default), boxplots are drawn.
a numeric value indicating the opacity of the boxplots.
a numeric value indicating the width of the boxplots.
logical: if TRUE
(default), jittered data points are drawn.
a numeric value indicating the size
aesthetic for the jittered data points.
a numeric value indicating the amount of vertical and horizontal jitter.
a numeric value indicating 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 subtitlefor the plot.
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
, argument specification is checked.
logical: if TRUE
, 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
dat <- data.frame(y = c(2, 3, 4, 5, 5, 7, 8, 4, 5, 2, 4, 3),
group = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3))
# Levene's test based on the median with 95% confidence interval
test.levene(y ~ group, data = dat)
# Levene's test based on the arithmetic mean with 95% confidence interval
test.levene(y ~ group, data = dat, method = "mean")
# Levene's test based on the median with 99% confidence interval
test.levene(y ~ group, data = dat, conf.level = 0.99)
if (FALSE) {
# Levene's test based on the median with 95
# plot results
test.levene(y ~ group, data = dat, plot = TRUE)
# Load ggplot2 package
library(ggplot2)
# Save plot, ggsave() from the ggplot2 package
ggsave("Levene-test.png", dpi = 600, width = 5, height = 6)
# Levene's test based on the median with 95
# extract plot
p <- test.levene(y ~ group, data = dat, output = FALSE)$plot
p
# Extract data
plotdat <- test.levene(y ~ group, data = dat, output = FALSE)$data
# Draw violin and boxplots in line with the default setting of test.levene()
ggplot(plotdat, aes(group, y, fill = group)) +
geom_violin(alpha = 0.3, trim = FALSE) +
geom_boxplot(alpha = 0.2, width = 0.2) +
geom_jitter(alpha = 0.2, width = 0.05, size = 1.25) +
theme_bw() + guides(fill = "none")
}
Run the code above in your browser using DataLab