order = 3
    exog = x**np.arange(order + 1)
    beta = np.array([1, 1, 0.1, 0.0])[:order+1] # 1. / np.arange(1, order + 2)
    y_true = np.dot(exog, beta)
    y = y_true + sig_e * np.random.normal(size=nobs)
    endog = y

    print('DGP')
    print('nobs=%d, beta=%r, sig_e=%3.1f' % (nobs, beta, sig_e))

    mod_ols = OLS(endog, exog[:,:2])
    res_ols = mod_ols.fit()
    #'cv_ls'[1000, 0.5][0.01, 0.45]
    tst = smke.TestFForm(endog, exog[:,:2], bw=[0.01, 0.45], var_type='cc',
                         fform=lambda x,p: mod_ols.predict(p,x),
                         estimator=lambda y,x: OLS(y,x).fit().params,
                         nboot=1000)

    print('bw', tst.bw)
    print('tst.test_stat', tst.test_stat)
    print(tst.sig)
    print('tst.boots_results mean, min, max', (tst.boots_results.mean(),
                                               tst.boots_results.min(),
                                               tst.boots_results.max()))
    print('lower tail bootstrap p-value', (tst.boots_results < tst.test_stat).mean())
    print('upper tail bootstrap p-value', (tst.boots_results >= tst.test_stat).mean())
    from scipy import stats
    print('aymp.normal p-value (2-sided)', stats.norm.sf(np.abs(tst.test_stat))*2)
    print('aymp.normal p-value (upper)', stats.norm.sf(tst.test_stat))

    do_plot=True
Beispiel #2
0
        order = 2
        exog = x**np.arange(1, order + 1)
        beta = np.array([2,
                         -0.2])[:order + 1 - 1]  # 1. / np.arange(1, order + 2)
        y_true = np.dot(exog, beta)
        y = y_true + sig_e * np.random.normal(size=nobs)
        endog = y

        mod_ols = OLS(endog, exog[:, :1])
        #res_ols = mod_ols.fit()
        #'cv_ls'[1000, 0.5]
        bw_lw = [1. / np.sqrt(12.) * nobs**(-0.2)] * 2  #(-1. / 5.)
        tst = smke.TestFForm(endog,
                             exog[:, :1],
                             bw=bw_lw,
                             var_type='c',
                             fform=lambda x, p: mod_ols.predict(p, x),
                             estimator=lambda y, x: OLS(y, x).fit().params,
                             nboot=399)
        b_res.append([
            tst.test_stat,
            stats.norm.sf(tst.test_stat),
            (tst.boots_results > tst.test_stat).mean()
        ])
    t1 = time.time()
    b_res = np.asarray(b_res)

    print('time', (t1 - t0) / 60.)
    print(b_res.mean(0))
    print(b_res.std(0))
    print('reject at [0.2, 0.1, 0.05] (row 1: normal, row 2: bootstrap)')