Number of new predictors

15 Views Asked by At

Suppose I have a matrix $X$ which has columns $x_1, x_2, \dots x_n$. I'd like to create some additional columns for interactions. For instance $x_1^2, x_1x_2, \dots, x_1x_n, x_2^2, \dots, x_n^2$.

EDIT: There would be no need to generate the same interaction term twice. So if I've already generated $x_ix_j$ there is no need to generate $x_jx_i$.

I'd like to be able to count how many new columns I would generate through this process. How can I go about doing this?

1

There are 1 best solutions below

3
On

The number interaction with itself, i.e. of the form $x_i^2$ is $n$. And the number of ordered pairs $(x_i,x_j)$ such that $i\neq j$ is $n(n-1)$. Then the number of unordered pairs $(x_i,x_j)$ such that $i\neq j$ is $n(n-1)/2$. Hence required number of interactions$$=n+\frac{n(n-1)}{2}$$