Class ANOVAFactorial
- All Implemented Interfaces:
Serializable,Cloneable
Class ANOVAFactorial performs an analysis for an
n-way classification design with balanced data. For balanced data,
there must be an equal number of responses in each cell of the n-way
layout. The effects are assumed to be fixed effects. The model is an
extension of the two-way model to include n factors. The interactions
(two-way, three-way, up to n-way) can be included in the model, or
some of the higher-way interactions can be pooled into error.
setModelOrder specifies the number of factors to be included
in the highest-way interaction. For example, if three-way and higher-way
interactions are to be pooled into error, specify
modelOrder = 2. (By default,
modelOrder = nSubscripts - 1 with the last subscript being the
error subscript.) PURE_ERROR indicates there are repeated
responses within the n-way cell; POOL_INTERACTIONS
indicates otherwise.
Class ANOVAFactorial requires the responses as input into a
single vector y in lexicographical order, so that the response
subscript associated with the first factor varies least rapidly, followed by
the subscript associated with the second factor, and so forth. Hemmerle
(1967, Chapter 5) discusses the computational method.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndicates factornSubscriptsis not error.static final intIndicates factornSubscriptsis error. -
Constructor Summary
ConstructorsConstructorDescriptionANOVAFactorial(int nSubscripts, int[] nLevels, double[] y) Constructor forANOVAFactorial. -
Method Summary
Modifier and TypeMethodDescriptionfinal doublecompute()Analyzes a balanced factorial design with fixed effects.double[]Returns the analysis of variance table.double[]getMeans()Returns the subgroup means.double[][]Returns statistics relating to the sums of squares for the effects in the model.voidsetErrorIncludeType(int type) Sets error included type.voidsetModelOrder(int modelOrder) Sets the number of factors to be included in the highest-way interaction in the model.
-
Field Details
-
PURE_ERROR
public static final int PURE_ERRORIndicates factornSubscriptsis error.- See Also:
-
POOL_INTERACTIONS
public static final int POOL_INTERACTIONSIndicates factornSubscriptsis not error.- See Also:
-
-
Constructor Details
-
ANOVAFactorial
public ANOVAFactorial(int nSubscripts, int[] nLevels, double[] y) Constructor forANOVAFactorial.- Parameters:
nSubscripts- anintscalar containing the number of subscripts. Number of factors in the model + 1 (for the error term).nLevels- anintarray of lengthnSubscriptscontaining the number of levels for each of the factors for the firstnSubscripts-1 elements.nLevels[nSubscripts-1]is the number of observations per cell.y- adoublearray of lengthnLevels[0] * nLevels[1] * ... * nLevels[nSubscripts-1]containing the responses.ymust not contain NaN for any of its elements, i.e., missing values are not allowed.- Throws:
IllegalArgumentException- is thrown ifnLevels.length, andy.lengthare not consistent
-
-
Method Details
-
compute
public final double compute()Analyzes a balanced factorial design with fixed effects.- Returns:
- a
doublescalar containing the p-value for the overall F test
-
getMeans
public double[] getMeans()Returns the subgroup means. Note that thecomputemethod must be invoked first before invoking this method. Otherwise, the method throws aNullPointerExceptionexception.- Returns:
- a
doublearray containing the subgroup means
-
getTestEffects
public double[][] getTestEffects()Returns statistics relating to the sums of squares for the effects in the model. Note that thecomputemethod must be invoked first before invoking this method. Otherwise, the method throws aNullPointerExceptionexception.- Returns:
- a
doublematrix containing statistics relating to the sums of squares for the effects in the model. Here,$${\rm NEF} = {n \choose 1} + {n \choose 2} + \cdots + {n \choose \min(n,|{\rm model\_order}|)} $$
where
nis given bynSubscriptsifANOVAFactorial.POOL_INTERACTIONSis specified; otherwise,nSubscripts - 1. Suppose the factors are A, B, C, and error. WithmodelOrder = 3, rows 0 through NEF-1 would correspond to A, B, C, AB, AC, BC, and ABC, respectively.The columns of the output matrix are as follows:
Column Description 0 degrees of freedom 1 sum of squares 2 F-statistic 3 p-value
-
getANOVATable
public double[] getANOVATable()Returns the analysis of variance table. Note that thecomputemethod must be invoked first before invoking this method. Otherwise, the method throws aNullPointerExceptionexception.- Returns:
- a
doublearray containing the analysis of variance table. The analysis of variance statistics are given as follows:Element Analysis of Variance Statistics 0 degrees of freedom for the model 1 degrees of freedom for error 2 total (corrected) degrees of freedom 3 sum of squares for the model 4 sum of squares for error 5 total (corrected) sum of squares 6 model mean square 7 error mean square 8 overall F-statistic 9 p-value 10 \(R^2\) (in percent) 11 adjusted \(R^2\) (in percent) 12 estimate of the standard deviation 13 overall mean of y 14 coefficient of variation (in percent)
-
setErrorIncludeType
public void setErrorIncludeType(int type) Sets error included type.- Parameters:
type- anintscalar.ANOVAFactorial.PURE_ERROR, the default option, indicates factornSubscriptsis error. Its main effect and all its interaction effects are pooled into the error with the other (modelOrder + 1)-way and higher-way interactions.ANOVAFactorial.POOL_INTERACTIONSindicates factornSubscriptsis not error. Only (modelOrder + 1)-way and higher-way interactions are included in the error.
-
setModelOrder
public void setModelOrder(int modelOrder) Sets the number of factors to be included in the highest-way interaction in the model.- Parameters:
modelOrder- anintscalar containing the number of factors to be included in the highest-way interaction in the model.modelOrdermust be in the interval [1,nSubscripts - 1]. For example, amodelOrderof 1 indicates that a main effect model will be analyzed, and amodelOrderof 2 indicates that two-way interactions will be included in the model. Default:modelOrder = nSubscripts - 1
-