The effects of density dependence and habitat preference on species coexistence and relative abundance