コード例 #1
0
def test_can_add_hoc_lv_paths_correctly():
    structure = c.Structure()
    structure.add_path(["MANDRILL", "BONOBO"], ["APE"])
    structure.add_path(["APE"], ["GOAT"])
    initial_path = structure.path()
    config = c.Config(initial_path)
    config.add_higher_order("APE", Mode.A, ["CHEDDAR", "GOUDA"])
    estimator = Estimator(config)
    structure = c.Structure(initial_path)
    structure.add_path(["MANDRILL", "BONOBO"], ["CHEDDAR"])
    structure.add_path(["MANDRILL", "BONOBO"], ["GOUDA"])
    structure.add_path(["GOUDA", "CHEDDAR"], ["GOAT"])
    expected = structure.path().drop("APE").drop("APE", axis=1)
    actual = estimator.hoc_path_first_stage(config)
    pt.assert_frame_equal(expected, actual)
コード例 #2
0
def test_paths():
    mobi = pd.read_csv("file:tests/data/mobi.csv", index_col=0)

    structure = c.Structure()
    structure.add_path(["Expectation", "Quality"], ["Loyalty"])
    structure.add_path(["Image"], ["Expectation"])
    structure.add_path(["Complaints"], ["Loyalty"])

    config = c.Config(structure.path(), default_scale=Scale.NUM)
    config.add_lv_with_columns_named("Expectation", Mode.A, mobi, "CUEX")
    config.add_lv_with_columns_named("Quality", Mode.B, mobi, "PERQ")
    config.add_lv_with_columns_named("Loyalty", Mode.A, mobi, "CUSL")
    config.add_lv_with_columns_named("Image", Mode.A, mobi, "IMAG")
    config.add_lv_with_columns_named("Complaints", Mode.A, mobi, "CUSCO")
    mobi_pls = Plspm(mobi, config, Scheme.PATH, 100, 0.00000001)
    expected_outer_model = pd.read_csv(
        "file:tests/data/seminr-mobi-basic-outer-model.csv", index_col=0)
    actual_outer_model = mobi_pls.outer_model().drop(
        ["communality", "redundancy"], axis=1)
    npt.assert_allclose(expected_outer_model.sort_index(),
                        actual_outer_model.sort_index(),
                        rtol=1e-5)

    expected_paths = pd.read_csv("file:tests/data/seminr-mobi-basic-paths.csv",
                                 index_col=0)
    actual_paths = mobi_pls.path_coefficients().transpose()
    npt.assert_allclose(expected_paths.sort_index().sort_index(axis=1),
                        actual_paths.sort_index().sort_index(axis=1),
                        rtol=1e-6)
コード例 #3
0
def test_cannot_add_mvs_twice():
    structure = c.Structure()
    structure.add_path(source=["BONOBO"], target=["APE"])
    config = c.Config(structure.path())
    config.add_lv("BONOBO", Mode.A, c.MV("a"), c.MV("b"))
    with pytest.raises(ValueError):
        config.add_lv("APE", Mode.A, c.MV("a"), c.MV("b"))
コード例 #4
0
def satisfaction_path_matrix():
    structure = c.Structure()
    structure.add_path(["IMAG"], ["EXPE", "SAT", "LOY"])
    structure.add_path(["EXPE"], ["QUAL", "VAL", "SAT"])
    structure.add_path(["QUAL"], ["VAL", "SAT"])
    structure.add_path(["VAL"], ["SAT"])
    structure.add_path(["SAT"], ["LOY"])
    return structure.path()
コード例 #5
0
def test_create_path_from_structure():
    lvs = ["MANDRILL", "BONOBO", "APE", "GOAT", "CATFISH"]
    expected = pd.DataFrame([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 1, 0, 0, 0],
                             [0, 0, 1, 0, 0], [0, 0, 1, 0, 0]],
                            index=lvs,
                            columns=lvs)
    structure = c.Structure()
    structure.add_path(source=["BONOBO", "MANDRILL"], target=["APE"])
    structure.add_path(source=["APE"], target=["CATFISH", "GOAT"])
    pt.assert_frame_equal(expected, structure.path())
コード例 #6
0
 def hoc_path_first_stage(self, config: c.Config) -> pd.DataFrame:
     # For first pass, for HOCs we'll create paths from each and for each exogenous LV to the HOC's constituent LVs,
     # and from each consituent LV to the endogenous LVs.
     path = config.path()
     for hoc, lvs in config.hoc().items():
         structure = c.Structure(path)
         exogenous = path.loc[hoc]
         endogenous = path.loc[:, hoc]
         # structure.add_path(lvs, [hoc])
         for lv in list(exogenous[exogenous == 1].index):
             structure.add_path([lv], lvs)
         for lv in list(endogenous[endogenous == 1].index):
             structure.add_path(lvs, [lv])
         path = structure.path().drop(hoc).drop(hoc, axis=1)
     return path
コード例 #7
0
def test_hoc_two_stage():
    mobi = pd.read_csv("file:tests/data/mobi.csv", index_col=0)

    structure = c.Structure()
    structure.add_path(["Expectation", "Quality"], ["Satisfaction"])
    structure.add_path(["Satisfaction"], ["Complaints", "Loyalty"])

    config = c.Config(structure.path(), default_scale=Scale.NUM)
    config.add_higher_order("Satisfaction", Mode.A, ["Image", "Value"])
    config.add_lv_with_columns_named("Expectation", Mode.A, mobi, "CUEX")
    config.add_lv_with_columns_named("Quality", Mode.B, mobi, "PERQ")
    config.add_lv_with_columns_named("Loyalty", Mode.A, mobi, "CUSL")
    config.add_lv_with_columns_named("Image", Mode.A, mobi, "IMAG")
    config.add_lv_with_columns_named("Complaints", Mode.A, mobi, "CUSCO")
    config.add_lv_with_columns_named("Value", Mode.A, mobi, "PERV")
    mobi_pls = Plspm(mobi, config, Scheme.PATH, 100, 0.00000001)
    expected_outer_model = pd.read_csv(
        "file:tests/data/seminr-mobi-hoc-ts-outer-model.csv", index_col=0)
    actual_outer_model = mobi_pls.outer_model().drop(
        ["communality", "redundancy"], axis=1)
    indices = list(
        set(expected_outer_model.index.values.tolist()).intersection(
            set(actual_outer_model.index.values.tolist())))
    expected_outer_model = expected_outer_model.loc[indices].sort_index(
    ).sort_index(axis=1)
    actual_outer_model = actual_outer_model.loc[indices].sort_index(
    ).sort_index(axis=1)
    npt.assert_allclose(expected_outer_model, actual_outer_model, rtol=1e-4)

    expected_paths = pd.read_csv(
        "file:tests/data/seminr-mobi-hoc-ts-paths.csv",
        index_col=0).transpose()
    actual_paths = mobi_pls.path_coefficients()
    npt.assert_allclose(expected_paths.sort_index().sort_index(axis=1),
                        actual_paths.sort_index().sort_index(axis=1),
                        rtol=1e-6)
コード例 #8
0
def russa_path_matrix():
    structure = c.Structure()
    structure.add_path(["AGRI", "IND"], ["POLINS"])
    return structure.path()