wrote seperate function to calculate dispersion for reference datasets.