Skip to content

Instantly share code, notes, and snippets.

@richardkundl
Last active August 11, 2018 20:26
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardkundl/2950196 to your computer and use it in GitHub Desktop.
Save richardkundl/2950196 to your computer and use it in GitHub Desktop.
Lower bound of Wilson score confidence interval for a Bernoulli parameter(fix: 0.9604)
using System;
namespace Rating
{
class Program
{
/// <summary >
/// Ratings
/// (Lower bound of Wilson score confidence interval for a Bernoulli parameter)
/// </summary>
/// <param name="positive">Positive ratings</param>
/// <param name="negative">Negative ratings</param>
/// <returns></returns>
public static double Rating(int positive, int negative)
{
return (((positive + 1.9208) / (positive + negative) - 1.96 * Math.Sqrt(((positive * negative) / (positive + negative)) + 0.9604) / (positive + negative)) / (1 + 3.8416 / (positive + negative)));
}
static void Main(string[] args)
{
// tests
Console.WriteLine(Rating(10, 10).ToString());
Console.WriteLine(Rating(438, 10).ToString());
Console.WriteLine(Rating(1, 0).ToString());
Console.WriteLine(Rating(0, 13).ToString());
Console.WriteLine(Rating(30, 760).ToString());
Console.ReadKey();
}
}
}
@julienbourdeau
Copy link

Thank you!
That would be cool to provde the results of the tests, just to make sure I ported the function correctly in PHP ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment