means_compare
compares means across 3+ independent groups with a
separate one-way ANOVA for each variable. 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. means_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.
means_compare(
data,
vrb.nm,
nom.nm,
lvl = levels(as.factor(data[[nom.nm]])),
var.equal = TRUE,
r2.ci.type = "classic",
ci.level = 0.95,
rtn.table = TRUE,
check = TRUE
)
list of data.frames containing statistical information about the mean comparisons for each variable (the rows of the data.frames are
vrb.nm
): 1) nhst = one-way ANOVA stat info in a data.frame,
2) desc = descriptive statistics stat info in a data.frame,
3) std = standardized effect sizes stat info in a data.frame,
4) anova = traditional ANOVA table in a numeric 3D array (only
returned if rtn.table = TRUE)
1) nhst = one-way ANOVA stat info in a data.frame
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 data.frame (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 data.frame
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 3D array (only returned if rtn.table = TRUE).
The dimlabels of the array are "effect" for
the rows, "info" for the columns, and "vrb" for the layers. 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). There are as many layers as length(vrb.nm)
with the laynames equal to vrb.nm
.
data.frame of data.
character vector of length 1 with colnames from data
specifying the variables.
character vector of length 1 with colnames from data
specifying the 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 freedoms, F-values, and p-values.
character vector with length 1 specifying the type of confidence intervals to compute for the variance explained (i.e., R^2 or 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 tables 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 vrb.nm
are
not colnames within data
. 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 means_compare
,
mean_compare
for a single variable across the same 3+ groups,
ci.R2
for confidence intervals of the variance explained,
means_diff
for multiple variables across only 2 groups,
means_compare(mtcars, vrb.nm = c("mpg","wt","qsec"), nom.nm = "gear")
means_compare(mtcars, vrb.nm = c("mpg","wt","qsec"), nom.nm = "gear",
var.equal = FALSE)
means_compare(mtcars, vrb.nm = c("mpg","wt","qsec"), nom.nm = "gear",
rtn.table = FALSE)
means_compare(mtcars, vrb.nm = "mpg", nom.nm = "gear")
Run the code above in your browser using DataLab