I think it is usually out of fear. Whenver we use to pluck out the mice to feed, if we didnt get them on the first swipe, they would start tail shaking, and would tail shake more when confronted with a snake.

If not fear, perhaps a mixture of fear and defensive aggression.