The twoway analysis of variance with a planned (a priori) factor follows the next statistical fundamentals (degrees of freedom are between parentheses),
SSTO = SSM + SSE; (N1 = k1 + Nk; k = a*b)
SSTO, total sum of squares corrected; SSM, model sum of squares;SSE,error sum of squares (within). [N=Total data;a=Factor 1 levels;b=Factor 2 levels].
SSM = SSA + SSB + SSAB; [k1 = a1 + b1 + (a1)*(b1)]
SSA, Factor A sum of squares (Model I or II); SSB, Factor B sum of squares (Model I); SSAB, interaction sum of squares.
SSB = SS1 + SS2 +...+ SSC; (b1 = 1 + 1 +...+ 1)
SS1,...,SSC, contrast sum of squares.
SSj = Sj^2 / SUM(cj^2/nj); j=1,2,...,C
Sj^2 = c1*M1 + c2*M2 +...+ cC*MC
cj, contrast vector; Mj, means vector; nj, sample size vector.
If there is no interaction, it is better to perform two separate oneway ANOVAs. Here, factor A and B with a Model I/II and I (panned), respectively. An interaction effect is a change in the simple main effect of one variable over levels of the second.
In a fixedmodel (I), the treatment levels are deliberately selected and will remain constant from one replication to another. Generalization of such a model can be made only to the levels tested. Meanwhile, in a randommodel (II), the treatment levels are randomly selected and if we replicated the study we would again choose the levels randomly and would most likely have a whole new set of levels. Results can be generalized to the population levels from which the levels of the independent variable were randomly selected.
Planned contrasts are particular comparisions that the researcher is interested in examining prior to data collection or in certain specific contrasts, but not in the omnibus F test that examines all possible contrasts (Lomax, 2007). Fewer planned comparisions are usually conducted (k  1), due to their specificity. Each comparision corresponds to an independent hypothesis. To be sure that this is satisfied, we must to have a family of orthogonal planned comparisons.
Orthogonal contrasts are special in the sense that each contrast provides totally unique, nonredundant information about the means under study. If the two contrasts are orthogonal, then the sum of the cross products will be equal to '0'. Otherwise, the contrasts are nonorthogonal.
AOV2APR treats NaN values as missing values, and removes them.
Syntax: function aov2apr(x,m,z)
Inputs:
x – data nx3 matrix (Col 1 = data;Col 2 = factor 1 code [Model I/II];Col 3 = factor 2 code [Model Iplanned])
m  contrasts matrix (planned)
z  factor 1 fixed=1;factor 1 random=2
Output:
 Summary statistics from the analysis
