Statistics for HerMES: The contribution to the cosmic infrared background from galaxies selected by mass and redshift