means_compare {quest}R Documentation

Mean differences for multiple variables across 3+ independent groups (one-way ANOVAs)

Description

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.

Usage

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
)

Arguments

data

data.frame of data.

vrb.nm

character vector of length 1 with colnames from data specifying the variables.

nom.nm

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).

lvl

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.

var.equal

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.

r2.ci.type

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)

ci.level

numeric vector of length 1 specifying the confidence level. ci.level must range from 0 to 1.

rtn.table

logical vector of length 1 specifying whether the traditional ANOVA tables should be returned as the last element of the return object.

check

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).

Value

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

diff_avg

average mean difference across group pairs

se

NA to remind the user there is no standard error for the average mean difference

F

F-value

df_num

numerator degrees of freedom

df_den

denominator degrees of freedom

p

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_'lvl[k]'

mean of group k

mean_'lvl[j]'

mean of group j

mean_'lvl[i]'

mean of group i

sd_'lvl[k]'

standard deviation of group k

sd_'lvl[j]'

standard deviation of group j

sd_'lvl[i]'

standard deviation of group i

n_'lvl[k]'

sample size of group k

n_'lvl[j]'

sample size of group j

n_'lvl[i]'

sample size of group i

3) std = standardized effect sizes stat info in a data.frame

r2_reg_est

R^2 estimate

r2_reg_se

R^2 standard error (only available if r2.ci.type = "classic")

r2_reg_lwr

R^2 lower bound of the confidence interval

r2_reg_upr

R^2 upper bound of the confidence interval

r2_adj_est

R^2-adjusted estimate

r2_adj_se

R^2-adjusted standard error (only available if r2.ci.type = "classic")

r2_adj_lwr

R^2-adjusted lower bound of the confidence interval

r2_adj_upr

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.

References

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.

See Also

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,

Examples


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")


[Package quest version 0.2.0 Index]