One Way Test of Variance

Description

Here,we will use R to perform a one-way analysis of variance on a data frame containing sample values from two different groups. R includes an example data frame called sleep, which we will use for the test. The contents of sleep are shown below. To generate your own data frame for testing, see the page on the data.frame command here.

   extra group ID
1    0.7     1  1
2   -1.6     1  2
3   -0.2     1  3
4   -1.2     1  4
5   -0.1     1  5
6    3.4     1  6
7    3.7     1  7
8    0.8     1  8
9    0.0     1  9
10   2.0     1 10
11   1.9     2  1
12   0.8     2  2
13   1.1     2  3
14   0.1     2  4
15  -0.1     2  5
16   4.4     2  6
17   5.5     2  7
18   1.6     2  8
19   4.6     2  9
20   3.4     2 10

A one-way analysis of variance is performed in R using the {{oneway.test} command, and has 5 parameters:

  • formula: A formula showing the distribution of data. In our example, the formula is extra ~ group, which tells R that the values in extra are distributed according to group. In other words, each value belongs to the group identified in its row. Group names can be text or numbers, but must be included in the data frame for this test. Each group must have at least two values in it.
  • data: This is the data frame being tested. Here, we would put data = sleep.
  • subset: This parameter is not required. It can be used to declare a subset of values to be tested, rather than testing the entire data frame. If we only wanted to test the first 5 members of each group, we could put subset = c(1, 2, 3, 4, 5, 11, 12, 13, 14, 15) or subset=c(1:5, 11:15).
  • na.action: This parameter is a function that determines what R does when it encounters an NA "Not Available") value in the data frame. It can safely be ignored.
  • var.equal: This parameter determines whether the variances of each group are assumed to be equal or not, as R will perform a different kind of test depending on the assumption. Set it to TRUE to assume they are equal, or FALSE to assume they are not. The default value of this parameter is FALSE.

Sage Cell

Code

oneway.test(extra ~ group, data=sleep)

Options

none

Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.

Attribute

Permalink:

Author:

Date: 01 May 2019 15:13

Submitted by: Zane Corbiere

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License