Test for Equal Means in a One-Way Layout

Test whether two or more samples from normal distributions have the same means. The variances are not necessarily assumed to be equal.

oneway.test(formula, data, subset, na.action, var.equal = FALSE)
a formula of the form lhs ~ rhs where lhs gives the sample values and rhs the corresponding groups.
an optional matrix or data frame (or similar: see model.frame) containing the variables in the formula formula. By default the variables are taken from environment(formula).
an optional vector specifying a subset of observations to be used.
a function which indicates what should happen when the data contain NAs. Defaults to getOption("na.action").
a logical variable indicating whether to treat the variances in the samples as equal. If TRUE, then a simple F test for the equality of means in a one-way analysis of variance is performed. If FALSE, an approximate method of Welch (1951) is used, which generalizes the commonly known 2-sample Welch test to the case of arbitrarily many samples.

If the right-hand side of the formula contains more than one term, their interaction is taken to form the grouping.


  • A list with class "htest" containing the following components:
  • statisticthe value of the test statistic.
  • parameterthe degrees of freedom of the exact or approximate F distribution of the test statistic.
  • p.valuethe p-value of the test.
  • methoda character string indicating the test performed.
  • data.namea character string giving the names of the data.


B. L. Welch (1951), On the comparison of several mean values: an alternative approach. Biometrika, 38, 330--336.

See Also

The standard t test (t.test) as the special case for two samples; the Kruskal-Wallis test kruskal.test for a nonparametric test for equal location parameters in a one-way layout.

  • oneway.test
library(stats) ## Not assuming equal variances oneway.test(extra ~ group, data = sleep) ## Assuming equal variances oneway.test(extra ~ group, data = sleep, var.equal = TRUE) ## which gives the same result as anova(lm(extra ~ group, data = sleep))
Documentation reproduced from package stats, version 3.3, License: Part of R 3.3

Community examples

Looks like there are no examples yet.