Statistical mechanics of viscoelasticity