def create_model(realdata=True, force_implementation=None, filter_p=None):
        if realdata:
            ts = read_test_data(325278)
            start, end = datetime(1998, 1, 1), datetime(2007, 1, 1)
            breaktime = datetime(2002, 6, 19)
            ts = ts[start:end]
            ts.rename(columns={
                'CCI_41_COMBINED': 'candidate',
                'merra2': 'reference'
            },
                      inplace=True)
        else:
            ts, breaktime, [start, end] = create_artificial_test_data('asc2')

        if realdata:  # bias correction
            slope, inter = linreg_params(ts.dropna().candidate,
                                         ts.dropna().reference)
            ts.candidate = linreg_stored_params(ts.candidate, slope,
                                                inter)  # scale

        regress = LinearRegression(ts['candidate'].loc[start:end],
                                   ts['reference'].loc[start:end],
                                   filter_p=filter_p,
                                   fit_intercept=True,
                                   force_implementation=force_implementation)
        return regress
Exemple #2
0
    def setUpClass(cls):
        ts, breaktime, timeframe = create_artificial_test_data('mean')

        ts.rename(columns={
            'candidate': 'can',
            'reference': 'ref'
        },
                  inplace=True)
        cls.ts_full = ts  # this can be used to test if values to adjust are not same as for model
        start = timeframe[0]
        ts_frame = ts.loc[start:, :]

        lmp_kwargs = dict(regress_resample=None)

        lmp = RegressPairFit(
            ts_frame['can'],
            ts_frame['ref'],
            breaktime,
            candidate_freq='D',
            bias_corr_method='linreg',
            filter=None,  # cannot filter the test data, otherwise empty
            adjust_group=0,
            model_intercept=True,
            **lmp_kwargs)
        cls.lmp = lmp
Exemple #3
0
def test_var_break():
    '''Test var break detection'''

    df, breaktime, timeframe = create_artificial_test_data('var')

    test = TsRelBreakTest(candidate=df.candidate,
                          reference=df.reference,
                          breaktime=breaktime,
                          test_resample=None,
                          test_check_min_data=3,
                          test_check_spearR_sig=(-1, 1),
                          bias_corr_method=None,
                          alpha=0.01)

    test.run_tests()
    testresults, error_dict, checkstats = test.get_results()

    assert (testresults['var']['h'] == 1)
    assert (error_dict['error_code_test'] == 0)
    assert (checkstats['n0'] == 182)
    assert (checkstats['n1'] == 184)
    nptest.assert_almost_equal(checkstats['frame_spearmanR'], 0.8944298, 4)
    nptest.assert_almost_equal(checkstats['frame_corrPval'], 0, 4)

    assert (test.check_test_results()[1] == 'var')
    assert (test.check_test_results()[0] == True)
Exemple #4
0
 def setUp(self):
     breaktype = self.shortDescription()
     self.df, breaktime, timeframe = create_artificial_test_data(
         type=breaktype)
     self.base = TsRelBreakBase(candidate=self.df.candidate,
                                reference=self.df.reference,
                                breaktime=breaktime,
                                bias_corr_method=None)
Exemple #5
0
    def setUpClass(cls):
        ts, breaktime, timeframe = create_artificial_test_data('norm_mean')
        ts.rename(columns={
            'candidate': 'can',
            'reference': 'ref'
        },
                  inplace=True)
        cls.ts_full = ts  # this can be used to test if values to adjust are not same as for model

        qcm_kwargs = dict(categories=1, first_last='equal', fit='mean')

        qcm = QuantileCatMatch(ts['can'],
                               ts['ref'],
                               breaktime,
                               bias_corr_method='linreg',
                               adjust_group=0,
                               **qcm_kwargs)
        cls.qcm = qcm
    def create_model(realdata=True, poly_order=2, filter_p=None):
        if realdata:
            ts = read_test_data(325278)
            start, end = datetime(1998, 1, 1), datetime(2007, 1, 1)
            ts.rename(columns={
                'CCI_41_COMBINED': 'can',
                'merra2': 'ref'
            },
                      inplace=True)
            ts_drop = ts.dropna()
            slope, inter = linreg_params(ts_drop['can'], ts_drop['ref'])
            ts['can'] = linreg_stored_params(ts['can'], slope, inter)  # scale
        else:
            ts, breaktime, [start, end] = create_artificial_test_data('asc2')

        regress = HigherOrderRegression(ts['can'].loc[start:end],
                                        ts['ref'].loc[start:end],
                                        poly_order=poly_order,
                                        filter_p=filter_p)
        return regress
Exemple #7
0
    def setUpClass(cls):
        ts, breaktime, timeframe = create_artificial_test_data('norm_mean')

        ts.rename(columns={'candidate': 'can',
                           'reference': 'ref'}, inplace=True)
        cls.ts_full = ts  # this can be used to test if values to adjust are not same as for model
        start = timeframe[0]
        ts_frame = ts.loc[start:, :]

        hom_kwargs = dict(regress_resample=None)

        hom = HigherOrderMoments(ts_frame['can'],
                                 ts_frame['ref'],
                                 breaktime,
                                 bias_corr_method=None,
                                 filter=None,
                                 adjust_group=0,
                                 poly_orders=2,
                                 select_by=None,
                                 cdf_types=None,
                                 **hom_kwargs)
        cls.hom = hom
Exemple #8
0
def test_mean_break():
    ''' Test mean break detection'''

    df_mean, breaktime, timeframe = create_artificial_test_data('mean')

    test = TsRelBreakTest(candidate=df_mean.candidate,
                          reference=df_mean.reference,
                          breaktime=breaktime,
                          test_resample=('M', 0.3),
                          test_check_min_data=3,
                          test_check_spearR_sig=(-1, 1),
                          bias_corr_method=None,
                          alpha=0.01)

    test.run_tests()
    testresults, error_dict, checkstats = test.get_results()

    assert (testresults['mean']['h'] == 1)
    assert (error_dict['error_code_test'] == 0)
    assert (checkstats['n0'] == 6)
    assert (checkstats['n1'] == 6)

    assert (test.check_test_results()[1] == 'mean')
    assert (test.check_test_results()[0] == True)
Exemple #9
0
 def setUp(self):
     self.df, breaktime, timeframe = create_artificial_test_data(
         type='const')
     self.test = HorizontalVal(candidate=self.df.candidate,
                               reference=self.df.reference,
                               breaktime=breaktime)