Table Of Contents

ANOVA (Two-Way ANOVA) (G Dataflow)

Version:
Last Modified: August 28, 2017

Performs a two-way analysis of variance (ANOVA) and determines whether the two factors and their interaction have a significant effect on the experimental outcome.

connector_pane_image
datatype_icon

levels b

Number of levels in factor b. levels b must be equal to or greater than 2. Otherwise, this node returns an error.

Specify a positive value if b is a fixed effect. Specify a negative value if b is a random effect.

Default: 2

datatype_icon

levels a

Number of levels in factor a. levels a must be equal to or greater than 2. Otherwise, this node returns an error.

Specify a positive value if a is a fixed effect. Specify a negative value if a is a random effect.

Default: 2

datatype_icon

x

All the observational data. You must specify an equal number of observations in each cell.

The total number of data points in x must equal the result of multiplying the number of levels in each factor and the number of observations per cell. Otherwise, this node returns an error. For example, if level a is 2, level b is 3, and observations per cell is 2, x must contain 12 data points.

datatype_icon

index a

The level of factor a to which the corresponding observation belongs.

This node converts arrays that do not begin with 0 or have nonconsecutive values into arrays of consecutive values that begin with 0. For example, if you enter [3, 5, 7], this node converts the array into [0, 1, 2].

datatype_icon

index b

The level of factor b to which the corresponding observation belongs.

This node converts arrays that do not begin with 0 or have nonconsecutive values into arrays of consecutive values that begin with 0. For example, if you enter [3, 5, 7], this node converts the array into [0, 1, 2].

datatype_icon

error in

Error conditions that occur before this node runs.

The node responds to this input according to standard error behavior.

Standard Error Behavior

Many nodes provide an error in input and an error out output so that the node can respond to and communicate errors that occur while code is running. The value of error in specifies whether an error occurred before the node runs. Most nodes respond to values of error in in a standard, predictable way.

error in does not contain an error error in contains an error
If no error occurred before the node runs, the node begins execution normally.

If no error occurs while the node runs, it returns no error. If an error does occur while the node runs, it returns that error information as error out.

If an error occurred before the node runs, the node does not execute. Instead, it returns the error in value as error out.

Default: No error

datatype_icon

observations per cell

Number of observations in each cell. observations per cell must be equal to or greater than 1. Otherwise, this node returns an error.

Default: 1 — Causes this node to ignore the interaction between the factors and return False in ab significant?. Both levels a and levels b must be positive if observations per cell is 1.

datatype_icon

significance level

Acceptable probability that this node incorrectly rejects a true null hypothesis.

significance level is a threshold value used to judge whether a factor has a significant effect on the experimental outcome.

Default: 0.05

datatype_icon

significance

Significance values of the factors and their interaction.

Algorithm for Calculating significance

This node calculates significance using the following equations:

