The HDIR function computes the horizontal direct product of two numeric matrices. This operation is useful in constructing design matrices of interaction effects.
Specifically, the HDIR function performs a direct product on all rows of matrix1 and matrix2 and creates a new matrix by stacking these row vectors into a matrix. The matrix1 and matrix2 arguments must have the same number of rows, which is also the same number of rows in the result matrix. The number of columns in the result matrix is equal to the product of the number of columns in matrix1 and matrix2.
For example, the following statements produce the matrix c
, shown in Figure 23.138:
a = {1 2, 2 4, 3 6}; b = {0 2, 1 1, 0 -1}; c = hdir(a, b); print c;
The HDIR function is useful for constructing crossed and nested effects from main-effect design matrices in ANOVA models.