Skip to content

Instantly share code, notes, and snippets.

@technetium
Last active August 3, 2016 16:15
Show Gist options
  • Save technetium/de8e58df900c5b11c372346c3d911893 to your computer and use it in GitHub Desktop.
Save technetium/de8e58df900c5b11c372346c3d911893 to your computer and use it in GitHub Desktop.
A function to calculate Lower bound of Wilson score confidence interval for a Bernoulli parameter @see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html For this formula the interval is set at 95%
CREATE FUNCTION wilson(stars INT, total INT)
RETURNS REAL DETERMINISTIC
RETURN IF (
total,
(
(stars + 1.9208) / total -
1.96 * SQRT((stars * (total-stars)) / total + 0.9604) / total
) / (1 + 3.8416 / total),
0
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment