samedi 20 juillet 2019

List index out of range - chi square test

I created LCG generator and I'm trying to do a chi square test for unimormity.

From generator I choose 100 random numbers:

np.seterr(over='ignore')

a = np.uint32(1664525)
c = np.uint32(1013904223)
seed = np.uint32(1)

rng = LCG(seed, a, c)
q = [rng.next() for _ in range(0, 100)]
print(q)
data_set = q 

Next I was trying to do chi square this way: def chi_square_uniformity_test():

chi_sq_value = 0.0
num_samples = 10000
degrees_of_freedom = num_samples - 1
data_set
observed_val = 1 

expected_val = num_samples/10

for observed_val in data_set:

    chi_sq_value += ( pow((expected_val - data_set[observed_val]), 2)/expected_val )

return chi_sq_value

it is giving following error -

IndexError                                Traceback (most recent call last)
<ipython-input-43-675902c0a85e> in <module>
----> 1 chi_square_uniformity_test()

<ipython-input-42-3960c5593af3> in chi_square_uniformity_test()
     30     for observed_val in data_set:
     31         #print "Observed value is: " + observed_val
---> 32         chi_sq_value += ( pow((expected_val - data_set[observed_val]), 2)/expected_val )
     33 
     34     # Coming out of this loop, we'll have a chi-squared test statistic

IndexError: list index out of range




Aucun commentaire:

Enregistrer un commentaire