You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Constructing a proportional hazard model from a formula with smf.phreg (aka PHReg.from_formula) doesn't use the proper environment.
Specifically, PHReg overrides the from_formula class method but doesn't adjust or set the eval_env keyword. It calls Model.from_formula to parse the formula, but Model.from_formula doesn't know that it was called indirectly and therefore underestimates its depth by one. In the default case, Model.from_formula pulls the environment from where it was called, but this is hazard_regression.py rather than the user's environment (where PHReg.from_formula was called). User-defined symbols aren't found, though internal ones like np are available.
This problem should also show up for all the other subclass implementations of from_formulas (e.g., GEE, QIF, OrderedModel).
Describe the bug
Constructing a proportional hazard model from a formula with
smf.phreg
(akaPHReg.from_formula
) doesn't use the proper environment.Specifically,
PHReg
overrides thefrom_formula
class method but doesn't adjust or set theeval_env
keyword. It callsModel.from_formula
to parse the formula, butModel.from_formula
doesn't know that it was called indirectly and therefore underestimates its depth by one. In the default case,Model.from_formula
pulls the environment from where it was called, but this ishazard_regression.py
rather than the user's environment (wherePHReg.from_formula
was called). User-defined symbols aren't found, though internal ones likenp
are available.This problem should also show up for all the other subclass implementations of
from_formula
s (e.g.,GEE
,QIF
,OrderedModel
).Code Sample, a copy-pastable example if possible
Expected Output
A clear and concise description of what you expected to happen.
Output of
import statsmodels.api as sm; sm.show_versions()
INSTALLED VERSIONS
Python: 3.11.5.final.0
OS: Darwin
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
statsmodels
Installed: 0.14.0
Required Dependencies
cython: Not installed
numpy: 1.26.1
scipy: 1.11.3
pandas: 2.1.1
dateutil: 2.8.2
patsy: 0.5.3
Optional Dependencies
matplotlib: Not installed
cvxopt: Not installed
joblib: Not installed
Developer Tools
IPython: Not installed
jinja2: Not installed
sphinx: Not installed
pygments: Not installed
pytest: Not installed
virtualenv: Not installed
The text was updated successfully, but these errors were encountered: