calculate weighted median