Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail to define a model with random slope for individuals #393

Open
XiaoyuZeng opened this issue Apr 16, 2024 · 2 comments
Open

fail to define a model with random slope for individuals #393

XiaoyuZeng opened this issue Apr 16, 2024 · 2 comments
Assignees
Labels
bug Something isn't working upstream Related to upstream packages

Comments

@XiaoyuZeng
Copy link

XiaoyuZeng commented Apr 16, 2024

Describe the bug
A clear and concise description of what the bug is.

I am unable to fit a ddm with hierarchical structure that I want to also fit random slope at the individual level.

I encountered a error report:

ValueError: Size length is incompatible with batched dimensions of parameter 0 Cast{float32}.0:
len(size) = 1, len(batched dims Cast{float32}.0) = 2. Size length must be 0 or >= 2

I confirmed that this error did not occur when I:

  • used the hssm installed through pip install (0.2.0? I'm not sure)
  • directly removed the random slope term such as (1+condition * stage|subj_idx)
  • only estimated random intercept but not random slope

HSSM version
What is the version of HSSM you are using?
hssm 0.2.1.

To Reproduce
Minimum reproducible code for us to reproduce the error.

data:

icns_BARTall_HDDM_inputdata_allstage_temp.csv

model:

mfull = hssm.HSSM(
model="ddm",
data=df,
include=[
{
"name": "v",
"formula": "v ~ 1 + condition * stage + (1+condition * stage|subj_idx)",
"link": "identity",
},
{
"name": "z",
"formula": "z ~ 1 + condition * stage + (1+condition * stage|subj_idx)",
"link": "identity",
},
{
"name": "a",
"formula": "a ~ 1 + condition * stage + (1+condition * stage|subj_idx)",
"link": "identity",
},
{
"name": "t",
"formula": "t ~ 1 + condition * stage + (1+condition * stage|subj_idx)",
"link": "identity",
},
],
)

Screenshots
If applicable, add screenshots to help explain your problem.

no

Additional context
Add any other context about the problem here, such as the print out of the model.
here I report all of the error report information:

ValueError Traceback (most recent call last)
Cell In[6], line 1
----> 1 mfull = hssm.HSSM(model="ddm",
2 data=df,
3 include=[
4 {
5 "name": "v",
6 "formula": "v ~ 1 + condition * stage + (1+condition * stage|subj_idx)",
7 "link": "identity",
8 },
9 {
10 "name": "z",
11 "formula": "z ~ 1 + condition * stage + (1+condition * stage|subj_idx)",
12 "link": "identity",
13 },
14 {
15 "name": "a",
16 "formula": "a ~ 1 + condition * stage + (1+condition * stage|subj_idx)",
17 "link": "identity",
18 },
19 {
20 "name": "t",
21 "formula": "t ~ 1 + condition * stage + (1+condition * stage|subj_idx)",
22 "link": "identity",
23 },
24 ],)

File ~\AppData\Roaming\Python\Python311\site-packages\hssm\hssm.py:386, in HSSM.init(self, data, model, include, model_config, loglik, loglik_kind, p_outlier, lapse, hierarchical, link_settings, prior_settings, extra_namespace, missing_data, deadline, loglik_missing_data, **kwargs)
374 self.model = bmb.Model(
375 self.formula,
376 data=self.data,
(...)
380 **other_kwargs,
381 )
383 self._aliases = _get_alias_dict(
384 self.model, self._parent_param, self.response_c, self.response_str
385 )
--> 386 self.set_alias(self._aliases)
387 self._postprocess_initvals_deterministic(initval_settings=INITVAL_SETTINGS)
388 self._jitter_initvals(
389 jitter_epsilon=INITVAL_JITTER_SETTINGS["jitter_epsilon"], vector_only=True
390 )

File ~\AppData\Roaming\Python\Python311\site-packages\hssm\hssm.py:675, in HSSM.set_alias(self, aliases)
664 """Set parameter aliases.
665
666 Sets the aliases according to the dictionary passed to it and rebuild the
(...)
672 A dict specifying the parameter names being aliased and the aliases.
673 """
674 self.model.set_alias(aliases)
--> 675 self.model.build()

File ~\AppData\Roaming\Python\Python311\site-packages\bambi\models.py:358, in Model.build(self)
349 """Set up the model for sampling/fitting.
350
351 Creates an instance of the underlying PyMC model and adds all the necessary terms to it.
(...)
355 None
356 """
357 self.backend = PyMCModel()
--> 358 self.backend.build(self)
359 self.built = True

File ~\AppData\Roaming\Python\Python311\site-packages\bambi\backend\pymc.py:72, in PyMCModel.build(self, spec)
69 self.components[name] = DistributionalComponent(component)
70 self.components[name].build(self, spec)
---> 72 self.build_response(spec)
73 self.build_potentials(spec)
75 self.spec = spec

File ~\AppData\Roaming\Python\Python311\site-packages\bambi\backend\pymc.py:129, in PyMCModel.build_response(self, spec)
121 """Add response term to the PyMC model
122
123 Parameters
(...)
126 The model.
127 """
128 response_component = self.components[spec.response_name]
--> 129 response_component.build_response(self, spec)

File ~\AppData\Roaming\Python\Python311\site-packages\bambi\backend\model_components.py:165, in DistributionalComponent.build_response(self, pymc_backend, bmb_model)
163 # Create and build the response term
164 response_term = ResponseTerm(response_term, bmb_model.family)
--> 165 response_term.build(pymc_backend, bmb_model)

File ~\AppData\Roaming\Python\Python311\site-packages\bambi\backend\terms.py:264, in ResponseTerm.build(self, pymc_backend, bmb_model)
261 kwargs[parent] = linkinv(eta)
263 # Build the response distribution
--> 264 dist = self.build_response_distribution(kwargs, pymc_backend)
266 return dist

File ~\AppData\Roaming\Python\Python311\site-packages\bambi\backend\terms.py:299, in ResponseTerm.build_response_distribution(self, kwargs, pymc_backend)
295 dist_rv = pm.Censored(
296 self.name, stateless_dist, lower=lower, upper=upper, observed=observed, dims=dims
297 )
298 else:
--> 299 dist_rv = distribution(self.name, **kwargs)
301 return dist_rv

File ~\AppData\Roaming\Python\Python311\site-packages\pymc\distributions\distribution.py:554, in Distribution.new(cls, name, rng, dims, initval, observed, total_size, transform, *args, **kwargs)
551 elif observed is not None:
552 kwargs["shape"] = tuple(observed.shape)
--> 554 rv_out = cls.dist(*args, **kwargs)
556 rv_out = model.register_rv(
557 rv_out,
558 name,
(...)
563 initval=initval,
564 )
566 # add in pretty-printing support

File ~\AppData\Roaming\Python\Python311\site-packages\hssm\distribution_utils\dist.py:437, in make_distribution..SSMDistribution.dist(cls, **kwargs)
435 dist_params += [pm.floatX(field) for field in cls._extra_fields]
436 other_kwargs = {k: v for k, v in kwargs.items() if k not in cls.params}
--> 437 return super().dist(dist_params, **other_kwargs)

File ~\AppData\Roaming\Python\Python311\site-packages\pymc\distributions\distribution.py:633, in Distribution.dist(cls, dist_params, shape, **kwargs)
631 ndim_supp = cls.rv_op(*dist_params, **kwargs).owner.op.ndim_supp
632 create_size = find_size(shape=shape, size=size, ndim_supp=ndim_supp)
--> 633 rv_out = cls.rv_op(*dist_params, size=create_size, **kwargs)
635 rv_out.logp = _make_nice_attr_error("rv.logp(x)", "pm.logp(rv, x)")
636 rv_out.logcdf = _make_nice_attr_error("rv.logcdf(x)", "pm.logcdf(rv, x)")

File ~\AppData\Roaming\Python\Python311\site-packages\pytensor\tensor\random\op.py:241, in RandomVariable.call(self, size, name, rng, dtype, *args, **kwargs)
240 def call(self, *args, size=None, name=None, rng=None, dtype=None, **kwargs):
--> 241 res = super().call(rng, size, dtype, *args, **kwargs)
243 if name is not None:
244 res.name = name

File ~\AppData\Roaming\Python\Python311\site-packages\pytensor\graph\op.py:292, in Op.call(self, *inputs, **kwargs)
250 r"""Construct an Apply node using :meth:Op.make_node and return its outputs.
251
252 This method is just a wrapper around :meth:Op.make_node.
(...)
289
290 """
291 return_list = kwargs.pop("return_list", False)
--> 292 node = self.make_node(*inputs, **kwargs)
294 if config.compute_test_value != "off":
295 compute_test_value(node)

File ~\AppData\Roaming\Python\Python311\site-packages\pytensor\tensor\random\op.py:286, in RandomVariable.make_node(self, rng, size, dtype, *dist_params)
281 elif not isinstance(rng.type, RandomType):
282 raise TypeError(
283 "The type of rng should be an instance of either RandomGeneratorType or RandomStateType"
284 )
--> 286 shape = self._infer_shape(size, dist_params)
287 _, static_shape = infer_static_shape(shape)
288 dtype = self.dtype or dtype

File ~\AppData\Roaming\Python\Python311\site-packages\pytensor\tensor\random\op.py:173, in RandomVariable._infer_shape(self, size, dist_params, param_shapes)
171 param_batched_dims = getattr(param, "ndim", 0) - param_ndim_supp
172 if param_batched_dims > size_len:
--> 173 raise ValueError(
174 f"Size length is incompatible with batched dimensions of parameter {i} {param}:\n"
175 f"len(size) = {size_len}, len(batched dims {param}) = {param_batched_dims}. "
176 f"Size length must be 0 or >= {param_batched_dims}"
177 )
179 return tuple(size) + supp_shape
181 # Size was not provided, we must infer it from the shape of the parameters

ValueError: Size length is incompatible with batched dimensions of parameter 0 Cast{float32}.0:
len(size) = 1, len(batched dims Cast{float32}.0) = 2. Size length must be 0 or >= 2

@AlexanderFengler
Copy link
Collaborator

@XiaoyuZeng,
thank you for reporting this. I will look into it, not immediately clear what's causing the issue here.

@digicosmos86 digicosmos86 added bug Something isn't working upstream Related to upstream packages labels May 8, 2024
@reedorchinik
Copy link

Hello, I receive a similar error when using random slopes in a model. I am also using version 0.2.2. Any insights/help would be very much appreciated. Thanks!

If I use the following model, I receive the error:
Model:

model = hssm.HSSM(
    data=df,
    hierarchical = True,
    link_settings = "log_logit",
    loglik_kind = "blackbox",
        include = [
            {
                "name": "v",
                "formula": "v ~ 1 + plausibility + C(repeated) + (1 + plausibility + C(repeated) | participant_id)",
                "prior": {
                    "Intercept": {"name": "Normal", "mu": 0, "sigma": 3},
                    "plausibility": {"name": "Normal", "mu": 0, "sigma": 3},
                    "C(repeated)": {"name": "Normal", "mu": 0, "sigma": 3}
                },
                "link": "identity"
            }
    ]
)

Error:

ValueError                                Traceback (most recent call last)
Cell In[12], [line 1](vscode-notebook-cell:?execution_count=12&line=1)
----> [1](vscode-notebook-cell:?execution_count=12&line=1) model = hssm.HSSM(
      [2](vscode-notebook-cell:?execution_count=12&line=2)     data=df,
      [3](vscode-notebook-cell:?execution_count=12&line=3)     hierarchical = True,
      [4](vscode-notebook-cell:?execution_count=12&line=4)     link_settings = "log_logit",
      [5](vscode-notebook-cell:?execution_count=12&line=5)     loglik_kind = "blackbox",
      [6](vscode-notebook-cell:?execution_count=12&line=6)         include = [
      [7](vscode-notebook-cell:?execution_count=12&line=7)             {
      [8](vscode-notebook-cell:?execution_count=12&line=8)                 "name": "v",
      [9](vscode-notebook-cell:?execution_count=12&line=9)                 "formula": "v ~ 1 + plausibility + C(repeated) + (1 + plausibility + C(repeated) | participant_id)",
     [10](vscode-notebook-cell:?execution_count=12&line=10)                 "prior": {
     [11](vscode-notebook-cell:?execution_count=12&line=11)                     "Intercept": {"name": "Normal", "mu": 0, "sigma": 3},
     [12](vscode-notebook-cell:?execution_count=12&line=12)                     "plausibility": {"name": "Normal", "mu": 0, "sigma": 3},
     [13](vscode-notebook-cell:?execution_count=12&line=13)                     "C(repeated)": {"name": "Normal", "mu": 0, "sigma": 3}
     [14](vscode-notebook-cell:?execution_count=12&line=14)                 },
     [15](vscode-notebook-cell:?execution_count=12&line=15)                 "link": "identity"
     [16](vscode-notebook-cell:?execution_count=12&line=16)             }
     [17](vscode-notebook-cell:?execution_count=12&line=17)     ]
     [18](vscode-notebook-cell:?execution_count=12&line=18) )
     [20](vscode-notebook-cell:?execution_count=12&line=20) model

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:406, in HSSM.__init__(self, data, model, choices, include, model_config, loglik, loglik_kind, p_outlier, lapse, hierarchical, link_settings, prior_settings, extra_namespace, missing_data, deadline, loglik_missing_data, process_initvals, **kwargs)
    [394](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:394) self.model = bmb.Model(
    [395](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:395)     self.formula,
    [396](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:396)     data=self.data,
   (...)
    [400](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:400)     **other_kwargs,
    [401](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:401) )
    [403](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:403) self._aliases = _get_alias_dict(
    [404](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:404)     self.model, self._parent_param, self.response_c, self.response_str
    [405](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:405) )
--> [406](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:406) self.set_alias(self._aliases)
    [407](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:407) # _logger.info(self.pymc_model.initial_point())
    [409](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:409) if process_initvals:

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:877, in HSSM.set_alias(self, aliases)
    [866](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:866) """Set parameter aliases.
    [867](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:867) 
    [868](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:868) Sets the aliases according to the dictionary passed to it and rebuild the
   (...)
    [874](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:874)     A dict specifying the parameter names being aliased and the aliases.
    [875](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:875) """
    [876](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:876) self.model.set_alias(aliases)
--> [877](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:877) self.model.build()

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:358, in Model.build(self)
    [349](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:349) """Set up the model for sampling/fitting.
    [350](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:350) 
    [351](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:351) Creates an instance of the underlying PyMC model and adds all the necessary terms to it.
   (...)
    [355](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:355) None
    [356](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:356) """
    [357](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:357) self.backend = PyMCModel()
--> [358](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:358) self.backend.build(self)
    [359](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:359) self.built = True

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:72, in PyMCModel.build(self, spec)
     [69](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:69)         self.components[name] = DistributionalComponent(component)
     [70](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:70)         self.components[name].build(self, spec)
---> [72](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:72)     self.build_response(spec)
     [73](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:73)     self.build_potentials(spec)
     [75](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:75) self.spec = spec

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:129, in PyMCModel.build_response(self, spec)
    [121](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:121) """Add response term to the PyMC model
    [122](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:122) 
    [123](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:123) Parameters
   (...)
    [126](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:126)     The model.
    [127](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:127) """
    [128](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:128) response_component = self.components[spec.response_name]
--> [129](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:129) response_component.build_response(self, spec)

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/model_components.py:165, in DistributionalComponent.build_response(self, pymc_backend, bmb_model)
    [163](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/model_components.py:163) # Create and build the response term
    [164](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/model_components.py:164) response_term = ResponseTerm(response_term, bmb_model.family)
--> [165](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/model_components.py:165) response_term.build(pymc_backend, bmb_model)

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:264, in ResponseTerm.build(self, pymc_backend, bmb_model)
    [261](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:261) kwargs[parent] = linkinv(eta)
    [263](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:263) # Build the response distribution
--> [264](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:264) dist = self.build_response_distribution(kwargs, pymc_backend)
    [266](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:266) return dist

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:299, in ResponseTerm.build_response_distribution(self, kwargs, pymc_backend)
    [295](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:295)     dist_rv = pm.Censored(
    [296](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:296)         self.name, stateless_dist, lower=lower, upper=upper, observed=observed, dims=dims
    [297](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:297)     )
    [298](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:298) else:
--> [299](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:299)     dist_rv = distribution(self.name, **kwargs)
    [301](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:301) return dist_rv

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:536, in Distribution.__new__(cls, name, rng, dims, initval, observed, total_size, transform, default_transform, *args, **kwargs)
    [533](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:533)     elif observed is not None:
    [534](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:534)         kwargs["shape"] = tuple(observed.shape)
--> [536](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:536) rv_out = cls.dist(*args, **kwargs)
    [538](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:538) rv_out = model.register_rv(
    [539](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:539)     rv_out,
    [540](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:540)     name,
   (...)
    [546](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:546)     initval=initval,
    [547](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:547) )
    [549](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:549) # add in pretty-printing support

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/distribution_utils/dist.py:437, in make_distribution.<locals>.SSMDistribution.dist(cls, **kwargs)
    [435](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/distribution_utils/dist.py:435)     dist_params += [pm.floatX(field) for field in cls._extra_fields]
    [436](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/distribution_utils/dist.py:436) other_kwargs = {k: v for k, v in kwargs.items() if k not in cls.params}
--> [437](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/distribution_utils/dist.py:437) return super().dist(dist_params, **other_kwargs)

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:618, in Distribution.dist(cls, dist_params, shape, **kwargs)
    [615](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:615)     ndim_supp = cls.rv_op(*dist_params, **kwargs).owner.op.ndim_supp
    [617](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:617) create_size = find_size(shape=shape, size=size, ndim_supp=ndim_supp)
--> [618](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:618) rv_out = cls.rv_op(*dist_params, size=create_size, **kwargs)
    [620](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:620) rv_out.logp = _make_nice_attr_error("rv.logp(x)", "pm.logp(rv, x)")
    [621](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py:621) rv_out.logcdf = _make_nice_attr_error("rv.logcdf(x)", "pm.logcdf(rv, x)")

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:311, in RandomVariable.__call__(self, size, name, rng, dtype, *args, **kwargs)
    [309](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:309)     props["dtype"] = dtype
    [310](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:310)     new_op = type(self)(**props)
--> [311](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:311)     return new_op.__call__(
    [312](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:312)         *args, size=size, name=name, rng=rng, dtype=dtype, **kwargs
    [313](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:313)     )
    [315](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:315) res = super().__call__(rng, size, *args, **kwargs)
    [317](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:317) if name is not None:

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:315, in RandomVariable.__call__(self, size, name, rng, dtype, *args, **kwargs)
    [310](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:310)     new_op = type(self)(**props)
    [311](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:311)     return new_op.__call__(
    [312](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:312)         *args, size=size, name=name, rng=rng, dtype=dtype, **kwargs
    [313](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:313)     )
--> [315](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:315) res = super().__call__(rng, size, *args, **kwargs)
    [317](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:317) if name is not None:
    [318](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:318)     res.name = name

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/graph/op.py:293, in Op.__call__(self, name, return_list, *inputs, **kwargs)
    [249](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/graph/op.py:249) def __call__(
    [250](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/graph/op.py:250)     self, *inputs: Any, name=None, return_list=False, **kwargs
    [251](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/graph/op.py:251) ) -> Variable | list[Variable]:
    [252](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/graph/op.py:252)     r"""Construct an `Apply` node using :meth:`Op.make_node` and return its outputs.
    [253](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/graph/op.py:253) 
    [254](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/graph/op.py:254)     This method is just a wrapper around :meth:`Op.make_node`.
   (...)
    [291](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/graph/op.py:291) 
    [292](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/graph/op.py:292)     """
--> [293](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/graph/op.py:293)     node = self.make_node(*inputs, **kwargs)
    [294](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/graph/op.py:294)     if name is not None:
    [295](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/graph/op.py:295)         if len(node.outputs) == 1:

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:359, in RandomVariable.make_node(self, rng, size, *dist_params)
    [354](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:354) elif not isinstance(rng.type, RandomType):
    [355](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:355)     raise TypeError(
    [356](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:356)         "The type of rng should be an instance of RandomGeneratorType "
    [357](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:357)     )
--> [359](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:359) inferred_shape = self._infer_shape(size, dist_params)
    [360](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:360) _, static_shape = infer_static_shape(inferred_shape)
    [362](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:362) dist_params = explicit_expand_dims(
    [363](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:363)     dist_params,
    [364](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:364)     self.ndims_params,
    [365](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:365)     size_length=None if NoneConst.equals(size) else get_vector_length(size),
    [366](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:366) )

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:237, in RandomVariable._infer_shape(self, size, dist_params, param_shapes)
    [235](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:235)         param_batched_dims = getattr(param, "ndim", 0) - param_ndim_supp
    [236](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:236)         if param_batched_dims > size_len:
--> [237](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:237)             raise ValueError(
    [238](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:238)                 f"Size length is incompatible with batched dimensions of parameter {i} {param}:\n"
    [239](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:239)                 f"len(size) = {size_len}, len(batched dims {param}) = {param_batched_dims}. "
    [240](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:240)                 f"Size length must be 0 or >= {param_batched_dims}"
    [241](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:241)             )
    [243](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:243)     return tuple(size) + supp_shape
    [245](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pytensor/tensor/random/op.py:245) # Size was not provided, we must infer it from the shape of the parameters

ValueError: Size length is incompatible with batched dimensions of parameter 0 Cast{float32}.0:
len(size) = 1, len(batched dims Cast{float32}.0) = 2. Size length must be 0 or >= 2

When I use a more complicated model that includes a random slope for z, I receive a different but seemingly related error.

Model:

model = hssm.HSSM(
    data=df,
    hierarchical = True,
    link_settings = "log_logit",
    loglik_kind = "blackbox",
        include = [
            {
                "name": "v",
                "formula": "v ~ 1 + plausibility + C(repeated) + (1 + plausibility + C(repeated) | participant_id)",
                "prior": {
                    "Intercept": {"name": "Normal", "mu": 0, "sigma": 3},
                    "plausibility": {"name": "Normal", "mu": 0, "sigma": 3},
                    "C(repeated)": {"name": "Normal", "mu": 0, "sigma": 3}
                },
                "link": "identity"
            },
            {
                "name": "a",
                "formula": "a ~ 1 + (1 | participant_id)",
                "link": "identity"
            },
            {
                "name": "z",
                "formula": "z ~ 1 + C(repeated) + (1 + C(repeated) | participant_id)",
                "prior": {
                    "Intercept": {"name": "Normal", "mu": 0, "sigma": 3},
                    "repeated": {"name": "Normal", "mu": 0, "sigma": 3}
                }
            },
            {
                "name": "t",
                "formula": "t ~ 1 + (1 | participant_id)",
                "link": "identity"
            }
    ]
)

Error:

ValueError                                Traceback (most recent call last)
Cell In[10], [line 1](vscode-notebook-cell:?execution_count=10&line=1)
----> [1](vscode-notebook-cell:?execution_count=10&line=1) model = hssm.HSSM(
      [2](vscode-notebook-cell:?execution_count=10&line=2)     data=df,
      [3](vscode-notebook-cell:?execution_count=10&line=3)     hierarchical = True,
      [4](vscode-notebook-cell:?execution_count=10&line=4)     link_settings = "log_logit",
      [5](vscode-notebook-cell:?execution_count=10&line=5)     loglik_kind = "blackbox",
      [6](vscode-notebook-cell:?execution_count=10&line=6)         include = [
      [7](vscode-notebook-cell:?execution_count=10&line=7)             {
      [8](vscode-notebook-cell:?execution_count=10&line=8)                 "name": "v",
      [9](vscode-notebook-cell:?execution_count=10&line=9)                 "formula": "v ~ 1 + plausibility + C(repeated) + (1 + plausibility + C(repeated) | participant_id)",
     [10](vscode-notebook-cell:?execution_count=10&line=10)                 "prior": {
     [11](vscode-notebook-cell:?execution_count=10&line=11)                     "Intercept": {"name": "Normal", "mu": 0, "sigma": 3},
     [12](vscode-notebook-cell:?execution_count=10&line=12)                     "plausibility": {"name": "Normal", "mu": 0, "sigma": 3},
     [13](vscode-notebook-cell:?execution_count=10&line=13)                     "C(repeated)": {"name": "Normal", "mu": 0, "sigma": 3}
     [14](vscode-notebook-cell:?execution_count=10&line=14)                 },
     [15](vscode-notebook-cell:?execution_count=10&line=15)                 "link": "identity"
     [16](vscode-notebook-cell:?execution_count=10&line=16)             },
     [17](vscode-notebook-cell:?execution_count=10&line=17)             {
     [18](vscode-notebook-cell:?execution_count=10&line=18)                 "name": "a",
     [19](vscode-notebook-cell:?execution_count=10&line=19)                 "formula": "a ~ 1 + (1 | participant_id)",
     [20](vscode-notebook-cell:?execution_count=10&line=20)                 "link": "identity"
     [21](vscode-notebook-cell:?execution_count=10&line=21)             },
     [22](vscode-notebook-cell:?execution_count=10&line=22)             {
     [23](vscode-notebook-cell:?execution_count=10&line=23)                 "name": "z",
     [24](vscode-notebook-cell:?execution_count=10&line=24)                 "formula": "z ~ 1 + C(repeated) + (1 + C(repeated) | participant_id)",
     [25](vscode-notebook-cell:?execution_count=10&line=25)                 "prior": {
     [26](vscode-notebook-cell:?execution_count=10&line=26)                     "Intercept": {"name": "Normal", "mu": 0, "sigma": 3},
     [27](vscode-notebook-cell:?execution_count=10&line=27)                     "repeated": {"name": "Normal", "mu": 0, "sigma": 3}
     [28](vscode-notebook-cell:?execution_count=10&line=28)                 }
     [29](vscode-notebook-cell:?execution_count=10&line=29)             },
     [30](vscode-notebook-cell:?execution_count=10&line=30)             {
     [31](vscode-notebook-cell:?execution_count=10&line=31)                 "name": "t",
     [32](vscode-notebook-cell:?execution_count=10&line=32)                 "formula": "t ~ 1 + (1 | participant_id)",
     [33](vscode-notebook-cell:?execution_count=10&line=33)                 "link": "identity"
     [34](vscode-notebook-cell:?execution_count=10&line=34)             }
     [35](vscode-notebook-cell:?execution_count=10&line=35)     ]
     [36](vscode-notebook-cell:?execution_count=10&line=36) )
     [38](vscode-notebook-cell:?execution_count=10&line=38) model

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:406, in HSSM.__init__(self, data, model, choices, include, model_config, loglik, loglik_kind, p_outlier, lapse, hierarchical, link_settings, prior_settings, extra_namespace, missing_data, deadline, loglik_missing_data, process_initvals, **kwargs)
    [394](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:394) self.model = bmb.Model(
    [395](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:395)     self.formula,
    [396](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:396)     data=self.data,
   (...)
    [400](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:400)     **other_kwargs,
    [401](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:401) )
    [403](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:403) self._aliases = _get_alias_dict(
    [404](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:404)     self.model, self._parent_param, self.response_c, self.response_str
    [405](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:405) )
--> [406](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:406) self.set_alias(self._aliases)
    [407](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:407) # _logger.info(self.pymc_model.initial_point())
    [409](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:409) if process_initvals:

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:877, in HSSM.set_alias(self, aliases)
    [866](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:866) """Set parameter aliases.
    [867](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:867) 
    [868](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:868) Sets the aliases according to the dictionary passed to it and rebuild the
   (...)
    [874](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:874)     A dict specifying the parameter names being aliased and the aliases.
    [875](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:875) """
    [876](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:876) self.model.set_alias(aliases)
--> [877](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/hssm/hssm.py:877) self.model.build()

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:358, in Model.build(self)
    [349](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:349) """Set up the model for sampling/fitting.
    [350](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:350) 
    [351](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:351) Creates an instance of the underlying PyMC model and adds all the necessary terms to it.
   (...)
    [355](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:355) None
    [356](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:356) """
    [357](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:357) self.backend = PyMCModel()
--> [358](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:358) self.backend.build(self)
    [359](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/models.py:359) self.built = True

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:72, in PyMCModel.build(self, spec)
     [69](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:69)         self.components[name] = DistributionalComponent(component)
     [70](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:70)         self.components[name].build(self, spec)
---> [72](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:72)     self.build_response(spec)
     [73](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:73)     self.build_potentials(spec)
     [75](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:75) self.spec = spec

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:129, in PyMCModel.build_response(self, spec)
    [121](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:121) """Add response term to the PyMC model
    [122](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:122) 
    [123](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:123) Parameters
   (...)
    [126](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:126)     The model.
    [127](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:127) """
    [128](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:128) response_component = self.components[spec.response_name]
--> [129](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py:129) response_component.build_response(self, spec)

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/model_components.py:165, in DistributionalComponent.build_response(self, pymc_backend, bmb_model)
    [163](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/model_components.py:163) # Create and build the response term
    [164](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/model_components.py:164) response_term = ResponseTerm(response_term, bmb_model.family)
--> [165](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/model_components.py:165) response_term.build(pymc_backend, bmb_model)

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:245, in ResponseTerm.build(self, pymc_backend, bmb_model)
    [241](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:241)     aliased_name = (
    [242](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:242)         bmb_component.alias if bmb_component.alias else bmb_component.response_name
    [243](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:243)     )
    [244](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:244)     linkinv = get_linkinv(self.family.link[name], pymc_backend.INVLINKS)
--> [245](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:245)     kwargs[name] = pm.Deterministic(aliased_name, linkinv(component.output), dims=dims)
    [247](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:247) # Add observed and dims
    [248](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py:248) kwargs["observed"] = data

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:2279, in Deterministic(name, var, model, dims)
   [2277](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:2277) var = var.copy(model.name_for(name))
   [2278](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:2278) model.deterministics.append(var)
-> [2279](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:2279) model.add_named_variable(var, dims)
   [2281](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:2281) from pymc.printing import str_for_potential_or_deterministic
   [2283](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:2283) var.str_repr = types.MethodType(
   [2284](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:2284)     functools.partial(str_for_potential_or_deterministic, dist_name="Deterministic"), var
   [2285](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:2285) )

File /opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:1537, in Model.add_named_variable(self, var, dims)
   [1535](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:1535)     # This check implicitly states that only vars with .ndim attribute can have dims
   [1536](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:1536)     if var.ndim != len(dims):
-> [1537](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:1537)         raise ValueError(
   [1538](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:1538)             f"{var} has {var.ndim} dims but {len(dims)} dim labels were provided."
   [1539](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:1539)         )
   [1540](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:1540)     self.named_vars_to_dims[var.name] = dims
   [1542](https://file+.vscode-resource.vscode-cdn.net/opt/anaconda3/envs/hssm/lib/python3.11/site-packages/pymc/model/core.py:1542) self.named_vars[var.name] = var

ValueError: z has 2 dims but 1 dim labels were provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream Related to upstream packages
Projects
None yet
Development

No branches or pull requests

4 participants