significance a = { Prob { F dofa , dofe > fa } ( if b is fixed ) Prob { F dofa , dofab > fa } ( if b is random )
significance b = { Prob { F dofb , dofe > fb } ( if a is fixed ) Prob { F dofb , dofab > fb } ( if a is random )
significance a b = Prob { F dofab , dofe > fab }

where Fn1, n2 is the F distribution with n1 and n2 degrees of freedom.

datatype_icon

significance a

Significance value associated with factor a.

datatype_icon

significance b

Significance value associated with factor b.

datatype_icon

significance ab

Significance value associated with the interaction of factors a and b.

datatype_icon

summary

A 4-by-5 matrix that displays the obtained values for analysis.

summary = [ ssa dofa ssb dofb ssab dofab sse dofe msa fa msb fb msab fab mse 0.0 F critical a F critical b F critical ab 0.0 ]

where

  • The first column corresponds to the sum of squares associated with factor a, factor b, ab interaction, and residual error
  • The second column corresponds to the respective degrees of freedom
  • The third column corresponds to the respective mean squares
  • The fourth column corresponds to the respective F values
  • The fifth column corresponds to the respective F critical values

Algorithm for Calculating Sums of Squares

This node calculates the sums of squares using the following equations:

ssa = b L p = 0 a 1 ( x p ¯ x ¯ ) 2
ssb = a L q = 0 b 1 ( x q ¯ x ¯ ) 2
ssab = { L p = 0 a 1 q = 0 b 1 ( x p q ¯ x p ¯ x q ¯ + x ¯ ) 2 ( if L > 1 ) 0 ( if L = 1 )
sse = { p = 0 a 1 q = 0 b 1 r = 0 L 1 ( x p q r x p q ¯ ) 2 ( if L > 1 ) p = 0 a 1 q = 0 b 1 ( x p q 1 x p 1 ¯ x q 1 ¯ + x 1 ¯ ) 2 ( if L = 1 )

where

  • b is the number of levels in factor b
  • L is the number of observational data per cell
  • a is the number of levels in factor a
  • p is the index of each level in factor a, starting from 0
  • x p ¯ is the mean of all the observational data at the pth level of factor a
  • x ¯ is the mean of all the observational data
  • q is the index of each level in factor b, starting from 0
  • x q ¯ is the mean of all the observational data at the qth level of factor b
  • x p q ¯ is the mean of all the observational data at the pth and qth levels of factors a and b respectively
  • r is the index of each observational data in a cell defined by the pth and qth levels of factors a and b respectively
  • xpqr is the rth observational data at the pth and qth levels of factors a and b respectively
  • xpq1 is the only observational data in the cell defined by the pth and qth levels of factors a and b respectively, when L = 1
  • x p 1 ¯ is the mean of all the observational data at the pth level of factor a, when L = 1
  • x q 1 ¯ is the mean of all the observational data at the qth levels of factor b, when L = 1
  • x 1 ¯ is the mean of all the observational data, when L = 1

Algorithm for Calculating Degrees of Freedom

This node calculates the degrees of freedom using the following equations:

dofa = a 1
dofb = b 1
dofab = { ( a 1 ) ( b 1 ) ( if L > 1 ) 0 ( if L = 1 )
dofe = { a b ( L 1 ) ( if L > 1 ) ( a 1 ) ( b 1 ) ( if L = 1 )

where

  • a is the number of levels in factor a
  • b is the number of levels in factor b
  • L is the number of observational data per cell

Algorithm for Calculating Mean Squares

This node calculates the mean squares using the following equations:

msa = ssa dofa
msb = ssb dofb
msab = ssab dofab
mse = sse dofe

where

  • ssa is a measure of variation attributed to factor a
  • dofa is the degree of freedom of ssa
  • ssb is a measure of variation attributed to factor b
  • dofb is the degree of freedom of ssb
  • ssab is a measure of variation attributed to the interaction of factors a and b
  • dofab is the degree of freedom of ssab
  • sse is a measure of variation attributed to random fluctuation
  • dofe is the degree of freedom of sse

Algorithm for Calculating F Values

This node calculates the F values using the following equations:

fa = { msa mse ( if b is fixed ) msa msab ( if b is random )
fb = { msb mse ( if a is fixed ) msb msab ( if a is random )
fab = msab mse

where

  • msa is the mean square quantity of ssa
  • mse is the mean square quantity of sse
  • msab is the mean square quantity of ssab
  • msb is the mean square quantity of ssb

Algorithm for Calculating F Critical Values

F critical a is the value satisfying the following equation:

{ Prob { F dofa , dofe F critical a } = significance level ( if b is fixed ) Prob { F dofa , dofab F critical a } = significance level ( if b is random )

F critical b is the value satisfying the following equation:

{ Prob { F dofb , dofe F critical b } = significance level ( if a is fixed ) Prob { F dofb , dofab F critical b } = significance level ( if a is random )

F critical ab is the value satisfying the following equation:

Prob { F dofab , dofe > F critical ab } = significance level

where Fn1, n2 is the F distribution with n1 and n2 degrees of freedom.

datatype_icon

conclusion

Result of the analysis. Each Boolean value in this output indicates whether the corresponding factor or interaction of the factors has a significant effect on the experimental outcome.

True The corresponding element in significance is equal to or less than significance level, which means the corresponding factor or interaction of the factors has a significant effect on the experimental outcome.
False The corresponding element in significance is -1 or is greater than significance level, which means the corresponding factor or interaction of the factors does not have a significant effect on the experimental outcome.
datatype_icon

a significant?

Boolean value that indicates whether factor a has a significant effect on the experimental outcome.

datatype_icon

b significant?

Boolean value that indicates whether factor b has a significant effect on the experimental outcome.

datatype_icon

ab significant?

Boolean value that indicates whether the interaction of factors a and b has a significant effect on the experimental outcome.

datatype_icon

error out

Error information.

The node produces this output according to standard error behavior.

Standard Error Behavior

Many nodes provide an error in input and an error out output so that the node can respond to and communicate errors that occur while code is running. The value of error in specifies whether an error occurred before the node runs. Most nodes respond to values of error in in a standard, predictable way.

error in does not contain an error error in contains an error
If no error occurred before the node runs, the node begins execution normally.

If no error occurs while the node runs, it returns no error. If an error does occur while the node runs, it returns that error information as error out.

If an error occurred before the node runs, the node does not execute. Instead, it returns the error in value as error out.

Random and Fixed Effects

A factor is a basis for categorizing data. A factor is a random effect if it has a large population of levels about which you want to draw conclusions but such that you cannot sample from all levels. You thus pick levels at random and generalize about all levels.

A factor is a fixed effect if you can sample from all levels about which you want to draw conclusions.

ANOVA Cells

In ANOVA, cells mean level combinations of multiple factors. For example, if you specify the inputs for this node as shown in the following table, the second table below illustrates the cell distributions.

levels b 3
levels a 2
x [10, 17, 20, 25, 12, 4, 11, 16, 18, 24, 14, 6]
index a [0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0]
index b [0, 0, 2, 1, 1, 2, 0, 0, 2, 1, 1, 2]
observations per cell 2
factor b (Level 0) factor b (Level 1) factor b (Level 2)
factor a (Level 0) 10, 11 12, 14 4, 6
factor a (Level 1) 17, 16 25, 24 20, 18

Using age and weight as factors, this example demonstrates how to test whether age or weight has a significant effect on the number of sit-ups a person can do.

The following table defines the levels of age and weight.

factor a (age) Level 0 10 years old to 20 year old
Level 1 21 years old to 30 years old
factor b (weight) Level 0 less than 50 kg
Level 1 between 50 kg and 70 kg
Level 2 more than 70 kg

The following table lists the results of a random sampling of twelve people. The results are based on a series of observations of how many sit-ups people from different age and weight groups can do.

spd-note-note
Note  

To perform a two-way analysis of variance, you must make at least one observation per level, and make the same number of observations per cell.

Person 1 14 years old (Level 0) 40 kg (Level 0) 10 sit-ups
Person 2 22 years old (Level 1) 48 kg (Level 0) 17 sit-ups
Person 3 27 years old (Level 1) 72 kg (Level 2) 20 sit-ups
Person 4 24 years old (Level 1) 65 kg (Level 1) 25 sit-ups
Person 5 12 years old (Level 0) 51 kg (Level 1) 12 sit-ups
Person 6 18 years old (Level 0) 71 kg (Level 2) 4 sit-ups
Person 7 16 years old (Level 0) 45 kg (Level 0) 11 sit-ups
Person 8 25 years old (Level 1) 49 kg (Level 0) 16 sit-ups
Person 9 29 years old (Level 1) 75 kg (Level 2) 18 sit-ups
Person 10 21 years old (Level 1) 61 kg (Level 1) 24 sit-ups
Person 11 17 years old (Level 0) 53 kg (Level 1) 14 sit-ups
Person 12 19 years old (Level 0) 73 kg (Level 2) 6 sit-ups

The following table lists the inputs and outputs of this node.

levels b 3
levels a 2
x [10, 17, 20, 25, 12, 4, 11, 16, 18, 24, 14, 6]
index a [0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0]
index b [0, 0, 2, 1, 1, 2, 0, 0, 2, 1, 1, 2]
observations per cell 2
significance level 0.05
significance significance a 3.4353E-06
significance b 0.000334898
significance ab 0.00612114
summary ssa 330.75
ssb 100.5
ssab 33.5
sse 7.5
dofa 1
dofb 2
dofab 2
dofe 6
msa 330.75
msb 50.25
msab 16.75
mse 1.25
fa 264.6
fb 40.2
fab 13.4
0.0 0
F critical a 5.98736
F critical b 5.14321
F critical ab 5.14321
0.0 0
conclusion a significant? True
b significant? True
ab significant? True

Because all the Boolean values in conclusion are True, you can conclude that based on the sampling data, age, weight, and the interaction of age and weight have a significant effect on the number of sit-ups a person can do.

Where This Node Can Run:

Desktop OS: Windows

FPGA: This product does not support FPGA devices

Web Server: Not supported in VIs that run in a web application


Recently Viewed Topics