Analysing and forecasting transitions in complex systems