Skip to content

Extract GLM variables from calling environment #3381

Closed
@adamboche

Description

@adamboche

If you have questions about a specific use case, or you are not sure whether this is a bug or not, please post it to our discourse channel: https://discourse.pymc.io

Description of your problem

Please provide a minimal, self-contained, and reproducible example.

import pandas as pd
import patsy
import pymc3

z = pd.Series([10, 20, 30])
df = pd.DataFrame({"y": [0, 1, 0], "x": [1.0, 2.0, 3.0]})
pymc3.glm.GLM.from_formula("y ~ x + z", df, family=pymc3.glm.families.Binomial())

Please provide the full traceback.

Traceback (most recent call last):
  File "/home/adam/tmp/venv/lib/python3.6/site-packages/patsy/compat.py", line 36, in call_and_wrap_exc
    return f(*args, **kwargs)
  File "/home/adam/tmp/venv/lib/python3.6/site-packages/patsy/eval.py", line 166, in eval
    + self._namespaces))
  File "<string>", line 1, in <module>
NameError: name 'z' is not defined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "my.py", line 7, in <module>
    pymc3.glm.GLM.from_formula("y ~ x + z", df, family=pymc3.glm.families.Binomial())
  File "/home/adam/Documents/pymc3/pymc3/glm/linear.py", line 145, in from_formula
    y, x = patsy.dmatrices(formula, data)
  File "/home/adam/tmp/venv/lib/python3.6/site-packages/patsy/highlevel.py", line 310, in dmatrices
    NA_action, return_type)
  File "/home/adam/tmp/venv/lib/python3.6/site-packages/patsy/highlevel.py", line 165, in _do_highlevel_design
    NA_action)
  File "/home/adam/tmp/venv/lib/python3.6/site-packages/patsy/highlevel.py", line 70, in _try_incr_builders
    NA_action)
  File "/home/adam/tmp/venv/lib/python3.6/site-packages/patsy/build.py", line 696, in design_matrix_builders
    NA_action)
  File "/home/adam/tmp/venv/lib/python3.6/site-packages/patsy/build.py", line 443, in _examine_factor_types
    value = factor.eval(factor_states[factor], data)
  File "/home/adam/tmp/venv/lib/python3.6/site-packages/patsy/eval.py", line 566, in eval
    data)
  File "/home/adam/tmp/venv/lib/python3.6/site-packages/patsy/eval.py", line 551, in _eval
    inner_namespace=inner_namespace)
  File "/home/adam/tmp/venv/lib/python3.6/site-packages/patsy/compat.py", line 43, in call_and_wrap_exc
    exec("raise new_exc from e")
  File "<string>", line 1, in <module>
patsy.PatsyError: Error evaluating factor: NameError: name 'z' is not defined
    y ~ x + z
            ^

Please provide any additional information below.

Versions and main components

  • PyMC3 Version: 3.6
  • Theano Version: 1.0.4
  • Python Version: 3.6.7
  • Operating system: Ubuntu 18.04
  • How did you install PyMC3: pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions