# naginterfaces.library.anova.factorial¶

naginterfaces.library.anova.factorial(y, lfac, nblock, inter, irdf)[source]

factorial computes an analysis of variance table and treatment means for a complete factorial design.

For full information please refer to the NAG Library document for g04ca

https://www.nag.com/numeric/nl/nagdoc_29.2/flhtml/g04/g04caf.html

Parameters
yfloat, array-like, shape

The observations in standard order, see Notes.

lfacint, array-like, shape

must contain the number of levels for the th factor, for .

nblockint

The number of blocks. If there are no blocks, set or .

interint

The maximum number of factors in an interaction term. If no interaction terms are to be computed, set or .

irdfint

The adjustment to the residual and total degrees of freedom. The total degrees of freedom are set to and the residual degrees of freedom adjusted accordingly. For examples of the use of see Further Comments.

Returns
tablefloat, ndarray, shape

The first rows of contain the analysis of variance table. The first column contains the degrees of freedom, the second column contains the sum of squares, the third column (except for the row corresponding to the total sum of squares) contains the mean squares, i.e., the sums of squares divided by the degrees of freedom, and the fourth and fifth columns contain the ratio and significance level, respectively (except for rows corresponding to the total sum of squares, and the residual sum of squares). All other cells of the table are set to zero.

The first row corresponds to the blocks and is set to zero if there are no blocks.

The th row corresponds to the total sum of squares for and the th row corresponds to the residual sum of squares.

The central rows of the table correspond to the main effects followed by the interaction if specified by .

The main effects are in the order specified by and the interactions are in lexical order, see Notes.

itotalint

The row in corresponding to the total sum of squares. The number of treatment effects is .

tmeanfloat, ndarray, shape

The treatment means. The position of the means for an effect is given by the index in . For a given effect the means are in standard order, see Notes.

efloat, ndarray, shape

The estimated effects in the same order as for the means in .

imeanint, ndarray, shape

Indicates the position of the effect means in . The effect means corresponding to the first treatment effect in the ANOVA table are stored in up to . Other effect means corresponding to the th treatment effect, , are stored in up to .

semeanfloat, ndarray, shape

The standard error of the difference between means corresponding to the th treatment effect in the ANOVA table.

bmeanfloat, ndarray, shape

contains the grand mean, if , up to contain the block means.

rfloat, ndarray, shape

The residuals.

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, and

Constraint: .

(errno )

On entry, the number of plots per block is incompatible with the number of plot factors.

(errno )

On entry, and .

Constraint: when , must be a multiple of .

(errno )

On entry, the values of are constant.

Warns
NagAlgorithmicWarning
(errno )

The residual sum of squares is zero.

(errno )

There are no degrees of freedom for the residual sum of squares.

Notes

In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.

An experiment consists of a collection of units, or plots, to which a number of treatments are applied. In a factorial experiment the effects of several different sets of conditions are compared, e.g., three different temperatures, , and , and two different pressures, and . The conditions are known as factors and the different values the conditions take are known as levels. In a factorial experiment the experimental treatments are the combinations of all the different levels of all factors, e.g.,

The effect of a factor averaged over all other factors is known as a main effect, and the effect of a combination of some of the factors averaged over all other factors is known as an interaction. This can be represented by a linear model. In the above example if the response was for the th replicate of the th level of and the th level of the linear model would be

where is the overall mean, is the main effect of , is the main effect of , is the interaction and is the random error term. In order to find unique estimates constraints are placed on the parameters estimates. For the example here these are:

where denotes the estimate.

If there is variation in the experimental conditions (e.g., in an experiment on the production of a material different batches of raw material may be used, or the experiment may be carried out on different days), then plots that are similar are grouped together into blocks. For a balanced complete factorial experiment all the treatment combinations occur the same number of times in each block.

factorial computes the analysis of variance (ANOVA) table by sequentially computing the totals and means for an effect from the residuals computed when previous effects have been removed. The effect sum of squares is the sum of squared totals divided by the number of observations per total. The means are then subtracted from the residuals to compute a new set of residuals. At the same time the means for the original data are computed. When all effects are removed the residual sum of squares is computed from the residuals. Given the sums of squares an ANOVA table is then computed along with standard errors for the difference in treatment means.

The data for factorial has to be in standard order given by the order of the factors. Let there be factors, in that order with levels respectively. Standard order requires the levels of factor are in order and within each level of the levels of are in order and so on.

For an experiment with blocks the data is for block then for block , etc. Within each block the data must be arranged so that the levels of factor are in order and within each level of the levels of are in order and so on. Any within block replication of treatment combinations must occur within the levels of .

The ANOVA table is given in the following order. For a complete factorial experiment the first row is for blocks, if present, then the main effects of the factors in their order, e.g., followed by , etc. These are then followed by all the two factor interactions then all the three factor interactions, etc., the last two rows being for the residual and total sums of squares. The interactions are arranged in lexical order for the given factor order. For example, for the three factor interactions for a five factor experiment the interactions would be in the following order:

References

Cochran, W G and Cox, G M, 1957, Experimental Designs, Wiley

Davis, O L, 1978, The Design and Analysis of Industrial Experiments, Longman

John, J A and Quenouille, M H, 1977, Experiments: Design and Analysis, Griffin