suppose you have a set of 40 three letter words using only 10 letters (you're able to repeat letters in different words and in the same word), and you're attempting to calculate the association of particular characters, the probability of a D being next to an H, for example.
if you had only two letter words, you could run a chi-square test of independence with 10 rows/colums, but what if you have three letter words, or 10 letter words? How would one go about running this calculation?
Is it as simple as
((row total)(column total)(third dimensional column total)(fourth dimensional column total)...)/n ?
Almost. For the expected number in each cell you need to divide by $n^{d-1}$ when there are $d$ dimensions.
One way of remembering this is to consider the expected probability to be the product of the marginal probabilities $\frac{\text{row total}}{n}, \frac{\text{column total}}{n},$ etc., so leading to $n^d$ in the denominator. Then the expected number in a cell would be $n$ times this product
The degrees of freedom also change
If you have multiple dimensions and a small sample, some of the cells may get very small, so a standard chi-squared test may not be appropriate