encode_deviation function

Encode a given factor variable using deviation encoding