A theory for species co-occurrence in interaction networks