calculate average and deviation