Exemplo n.º 1
0
def test_panel_ols_formulas_math_op(data):
    if not isinstance(data.y, DataFrame):
        return
    joined = data.x
    joined["y"] = data.y
    formula = "y ~ x1 + np.exp(x2)"
    mod = PanelOLS.from_formula(formula, joined)
    mod.fit()
Exemplo n.º 2
0
def test_repeated_measures_weight():
    # Issue reported by email
    rs = np.random.RandomState(0)
    w = rs.chisquare(5, 300) / 5
    idx1 = ["a"] * 100 + ["b"] * 100 + ["c"] * 100
    idx2 = np.arange(300) % 25
    mi = pd.MultiIndex.from_arrays([idx1, idx2])
    df = pd.DataFrame(rs.standard_normal((300, 2)),
                      index=mi,
                      columns=["y", "x"])
    w = pd.Series(w, index=mi, name="weight")
    df["weight"] = w
    mod = PanelOLS.from_formula("y ~ x + EntityEffects + TimeEffects",
                                df,
                                weights=df["weight"])
    res = mod.fit()
    mod = PanelOLS.from_formula("y ~ x + EntityEffects + TimeEffects", df)
    res_un = mod.fit()
    assert res.params[0] != res_un.params[0]
Exemplo n.º 3
0
def test_panel_ols_formula(data):
    if not isinstance(data.y, DataFrame):
        return
    joined = data.x
    joined["y"] = data.y
    formula = "y ~ x1 + x2"
    mod = PanelOLS.from_formula(formula, joined)
    assert mod.formula == formula

    formula = "y ~ x1 + x2 + EntityEffects"
    mod = PanelOLS.from_formula(formula, joined)
    assert mod.formula == formula
    assert mod.entity_effects is True
    assert mod.time_effects is False

    formula = "y ~ x1 + x2 + TimeEffects"
    mod = PanelOLS.from_formula(formula, joined)
    assert mod.formula == formula
    assert mod.time_effects is True
    assert mod.entity_effects is False

    formula = "y ~ x1 + EntityEffects + TimeEffects + x2 "
    mod = PanelOLS.from_formula(formula, joined)
    assert mod.formula == formula
    assert mod.entity_effects is True
    assert mod.time_effects is True
    mod2 = panel_ols(formula, joined)
    res = mod.fit()
    res2 = mod2.fit()
    np.testing.assert_allclose(res.params, res2.params)

    formula = "y ~ x1 + EntityEffects + FixedEffects + x2 "
    with pytest.raises(ValueError):
        PanelOLS.from_formula(formula, joined)