We apply the HanleRT Tenerife Inversion Code to the spectropolarimetric observations obtained by the Chromospheric Layer Spectropolarimeter. This suborbital space experiment measured the variation with wavelength of the four Stokes parameters in the near-ultraviolet spectral region of the Mg ii h and k lines over a solar disk area containing part of an active region plage and the edge of a sunspot penumbra. We infer the stratification of the temperature, the electron density, the line-of-sight velocity, the microturbulent velocity, and the longitudinal component of the magnetic field from the observed intensity and circular polarization profiles. The inferred model atmosphere shows larger temperature and electron density in the plage and the superpenumbra regions than in the quiet regions. The shape of the plage region in terms of its brightness is similar to the pattern of the inferred longitudinal component of the magnetic field in the chromosphere, as well as to that of the overlying moss observed by the Atmospheric Imaging Assembly in the 171 Å band, which suggests a similar magnetic origin for the heating in both the plage and the moss region. Moreover, this heating is particularly significant in the regions with larger inferred magnetic flux. In contrast, in the superpenumbra, the regions with larger electron density and temperature are usually found in between these regions with larger magnetic flux, suggesting that the details of the heating mechanism in the chromosphere of the superpenumbra may be different from those in the plage, but with the magnetic field still playing a key role.