Skip to content
This repository was archived by the owner on Mar 16, 2026. It is now read-only.
This repository was archived by the owner on Mar 16, 2026. It is now read-only.

Failure with categorical variables run in pyfixest? #238

@donbowen

Description

@donbowen

Hi @vincentarelbundock

Tried to get this working, but failed.

from marginaleffects import hypotheses
import pyfixest as pf

data = pf.get_data() 
fit = pf.feols("Y ~ i(f1)", data=data)
pf.etable(fit)

# pick any two coefs to test
hypotheses(fit, f"Q({fit._coefnames[1]}) + Q({fit._coefnames[2]}) = 0")
---------------------------------------------------------------------------
ColumnNotFoundError                       Traceback (most recent call last)
<ipython-input-17-b451ce25fdde> in ?()
----> 1 hypotheses(fit, f"Q({fit._coefnames[1]}) + Q({fit._coefnames[2]}) = 0")

c:\Users\deb219\AppData\Local\anaconda3\Lib\site-packages\marginaleffects\hypotheses.py in ?(model, hypothesis, conf_level, vcov, equivalence, eps_vcov, joint, joint_test)
    106     eps_vcov=None,
    107     joint=False,
    108     joint_test="f",
    109 ):
--> 110     model = sanitize_model(model)
    111 
    112     if joint:
    113         out = joint_hypotheses(

c:\Users\deb219\AppData\Local\anaconda3\Lib\site-packages\marginaleffects\sanitize_model.py in ?(model)
     37 
     38     elif is_pyfixest(model):
     39         from .pyfixest import ModelPyfixest
     40 
---> 41         return ModelPyfixest(model)
     42 
     43     raise ValueError(
     44         "Unknown model type. Supported modelling packages include `statsmodels` and `pyfixst`. In addition, users can call `fit_sklearn()` or `fit_linearmodels()` to fit models using the Scikit-Learn and LinearModels modelling packages."

c:\Users\deb219\AppData\Local\anaconda3\Lib\site-packages\marginaleffects\pyfixest\model.py in ?(self, model, vault)
     13             "modeldata": modeldata,
     14             "formula": formula,
     15         }
     16         vault.update(cache)
---> 17         super().__init__(model, vault)
     18 
     19         # after super init & validation
     20         if hasattr(model, "_fixef"):

c:\Users\deb219\AppData\Local\anaconda3\Lib\site-packages\marginaleffects\model_abstract.py in ?(self, model, vault)
      8     def __init__(self, model, vault):
      9         self.model = model
     10         self.vault = vault
---> 11         self.validation()

c:\Users\deb219\AppData\Local\anaconda3\Lib\site-packages\marginaleffects\validation.py in ?(self)
     11         self.validate_response_name()
     12         self.validate_formula()
     13         self.validate_modeldata()
     14         self.vault.update(
---> 15             variables_type=get_type_dictionary(self.get_formula(), self.get_modeldata())
     16         )

c:\Users\deb219\AppData\Local\anaconda3\Lib\site-packages\marginaleffects\utils.py in ?(formula, modeldata)
    169         ]
    170         t_c = [pl.Utf8, pl.Categorical, pl.Enum]
    171         t_n = [pl.Float32, pl.Float64]
    172         t_b = [pl.Boolean]
--> 173         if modeldata[v].dtype in t_i:
    174             if modeldata[v].is_in([0, 1]).all():
    175                 out[v] = "binary"
    176             else:

c:\Users\deb219\AppData\Local\anaconda3\Lib\site-packages\polars\dataframe\frame.py in ?(self, key)
   1399         │ 2   ┆ 5   ┆ 3   │
   1400         │ 3   ┆ 6   ┆ 2   │
   1401         └─────┴─────┴─────┘
   1402         """
-> 1403         return get_df_item_by_key(self, key)

c:\Users\deb219\AppData\Local\anaconda3\Lib\site-packages\polars\_utils\getitem.py in ?(df, key)
    159     # Single string input, e.g. df["a"]
    160     if isinstance(key, str):
    161         # This case is required because empty strings are otherwise treated
    162         # as an empty Sequence in `_select_rows`
--> 163         return df.get_column(key)
    164 
    165     # Single input - df[1] - or multiple inputs - df["a", "b", "c"]
    166     try:

c:\Users\deb219\AppData\Local\anaconda3\Lib\site-packages\polars\dataframe\frame.py in ?(self, name, default)
   9035         try:
   9036             return wrap_s(self._df.get_column(name))
   9037         except ColumnNotFoundError:
   9038             if default is no_default:
-> 9039                 raise
   9040             return default

ColumnNotFoundError: "i" not found

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions