Refractive index is all about the density of atmospheric particles in it. Because of earth's gravity many of different density contained particles are attracted towards it which forms layer by combining similar density particles. so, the area of atmosphere containing low density particles will act as a rare while the higher density particles will act as a denser medium. Therefore, there are different medium in the atmosphere of the earth. This is also a cause of Atmospheric refraction.
I think it will help you.
if you want more information about it you can ask