Detecting regime shifts in ecosystems