I don't know the precise algorithm, but it's based on the number of cachers (particularly from that area, since automatic running of the checkers happens more for local cachers) who qualify compared to those who don't qualify. The less cachers who qualify, the higher the difficulty rating.