Anharmonic contributions to vibrational thermodynamic properties of solids: Part I. General formulation and application to the linear chain