Ab initio study of the phononic origin of negative thermal expansion