mean_compare
compares means across 3+ independent groups with a
one-way ANOVA. The function also calculates the descriptive statistics for
each group and the variance explained (i.e., R^2 aka eta^2) by the nominal
grouping variable. mean_compare
is simply a wrapper for
oneway.test
plus some extra calculations.
mean_compare
will work with 2 independent groups; however it arguably
makes more sense to use mean_diff
in that case.
mean_compare(
x,
nom,
lvl = levels(as.factor(nom)),
var.equal = TRUE,
r2.ci.type = "Fdist",
ci.level = 0.95,
rtn.table = TRUE,
check = TRUE
)
list of numeric vectors containing statistical information about the mean comparison: 1) nhst = one-way ANOVA stat info in a numeric vector, 2) desc = descriptive statistics stat info in a numeric vector, 3) std = standardized effect sizes stat info in a numeric vector, 4) anova = traditional ANOVA table in a numeric matrix (only returned if rtn.table = TRUE).
1) nhst = one-way ANOVA stat info in a numeric vector
average mean difference across group pairs
NA to remind the user there is no standard error for the average mean difference
F-value
numerator degrees of freedom
denominator degrees of freedom
two-sided p-value
2) desc = descriptive statistics stat info in a numeric vector (note there could be more than 3 groups - groups i, j, and k are just provided as an example)
mean of group k
mean of group j
mean of group i
standard deviation of group k
standard deviation of group j
standard deviation of group i
sample size of group k
sample size of group j
sample size of group i
3) std = standardized effect sizes stat info in a numeric vector
R^2 estimate
R^2 standard error (only available if r2.ci.type
= "classic")
R^2 lower bound of the confidence interval
R^2 upper bound of the confidence interval
R^2-adjusted estimate
R^2-adjusted standard error (only available if r2.ci.type
= "classic")
R^2-adjusted lower bound of the confidence interval
R^2-adjusted upper bound of the confidence interval
4) anova = traditional ANOVA table in a numeric matrix (only returned if rtn.table = TRUE).
The dimlabels of the matrix was "effect" for the rows
and "info" for the columns. There are two rows with rownames 1. "nom" and 2.
"Residuals" where "nom" refers to the between-group effect of the nominal
variable and "Residuals" refers to the within-group residual errors. There
are 5 columns with colnames 1. "SS" = sum of squares, 2. "df" = degrees of
freedom, 3. "MS" = mean squares, 4. "F" = F-value. and 5. "p" = p-value. Note
the F-value and p-value will differ from the "nhst" returned vector if
var.equal
= FALSE because the traditional ANOVA table always assumes
variances are equal (i.e. var.equal
= TRUE).
numeric vector.
atomic vector (e.g., factor) the same length as x
that is a
nominal variable. It identifies the 3+ groups with 3+ unique values (other
than missing values).
character vector with length 3+ specifying the unique values for
the 3+ groups. If nom
is a factor, then lvl
should be the
factor levels rather than the underlying integer codes. This argument
allows you to specify the order of the descriptive statistics in the return
object, which will be opposite the order of lvl
for consistency with
mean_diff
and mean_change
.
logical vector of length 1 specifying whether the variances of the groups are assumed to be equal (TRUE) or not (FALSE). If TRUE, a traditional one-way ANOVA is computed; if FALSE, Welch's ANOVA is computed. These two tests differ by their denominator degrees of freedom, F-value, and p-value.
character vector with length 1 specifying the type of confidence intervals to compute for the variance explained (i.e., R^2 aka eta^2). There are currently two options: 1) "Fdist" which calculates a non-symmetrical confidence interval based on the non-central F distribution (pg. 38, Smithson, 2003), 2) "classic" which calculates the confidence interval based on a large-sample theory standard error (eq. 3.6.3 in Cohen, Cohen, West, & Aiken, 2003), which is taken from Olkin & Finn (1995) - just above eq. 10. The confidence intervals for R^2-adjusted use the same formula as R^2, but replace R^2 with R^2 adjusted. Technically, the R^2 adjusted confidence intervals can have poor coverage (pg. 54, Smithson, 2003)
numeric vector of length 1 specifying the confidence level.
ci.level
must range from 0 to 1.
logical vector of length 1 specifying whether the traditional ANOVA table should be returned as the last element of the return object.
logical vector of length 1 specifying whether the input
arguments should be checked for errors. For example, if nom
has
length different than the length of x
. This is a tradeoff between
computational efficiency (FALSE) and more useful error messages (TRUE).
Cohen, J., Cohen, P., West, A. G., & Aiken, L. S. (2003). Applied Multiple Regression/Correlation Analysis for the Behavioral Science - third edition. New York, NY: Routledge.
Olkin, I., & Finn, J. D. (1995). Correlations redux. Psychological Bulletin, 118(1), 155-164.
Smithson, M. (2003). Confidence intervals. Thousand Oaks, CA: Sage Publications.
oneway.test
the workhorse for mean_compare
,
means_compare
for multiple variables across the same 3+ groups,
ci.R2
for confidence intervals of the variance explained,
mean_diff
for a single variable across only 2 groups,
mean_compare(x = mtcars$"mpg", nom = mtcars$"gear")
mean_compare(x = mtcars$"mpg", nom = mtcars$"gear", var.equal = FALSE)
mean_compare(x = mtcars$"mpg", nom = mtcars$"gear", rtn.table = FALSE)
mean_compare(x = mtcars$"mpg", nom = mtcars$"gear", r2.ci.type = "classic")
Run the code above in your browser using DataLab