Ejemplo n.º 1
0
def test_identify_relevant_covariates():
    params = pd.read_csv(
        io.StringIO(
            dedent("""
                category,name,value
                wage_a,constant,1
                nonpec_b,upper_upper,1
                wage_c,upper_upper_with_spacing_problem,1
                """)),
        index_col=["category", "name"],
    )

    options = {
        "covariates": {
            "constant": "1",
            "nested_covariate": "2",
            "upper": "nested_covariate > 2",
            "upper_upper": "upper == 5",
            "unrelated_covariate": "2",
            "unrelated_covariate_upper": "unrelated_covariate",
            "upper_upper_with_spacing_problem": "upper>2",
        }
    }

    expected = options.copy()
    expected["covariates"].pop("unrelated_covariate")
    expected["covariates"].pop("unrelated_covariate_upper")

    relevant_covariates = remove_irrelevant_covariates(options, params)

    assert expected == relevant_covariates
Ejemplo n.º 2
0
def process_params_and_options(params, options):
    """Process ``params`` and ``options``.

    This function is interface for parsing the model specification given by the user.

    """
    options = _read_options(options)
    params = _read_params(params)

    options = {**DEFAULT_OPTIONS, **options}
    options = _create_internal_seeds_from_user_seeds(options)
    options = remove_irrelevant_covariates(options, params)
    validate_options(options)

    optim_paras = _parse_parameters(params, options)
    optim_paras, options = _sync_optim_paras_and_options(optim_paras, options)
    validate_params(params, optim_paras)

    return optim_paras, options