lnccbrown / lnccbrown/HSSM

Specifying priors for categorical variables in regression does not work

Open
#387 12 comments 0 reactions 1 assignee View on GitHub

@digicosmos86 is already working on this.

Since May 8, 2024.

bug upstream
Dominant language
Python
Stars
124
Forks
24
Avg merge
19h 32m
Merged PRs (30d)
60

Description

**Describe the bug**

When running a (hierarchical) regression model and I try to specify priors for categorical variables I receive following error:
`TypeError: Wrong number of dimensions: expected 1, got 0 with shape ().` (full stack trace below). I only tried this for the `angle` model

**HSSM version**

0.2

**To Reproduce**
```
import hssm
from pandas import read_csv

data = read_csv('cavanagh_theta_nn.csv')
model = hssm.HSSM(data=data,
model='angle',
loglik='angle.onnx',
loglik_kind='approx_differentiable',
include=[
{
"name": "v",
"formula":"v ~ (1 | participant_id) + conf",
"prior": {
"Intercept": {"name": "Uniform", "lower": -1, "upper": 1, "initval":0},
"conf": {"name": "Normal", "mu": 0, "sigma": 1, "initval":0}
}
}
],
hierarchical=True,
link_settings='log_logit'
)
```

Full stack trace:
Traceback (most recent call last):
```
File "/gpfs/project/ort/lorasick/ddm/code/hssm_reg.py", line 50, in
model = hssm.HSSM(data=data,
^^^^^^^^^^^^^^^^^^^^
File "/gpfs/project/projects/bpsydm/tools/pyEnvs/hssm/lib/python3.11/site-packages/hssm/hssm.py", line 334, in __init__
self.set_alias(self._aliases)
File "/gpfs/project/projects/bpsydm/tools/pyEnvs/hssm/lib/python3.11/site-packages/hssm/hssm.py", line 594, in set_alias
self.model.build()
File "/gpfs/project/projects/bpsydm/tools/pyEnvs/hssm/lib/python3.11/site-packages/bambi/models.py", line 350, in build
self.backend.build(self)
File "/gpfs/project/projects/bpsydm/tools/pyEnvs/hssm/lib/python3.11/site-packages/bambi/backend/pymc.py", line 70, in build
self.components[name].build(self, spec)
File "/gpfs/project/projects/bpsydm/tools/pyEnvs/hssm/lib/python3.11/site-packages/bambi/backend/model_components.py", line 60, in build
self.build_common_terms(pymc_backend, bmb_model)
File "/gpfs/project/projects/bpsydm/tools/pyEnvs/hssm/lib/python3.11/site-packages/bambi/backend/model_components.py", line 98, in build_common_terms
coef, data = common_term.build(bmb_model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/gpfs/project/projects/bpsydm/tools/pyEnvs/hssm/lib/python3.11/site-packages/bambi/backend/terms.py", line 58, in build
coef = distribution(label, dims=dims, **args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/gpfs/project/projects/bpsydm/tools/pyEnvs/hssm/lib/python3.11/site-packages/pymc/distributions/distribution.py", line 316, in __new__
rv_out = model.register_rv(
^^^^^^^^^^^^^^^^^^
File "/gpfs/project/projects/bpsydm/tools/pyEnvs/hssm/lib/python3.11/site-packages/pymc/model/core.py", line 1294, in register_rv
self.set_initval(rv_var, initval)
File "/gpfs/project/projects/bpsydm/tools/pyEnvs/hssm/lib/python3.11/site-packages/pymc/model/core.py", line 1110, in set_initval
initval = rv_var.type.filter(initval)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/gpfs/project/projects/bpsydm/tools/pyEnvs/hssm/lib/python3.11/site-packages/pytensor/tensor/type.py", line 241, in filter
raise TypeError(
TypeError: Wrong number of dimensions: expected 1, got 0 with shape ().
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.