This is in principle a very old question that Newton was already concerned with. In fact, it is not density that is relevant in the end - the changes of the refractive index are connected with Beer's law - read the whole story under Article Understanding Refractive Index Changes in Homologous Series ...