Thursday, June 11, 2015

Order by rating

Incorrect:

SELECT name, positive, negative, positive/total x FROM productz ORDER BY x DESC;

By the way, I'm not sure that the Wilson correction gives any better results than a one standard deviation lower bound for the positive score:

SELECT name, positive, negative, positive/total - sqrt(positive*negative/total)/total x FROM productz ORDER BY x DESC;

Score = Lower bound of Wilson score confidence interval for a Bernoulli parameter:

SELECT name, positive, negative, ((positive + 1.9208) / (positive + negative) - 

                   1.96 SQRT((positive negative) / (positive + negative) + 0.9604) / 

                          (positive + negative)) / (1 + 3.8416 / (positive + negative)) 

       AS ci_lower_bound

FROM productz

WHERE positive + negative > 0 

ORDER BY ci_lower_bound DESC;

Single 1 0 1

Good new 5 0 1

Excellent 23400 23 0.9988134107340426

Quite good 520 200 0.7055298549839887

Exc-ish 5 1 0.6811881781678829

Some shitty 1000 2000 0.3247267033417656

Quite bad 28 82 0.21301210856756564

Bad-ish 1 2 0.06116780616017409

Single bad 0 1 0

Single 1 0 1.0000

Good new 5 0 1.0000

Excellent 23400 23 0.9990

Exc-ish 5 1 0.8333

Quite good 520 200 0.7222

Some shitty 1000 2000 0.3333

Bad-ish 1 2 0.3333

Quite bad 28 82 0.2545

Single bad 0 1 0.0000

Excellent 23400 23 0.998

Quite good 520 200 0.688

Good new 5 0 0.565

Exc-ish 5 1 0.436

Some shitty 1000 2000 0.316

Single 1 0 0.206

Quite bad 28 82 0.182

Bad-ish 1 2 0.061

Single bad 0 1 4.586

rating = (((positive + 1.9208) / (positive + negative) - 1.96 Math.Sqrt(((positive negative) / (positive + negative)) + 0.9604) / (positive + negative)) / (1 + 3.8416 / (positive + negative)));