4

I would like to create an algorithm in C# that implements the chi-square distribution. I

I have found a bunch of implementations on the internet but all of them use a lot of framework and I would like somthing simpler for a project at school.

How can this be done?

p.campbell
  • 98,673
  • 67
  • 256
  • 322
marius212
  • 43
  • 1
  • 5
  • 1
    what exactly do you want? Distribution function? Density? Sampling? – David Heffernan Feb 03 '11 at 07:39
  • and why does it have to be C#? You should be using R if you are doing stats. – David Heffernan Feb 03 '11 at 07:40
  • I'm not exactly sure what you are after but have a look here to see if it matches your requirements: http://www.codeproject.com/KB/cs/SpecialFunction.aspx – Bazzz Feb 03 '11 at 08:36
  • i want to simulate the chi-square distribution – marius212 Feb 04 '11 at 06:40
  • 2
    Actually, you should be using whatever language is best suited to the problem, including considering your own comfort level. Don't listen to anyone who tells you what language you "should" be using. That person likely only knows one language. Take a look here http://www.codeproject.com/Articles/432194/How-to-Calculate-the-Chi-Squared-P-Value. It can trivially be ported to C#. – Jeff Dec 04 '12 at 19:22

1 Answers1

3

A couple of years ago I ported the Perl module Statistics::Distributions to JavaScript. Among other distributions, it implements chi-square. It is a very lightweight and simple. You can find that implementation at http://statistics-distributions-js.googlecode.com/files/statistics-distributions-001.js.

It shouldn't be too hard to port that to C#. Or you can try something like http://jint.codeplex.com/ and see if you can just run the JavaScript directly on .NET.

btilly
  • 43,296
  • 3
  • 59
  • 88