function to calculate KWER-distribution