Usually you have a contingency table from which you derive a $\chi^2$ Value. I want to reaarange this. I want to have the sums and a p-Value (or $\chi^2$ Value) given and derive from that randomly generated values valid for that contingecy table and that p-Value. Also I called this "backward" chi-square. Maybe this already exists and I just don't know the name of it? If so please let me know the real name of this concept. So to sum it up:
Predefined: bold numbers in contingency table, p-Value
Solve for: italic letters in contingency table
| A | B | $\sum$ | |
|---|---|---|---|
| X | a | b | 50 |
| Y | c | d | 50 |
| $\sum$ | 50 | 50 | 100 |
Once $a,$ for $a = 0, 1, \dots, 50$ is chosen the rest of your $2\times 2$ table is uniquely defined. (That's roughly what it means to have degrees of freedom $1.)$
So, correspondingly, there are $51$ possible values of the chi-squared statistic $H.$ Of these only $26$ are unique. [So, once you know a legal value of $H,$ you know which of two tables must have been used.] in R, we have: