def expected_freq(observed):
 observed = np.asarray(observed, dtype=np.float64)
 margsums = margins(observed)
 d = observed.ndim
 expected = (reduce(np.multiply, margsums) / (observed.sum() ** (d - 1)))
 return expected

def expected_freq ( observed ) : observed = np . asarray ( observed , dtype = np . float64 ) margsums = margins ( observed ) d = observed . ndim expected = ( reduce ( np . multiply , margsums ) / ( observed . sum ( ) ** ( d - 1 ) ) ) return expected
compute the expected frequencies from a contingency table .