Example #1
0
def test_plot():
    import matplotlib.pyplot as plt

    y, x, w = gen_data(250, 3, True, pandas=True)
    fmla = "y ~ 1 + x0 + x1 + x2"
    data = pd.concat([y, x], axis=1)
    mod = RollingWLS.from_formula(fmla, window=100, data=data, weights=w)
    res = mod.fit()
    fig = res.plot_recursive_coefficient()
    assert isinstance(fig, plt.Figure)
    res.plot_recursive_coefficient(variables=2, alpha=None, figsize=(30, 7))
    res.plot_recursive_coefficient(variables="x0", alpha=None, figsize=(30, 7))
    res.plot_recursive_coefficient(variables=[0, 2],
                                   alpha=None,
                                   figsize=(30, 7))
    res.plot_recursive_coefficient(variables=["x0"],
                                   alpha=None,
                                   figsize=(30, 7))
    res.plot_recursive_coefficient(variables=["x0", "x1", "x2"],
                                   alpha=None,
                                   figsize=(30, 7))
    with pytest.raises(ValueError, match="variable x4 is not an integer"):
        res.plot_recursive_coefficient(variables="x4")

    fig = plt.Figure()
    # Just silence the warning
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        out = res.plot_recursive_coefficient(fig=fig)
    assert out is fig
    res.plot_recursive_coefficient(alpha=None, figsize=(30, 7))
Example #2
0
def test_plot():
    import matplotlib.pyplot as plt

    y, x, w = gen_data(250, 3, True, pandas=True)
    fmla = 'y ~ 1 + x0 + x1 + x2'
    data = pd.concat([y, x], axis=1)
    mod = RollingWLS.from_formula(fmla, window=100, data=data, weights=w)
    res = mod.fit()
    fig = res.plot_recursive_coefficient()
    assert isinstance(fig, plt.Figure)
    res.plot_recursive_coefficient(variables=2, alpha=None, figsize=(30, 7))
    res.plot_recursive_coefficient(variables='x0', alpha=None, figsize=(30, 7))
    res.plot_recursive_coefficient(variables=[0, 2],
                                   alpha=None,
                                   figsize=(30, 7))
    res.plot_recursive_coefficient(variables=['x0'],
                                   alpha=None,
                                   figsize=(30, 7))
    res.plot_recursive_coefficient(variables=['x0', 'x1', 'x2'],
                                   alpha=None,
                                   figsize=(30, 7))
    with pytest.raises(ValueError, match='variable x4 is not an integer'):
        res.plot_recursive_coefficient(variables='x4')

    fig = plt.Figure()
    with pytest.warns(UserWarning, match="tight_layout"):
        out = res.plot_recursive_coefficient(fig=fig)
    assert out is fig
    res.plot_recursive_coefficient(alpha=None, figsize=(30, 7))
Example #3
0
def test_formula():
    y, x, w = gen_data(250, 3, True, pandas=True)
    fmla = "y ~ 1 + x0 + x1 + x2"
    data = pd.concat([y, x], axis=1)
    mod = RollingWLS.from_formula(fmla, window=100, data=data, weights=w)
    res = mod.fit()
    alt = RollingWLS(y, x, window=100)
    alt_res = alt.fit()
    assert_allclose(res.params, alt_res.params)
    ols_mod = RollingOLS.from_formula(fmla, window=100, data=data)
    ols_mod.fit()