# ANOVA (Two-Way ANOVA) (G Dataflow)

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.

## 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

## 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

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

## 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].

## 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].

## 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

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

## 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

## significance

Significance values of the factors and their interaction.

Algorithm for Calculating significance

This node calculates significance using the following equations:

$\mathrm{significance}\text{\hspace{0.17em}}a=\left\{\begin{array}{cc}\mathrm{Prob}\left\{{F}_{\mathrm{dofa},\text{\hspace{0.17em}}\text{\hspace{0.17em}}\mathrm{dofe}}>\mathrm{fa}\right\}& \left(\mathrm{if}\text{\hspace{0.17em}}b\text{\hspace{0.17em}}\mathrm{is}\text{\hspace{0.17em}}\mathrm{fixed}\right)\\ \mathrm{Prob}\left\{{F}_{\mathrm{dofa},\text{\hspace{0.17em}}\text{\hspace{0.17em}}\mathrm{dofab}}>\mathrm{fa}\right\}& \left(\mathrm{if}\text{\hspace{0.17em}}b\text{\hspace{0.17em}}\mathrm{is}\text{\hspace{0.17em}}\mathrm{random}\right)\end{array}$
$\mathrm{significance}\text{\hspace{0.17em}}b=\left\{\begin{array}{cc}\mathrm{Prob}\left\{{F}_{\mathrm{dofb},\text{\hspace{0.17em}}\text{\hspace{0.17em}}\mathrm{dofe}}>\mathrm{fb}\right\}& \left(\mathrm{if}\text{\hspace{0.17em}}a\text{\hspace{0.17em}}\mathrm{is}\text{\hspace{0.17em}}\mathrm{fixed}\right)\\ \mathrm{Prob}\left\{{F}_{\mathrm{dofb},\text{\hspace{0.17em}}\text{\hspace{0.17em}}\mathrm{dofab}}>\mathrm{fb}\right\}& \left(\mathrm{if}\text{\hspace{0.17em}}a\text{\hspace{0.17em}}\mathrm{is}\text{\hspace{0.17em}}\mathrm{random}\right)\end{array}$
$\mathrm{significance}\text{\hspace{0.17em}}ab=\mathrm{Prob}\left\{{F}_{\mathrm{dofab},\text{\hspace{0.17em}}\text{\hspace{0.17em}}\mathrm{dofe}}>\mathrm{fab}\right\}$

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

### significance a

Significance value associated with factor a.

### significance b

Significance value associated with factor b.

### significance ab

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

## summary

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

$\mathrm{summary}=\left[\begin{array}{cc}\mathrm{ssa}& \mathrm{dofa}\\ \mathrm{ssb}& \mathrm{dofb}\\ \mathrm{ssab}& \mathrm{dofab}\\ \mathrm{sse}& \mathrm{dofe}\end{array}\phantom{\rule{0ex}{0ex}}\text{\hspace{0.17em}}\phantom{\rule{0ex}{0ex}}\phantom{\square }\begin{array}{cc}\mathrm{msa}& \mathrm{fa}\\ \mathrm{msb}& \mathrm{fb}\\ \mathrm{msab}& \mathrm{fab}\\ \mathrm{mse}& 0.0\end{array}\phantom{\rule{0ex}{0ex}}\text{\hspace{0.17em}}\phantom{\rule{0ex}{0ex}}\phantom{\square }\begin{array}{c}F\text{\hspace{0.17em}}\mathrm{critical}\text{\hspace{0.17em}}a\\ F\text{\hspace{0.17em}}\mathrm{critical}\text{\hspace{0.17em}}b\\ F\text{\hspace{0.17em}}\mathrm{critical}\text{\hspace{0.17em}}\mathrm{ab}\\ 0.0\end{array}\right]$

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:

$\mathrm{ssa}=bL\underset{p=0}{\overset{a-1}{\sum }}{\left(\stackrel{¯}{{x}_{p\cdot \cdot }}-\stackrel{¯}{{x}_{\cdots }}\right)}^{2}$
$\mathrm{ssb}=aL\underset{q=0}{\overset{b-1}{\sum }}{\left(\stackrel{¯}{{x}_{\cdot q\cdot }}-\stackrel{¯}{{x}_{\cdots }}\right)}^{2}$
$\mathrm{ssab}=\left\{\begin{array}{cc}L\underset{p=0}{\overset{a-1}{\sum }}\underset{q=0}{\overset{b-1}{\sum }}{\left(\stackrel{¯}{{x}_{pq\cdot }}-\stackrel{¯}{{x}_{p\cdot \cdot }}-\stackrel{¯}{{x}_{\cdot q\cdot }}+\stackrel{¯}{{x}_{\cdots }}\right)}^{2}& \left(\mathrm{if}\text{\hspace{0.17em}}L>1\right)\\ 0& \left(\mathrm{if}\text{\hspace{0.17em}}L=1\right)\end{array}$
$\mathrm{sse}=\left\{\begin{array}{cc}\underset{p=0}{\overset{a-1}{\sum }}\underset{q=0}{\overset{b-1}{\sum }}\underset{r=0}{\overset{L-1}{\sum }}{\left({x}_{pqr}-\stackrel{¯}{{x}_{pq\cdot }}\right)}^{2}& \left(\mathrm{if}\text{\hspace{0.17em}}L>1\right)\\ \underset{p=0}{\overset{a-1}{\sum }}\underset{q=0}{\overset{b-1}{\sum }}{\left({x}_{pq1}-\stackrel{¯}{{x}_{p\cdot 1}}-\stackrel{¯}{{x}_{\cdot q1}}+\stackrel{¯}{{x}_{\cdot \cdot 1}}\right)}^{2}& \left(\mathrm{if}\text{\hspace{0.17em}}L=1\right)\end{array}$

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
• $\stackrel{¯}{{x}_{p\cdot \cdot }}$ is the mean of all the observational data at the pth level of factor a
• $\stackrel{¯}{{x}_{\cdots }}$ is the mean of all the observational data
• q is the index of each level in factor b, starting from 0
• $\stackrel{¯}{{x}_{\cdot q\cdot }}$ is the mean of all the observational data at the qth level of factor b
• $\stackrel{¯}{{x}_{pq\cdot }}$ 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
• $\stackrel{¯}{{x}_{p\cdot 1}}$ is the mean of all the observational data at the pth level of factor a, when L = 1
• $\stackrel{¯}{{x}_{\cdot q1}}$ is the mean of all the observational data at the qth levels of factor b, when L = 1
• $\stackrel{¯}{{x}_{\cdot \cdot 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:

$\mathrm{dofa}=a-1$
$\mathrm{dofb}=b-1$
$\mathrm{dofab}=\left\{\begin{array}{cc}\left(a-1\right)\left(b-1\right)& \left(\mathrm{if}\text{\hspace{0.17em}}L>1\right)\\ 0& \left(\mathrm{if}\text{\hspace{0.17em}}L=1\right)\end{array}$
$\mathrm{dofe}=\left\{\begin{array}{cc}ab\left(L-1\right)& \left(\mathrm{if}\text{\hspace{0.17em}}L>1\right)\\ \left(a-1\right)\left(b-1\right)& \left(\mathrm{if}\text{\hspace{0.17em}}L=1\right)\end{array}$

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:

$\mathrm{msa}=\frac{\mathrm{ssa}}{\mathrm{dofa}}$
$\mathrm{msb}=\frac{\mathrm{ssb}}{\mathrm{dofb}}$
$\mathrm{msab}=\frac{\mathrm{ssab}}{\mathrm{dofab}}$
$\mathrm{mse}=\frac{\mathrm{sse}}{\mathrm{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:

$\mathrm{fa}=\left\{\begin{array}{cc}\frac{\mathrm{msa}}{\mathrm{mse}}& \left(\mathrm{if}\text{\hspace{0.17em}}b\text{\hspace{0.17em}}\mathrm{is}\text{\hspace{0.17em}}\mathrm{fixed}\right)\\ \frac{\mathrm{msa}}{\mathrm{msab}}& \left(\mathrm{if}\text{\hspace{0.17em}}b\text{\hspace{0.17em}}\mathrm{is}\text{\hspace{0.17em}}\mathrm{random}\right)\end{array}$
$\mathrm{fb}=\left\{\begin{array}{cc}\frac{\mathrm{msb}}{\mathrm{mse}}& \left(\mathrm{if}\text{\hspace{0.17em}}a\text{\hspace{0.17em}}\mathrm{is}\text{\hspace{0.17em}}\mathrm{fixed}\right)\\ \frac{\mathrm{msb}}{\mathrm{msab}}& \left(\mathrm{if}\text{\hspace{0.17em}}a\text{\hspace{0.17em}}\mathrm{is}\text{\hspace{0.17em}}\mathrm{random}\right)\end{array}$
$\mathrm{fab}=\frac{\mathrm{msab}}{\mathrm{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:

$\begin{array}{c}\left\{\begin{array}{cc}\mathrm{Prob}\left\{{F}_{\mathrm{dofa},\text{\hspace{0.17em}}\text{\hspace{0.17em}}\mathrm{dofe}}\ge F\mathit{critical}\text{\hspace{0.17em}}a\right\}=\mathbf{significance}\text{\hspace{0.17em}}\mathbf{level}& \left(\mathrm{if}\text{\hspace{0.17em}}b\text{\hspace{0.17em}}\mathrm{is}\text{\hspace{0.17em}}\mathrm{fixed}\right)\\ \mathrm{Prob}\left\{{F}_{\mathrm{dofa},\text{\hspace{0.17em}}\text{\hspace{0.17em}}\mathrm{dofab}}\ge F\mathit{critical}\text{\hspace{0.17em}}a\right\}=\mathbf{significance}\text{\hspace{0.17em}}\mathbf{level}& \left(\mathrm{if}\text{\hspace{0.17em}}b\text{\hspace{0.17em}}\mathrm{is}\text{\hspace{0.17em}}\mathrm{random}\right)\end{array}\end{array}$

F critical b is the value satisfying the following equation:

$\begin{array}{c}\left\{\begin{array}{cc}\mathrm{Prob}\left\{{F}_{\mathrm{dofb},\text{\hspace{0.17em}}\text{\hspace{0.17em}}\mathrm{dofe}}\ge F\mathit{critical}\text{\hspace{0.17em}}b\right\}=\mathbf{significance}\text{\hspace{0.17em}}\mathbf{level}& \left(\mathrm{if}\text{\hspace{0.17em}}a\text{\hspace{0.17em}}\mathrm{is}\text{\hspace{0.17em}}\mathrm{fixed}\right)\\ \mathrm{Prob}\left\{{F}_{\mathrm{dofb},\text{\hspace{0.17em}}\text{\hspace{0.17em}}\mathrm{dofab}}\ge F\mathit{critical}\text{\hspace{0.17em}}b\right\}=\mathbf{significance}\text{\hspace{0.17em}}\mathbf{level}& \left(\mathrm{if}\text{\hspace{0.17em}}a\text{\hspace{0.17em}}\mathrm{is}\text{\hspace{0.17em}}\mathrm{random}\right)\end{array}\end{array}$

F critical ab is the value satisfying the following equation:

$\mathrm{Prob}\left\{{F}_{\mathrm{dofab},\text{\hspace{0.17em}}\text{\hspace{0.17em}}\mathrm{dofe}}>F\mathrm{critical}\text{\hspace{0.17em}}\mathrm{ab}\right\}=\mathrm{significance}\text{\hspace{0.17em}}\mathrm{level}$

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

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

### a significant?

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

### b significant?

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

### ab significant?

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

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

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: Not supported

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