I am trying to calculate chi-squared value for my fitted data using:
$$ \chi^2 = \sum_i^n{\frac{(y-f(x))^2}{f(x)}} $$
where $f(x)$ are theoretical values from fitted function and $y$ are observations.
However, if expected values are too small, I receive (logically) very large numbers. For example if I calculate chi-squared for values that are listed below, I'll receive (in C++): -inf as a result. But statistical software which I use as a reference outputs chi-squared as 0.39.
Please can you suggest what I am doing wrong?
Example data follows:
y: | f(x):
0 | 0.000233516
0 | 0.000748074
0 | 0.00226688
1 | 0.00649784
1 | 0.0176183
1 | 0.0451873
1 | 0.109628
0 | 0.251586
0 | 0.546141
0 | 1.12145
0 | 2.17825
1 | 4.00215
3 | 6.9556
6 | 11.4349
17 | 17.7821
22 | 26.1572
42 | 36.3961
41 | 47.9043
61 | 59.6417
79 | 70.2394
83 | 78.2468
82 | 82.4535
74 | 82.1877
81 | 77.4925
58 | 69.1145
73 | 58.3087
39 | 46.5322
34 | 35.1261
14 | 25.082
24 | 16.9414
19 | 10.8241
16 | 6.5417
11 | 3.73977
4 | 2.02234
4 | 1.03448
4 | 0.500544
4 | 0.229097
2 | 0.0991863
2 | 0.04062
2 | 0.0157356
1 | 0.00576612
2 | 0.00199866
1 | 0.000655315
0 | 0.000203244
0 | 5.96265e-05
0 | 1.65469e-05
0 | 4.34361e-06
0 | 1.07855e-06
0 | 2.53329e-07
1 | 5.62841e-08