Last active
August 11, 2018 20:26
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!
That would be cool to provde the results of the tests, just to make sure I ported the function correctly in PHP ^^