detectSWR function (week 5)