From June 04, 2020

Applying the chi-square test for the case of discrete random variables with an infinite number of values `(m = ∞)`. In this case the distribution can be geometric or poisson’s, an infinite number of intervals are used by grouping some of the values. The values are grouped on intervals as long as the probability’s total do not exceed the probabilities of some other value, in general large values of x are used.

The total of the probability will have a value near or less than the probabilities Pi of the other values `i < X`, in this procedure from the statistical calculation all values are accounted, starting with `X` as a singular value with a probability equal to: For example with `p = 0.8` we can get the geometric distribution, by making the chi-square test we can consider the distribution of the probability with the values `0, 1, 2 and > 2` with the probabilities `0.8, 0.16, 0.32 and 0.008` to apply the standard procedure of the test.

## Result  ### Implementation

``````int i = 0;
double sum = 0;

int n = int.Parse(textBox6.Text);
double param1 = double.Parse(textBox1.Text);
double param2 = double.Parse(textBox2.Text);

double p1 = param1;
double p2 = p1 * param2;
double p3 = p2 * param2;
double p4 = 1 - (p1 + p2 + p3);

sum = p1 + p2 + p3 + p4;

double[] e_probabilities = new double;
double[] probabilities = new double;
double[] experiments = new double;
double[] frequency = new double;

//Expected Value - µ
double xp1 = 1 * p1;
double xp2 = 2 * p2;
double xp3 = 3 * p3;
double xp4 = 4 * p4;

double miu = xp1 + xp2 + xp3 + xp4;

//Variance - µ
double x2p1 = (1*1) * p1;
double x2p2 = (2*2) * p2;
double x2p3 = (3*3) * p3;
double x2p4 = (4*4) * p4;

double variance = x2p1 + x2p2 + x2p3 + x2p4;

variance -= (miu * miu);

experiments = 0;
experiments = 0;
experiments = 0;
experiments = 0;

e_probabilities = xp1;
e_probabilities = xp2;
e_probabilities = xp3;
e_probabilities = xp4;

probabilities = p1;
probabilities = p2;
probabilities = p3;
probabilities = p4;

while (i < n)
{
// Any value greater than zero, x > 0 | nonnegative integers
// A countable set of infinite values
int r = rand.Next(1, Int32.MaxValue);

if (r == 1) experiments++;
else if (r == 2) experiments++;
else if (r == 3) experiments++;
else if (r >= 4) experiments++;
i++;
}

i = 0;
foreach (var item in experiments)
{
frequency[i++] = item / n;
}

double e_miu = 1 * frequency +
2 * frequency +
3 * frequency +
4 * frequency;

double e_variance = (1 * 1) * frequency +
(2 * 2) * frequency +
(3 * 3) * frequency +
(4 * 4) * frequency;

e_variance -= (e_miu * e_miu);

//Errors
double miuError = Math.Abs(e_miu - miu) / Math.Abs(miu);
double varianceError = Math.Abs(e_variance - variance) / Math.Abs(variance);

//Chi
double chi = 0;
double alfa = 0.05;

for (i = 0; i < 4; i++)
{
chi += Math.Pow((frequency[i] - probabilities[i]), 2) / probabilities[i];
}
textBoxAverage.Text = miu.ToString("0.000") + " (error = "+ Math.Round((miuError * 100)).ToString() + "%)";
textBoxVariance.Text = variance.ToString("0.000") + " (error = " + Math.Round((varianceError * 100)).ToString() + "%)";

labelChi.Text = "Chi-squared: \r\n" + chi.ToString("0.000") + " > " + alfa.ToString("0.000") + " ( " + ((chi > alfa) ? "YES" : "FALSE") + " )";
`````` 