def auto_correlation(sequence):
if isinstance(sequence, basestring):<EOL><INDENT>sequence = map(int, sequence)<EOL><DEDENT>seq = np.array(list(sequence), dtype=np.float)<EOL>dseq = np.column_stack((seq[<NUM_LIT:1>:], seq[:-<NUM_LIT:1>]))<EOL>slope, intercept, r, ttp, see = linregress(seq[<NUM_LIT:1>:], seq[:-<NUM_LIT:1>])<EOL>cc = np.corrcoef(dseq, rowvar=<NUM_LIT:0>)[<NUM_LIT:0>][<NUM_LIT:1>]<EOL>return {'<STR_LIT>': slope, '<STR_LIT>': intercept, '<STR_LIT>': r ** <NUM_LIT:2>,<EOL>'<STR_LIT:p>': ttp, '<STR_LIT>': see, '<STR_LIT>': cc}<EOL>
test for the autocorrelation of a sequence between t and t - 1
as the 'auto_correlation' it is less likely that the sequence is
generated randomly.
:param sequence: any iterable with at most 2 values that can be turned
                 into a float via np.float . e.g.
                 '1001001'
                 [1, 0, 1, 0, 1]
                 [1.2,.1,.5,1]
:rtype: returns a dict of the linear regression stats of sequence[1:] vs.
        sequence[:-1]

>>> result = auto_correlation('00000001111111111100000000')
>>> result['p'] < 0.05
True
>>> result['auto_correlation']
0.83766233766233755