Code for 'applying functional mediation' paper