Counting subsets of lattice points Let $n\ge 2$, and consider the set of $\binom{n}{2}$ lattice points in the interior of the triangle with vertices $(0,0)$, $(0,n+1)$ and $(n+1,n+1)$.  For $r\le \binom{n}{2}$, let $f(n,r)$ be the number of ways we can form a subset of cardinality $r$ such that the set of $x$-coordinates of the lattice points in the subset is disjoint from the set of $y$-coordinates.
For example, if $n=r=5$, one such subset is $\{(1,2),(1,4),(1,5),(3,4),(3,5)\}$.
What is a closed form for $f(n,r)$?
Some preliminary results I believe I can prove:
$$f(n,1)=\binom{n}{2}\\f(n,2)=\begin{bmatrix}n\\n-2\end{bmatrix}\\f\left(n,\left\lfloor\frac{n^2}{4}\right\rfloor\right)=\begin{cases}1&\text{if $n$ is even}\\2&\text{if $n$ is odd}\end{cases}\\f(n,r)=0\quad\text{for }r>\left\lfloor\frac{n^2}{4}\right\rfloor$$
where square brackets denote Stirling numbers of the first kind.  I'm less sure about the following results: $f(4,3)=7,\;f(5,3)=55,\;f(6,3)=240$.
This question is motivated by abelian matrix groups with generators of the form $A_{ij}=I_n+E_{ij}$, $j>i$, where $E_{ij}$ is the $n\times n$ matrix with a $1$ in the $ij$th entry and $0$'s elsewhere.  Such generators will pairwise commute if and only if their indices form a subset of lattice points as described in the above problem.
 A: This is a try at determining $p(n,3)$. We can arrange the sets in order of nondecreasing first coordinates, and break the count into four cases. 
If all first coordinates are equal then we have sets $(a,x),(a,y),(a,z)$ and suborder so that $x<y<z$, so that $a<x<y<z$ giving the count as the number of four element subsets of $\{1,...,n\}$, so $\binom{n}{4}$ for this type
If we have two distinct first coordinates among the three, it may be that the smaller is "doubled up", or the larger. In the case of first coordinates $a,a,b$ with $a<b$ the count of triples $(a,x),(a,y),(b,z)$ is from picking any $z$ above $b$ so $n-b$ ways for that, and the numbers $x,y$ must be distinct and chosen above $a$ but not allowing $b$ as a choice, so that there are $\binom{n-a-1}{2}$ ways to do that. So for the "aab" case we will sum
$$(n-b)\binom{n-a-1}{2}.$$
A similar analysis of the case of $(a,x),(b,y),(b,z)$  shows we should sum
$$\binom{n-b}{2}(n-a-1).$$
Both of these sums are over the same range $1 \le a < b \le n-1,$ and together contribuite the following to the count:
$$\frac{n(n-1)(n-2)(n-3)(2n-3)}{24}.$$
Finally we have the case in which all three first coordinates are distinct. Say they are $a,b,c$ with $a<b<c$, then the triples $(a,x),(b,y),(c,z)$ may be chosen in $(n-c)(n-b-1)(n-a-2)$ ways, the subtractions of $1$ or $2$ taken to account for the second coordinates not being among $a,b,c$. When the count for this case is taken, the result is
$$\frac{n(n-1)(n-2)^2(n-3)^2}{48}.$$
Totalling up all the cases gives the formula for $p(n,3)$ as
$$p(n,3)=\frac{n(n-1)(n-2)(n-3)(n^2-n+2)}{48}.$$
This gives, for the first few values beyond 3, the same results $7,55,240$ noted by Jared in the post.
