(Dec-03-2017, 04:11 PM)j.crater Wrote: "len() of unsized object" error generally means that the object, of which length you want to know, does not support this method - in your case it is np.cov("some_list"). You will need to convert it or use a different method of obtaining list length.
If you are using numpy array, try the "size" method, as suggested here:
https://stackoverflow.com/questions/4014...zed-object
That's helpful, thanks.
Actually, I just found some code online that is supposed to do the "Box's M" statistical test on co-variant matrices. I'm new to Python so maybe I'm missing something, but this code doesn't run with a simple example of two arrays:
import numpy as np
# def box_m(X0, X1):
X0 = np.array([1,2,3])
X1 = np.array([4,5,6])
global Xp
m = 2
k = (np.cov(X0).size) # returns 1, not sure if that's correct
n_1 = len(X0[0])
# ERROR >>> TypeError: object of type 'numpy.int64' has no len()
n_2 = len(X0[0])
# ERROR >>> TypeError: object of type 'numpy.int64' has no len()
n = len(X0[0]) + len(X1[0])
Xp = (((n_1 - 1) * np.cov(X0)) + ((n_2 - 1) * np.cov(X1))) / (n - m)
M = ((n - m) * np.log(np.linalg.det(Xp))) \
- (n_1 - 1) * (np.log(np.linalg.det(np.cov(X0)))) - (n_2 - 1) * (np.log(np.linalg.det(np.cov(X1))))
c = ((2 * (k ** 2) + (3 * k) - 1) / ((6 * (k + 1) * (m - 1)))) \
* ((1 / (n_1 - 1)) + (1 / (n_2 - 1)) - (1 / (n - m)))
df = (k * (k + 1) * (m - 1)) / 2
c2 = (((k - 1) * (k + 2)) / (6 * (m - 1))) \
* ((1 / ((n_1 - 1) ** 2)) + (1 / ((n_2 - 1) ** 2)) - (1 / ((n - m) ** 2)))
df2 = (df + 2) / (np.abs(c2 - c ** 2))
if (c2 > c ** 2):
a_plus = df / (1 - c - (df / df2))
F = M / a_plus
else:
a_minus = df2 / (1 - c + (2 / df2))
F = (df2 * M) / (df * (a_minus - M))
print('M = {}'.format(M))
print('c = {}'.format©)
print('c2 = {}'.format(c2))
print('-------------------')
print('df = {}'.format(df))
print('df2 = {}'.format(df2))
print('-------------------')
print('F = {}'.format(F))