def PrintSerialCorrelations(dailies):
    """Prints a table of correlations with different lags.

    dailies: map from category name to DataFrame of daily prices
    """
    filled_dailies = {}
    for name, daily in dailies.items():
        filled_dailies[name] = FillMissing(daily, span=30)

    # print serial correlations for raw price data
    for name, filled in filled_dailies.items():
        corr = thinkstats2.SerialCorr(filled.ppg, lag=1)
        print(name, corr)

    rows = []
    for lag in [1, 7, 30, 365]:
        row = [str(lag)]
        for name, filled in filled_dailies.items():
            corr = thinkstats2.SerialCorr(filled.resid, lag)
            row.append('%.2g' % corr)
        rows.append(row)

    print(r'\begin{tabular}{|c|c|c|c|}')
    print(r'\hline')
    print(r'lag & high & medium & low \\ \hline')
    for row in rows:
        print(' & '.join(row) + r' \\')
    print(r'\hline')
    print(r'\end{tabular}')

    filled = filled_dailies['high']
    acf = smtsa.acf(filled.resid, nlags=365, unbiased=True)
    print('%0.3f, %0.3f, %0.3f, %0.3f, %0.3f' %
          (acf[0], acf[1], acf[7], acf[30], acf[365]))
示例#2
0
    def TestStatistic(self, data):
        """Computes the test statistic.

        data: tuple of xs and ys
        """
        series, lag = data
        test_stat = abs(thinkstats2.SerialCorr(series, lag))
        return test_stat
示例#3
0
    def TestStatistic(self, data):
        """ computes the test statistic

        @param: data (tuple) - x and y values 

        returns
        @param: test_stat
        """
        series, lag = data
        test_stat = abs(thinkstats2.SerialCorr(series, lag))

        return test_stat
示例#4
0
def main():
    all_recs = cyb_records_2.Errors()
    all_recs.ReadRecords()
    print 'Number of total stats', len(all_recs.records)

    clean_recs = clean_events.CleanEvents(all_recs.records)
    print 'Number of clean events', len(clean_recs)

    errors = CorrErrDist(clean_recs)
    print 'Number of dict entries', len(errors)

    for key in errors.keys():
        print "Error id =", key, "Correlation =", thinkstats2.SerialCorr(
            errors.get(key)), "List length =", len(errors.get(key))