Skip to content

Discussion: Dims usage on univariate regression is a bit confusing #5561

Closed
@canyon289

Description

@canyon289

Description of your problem

Using coords or dims in univariate situations necessitates the usage of indexing. This can be confusing as if I have a model that is specified without indexing, and then add dims/coords, an shape mismatch is caused. If the behavior can't be changed can a more useful exception be raised?

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

# Generate data and specify coords
df = pd.DataFrame(np.random.normal(size=(10,2)), columns=["x_1", "y"])

COORDS = {
    "slopes": ["x_1"]
}

Doesnt work


with pm.Model(coords=COORDS) as adelie_regression:

    β = pm.Normal("β", sigma=1000, dims=("slopes"))
    
    mu =  β * df["x_1"].values
    pm.Normal(
        "obs",
        mu=mu,
        sigma=1,
        observed=df["y"].values
    )
    idata_regression = pm.sample()

Works

with pm.Model(coords=COORDS) as adelie_regression:

    β = pm.Normal("β", sigma=1000, dims=("slopes"))
    
    mu =  β[0] * df["x_1"].values
    pm.Normal(
        "obs",
        mu=mu,
        sigma=1,
        observed=df["y"].values
    )
    idata_regression = pm.sample()

Also works

with pm.Model() as adelie_regression:

    β = pm.Normal("β", sigma=1000)
    
    mu =  β* df["x_1"].values
    pm.Normal(
        "obs",
        mu=mu,
        sigma=1,
        observed=df["y"].values
    )
    idata_regression = pm.sample()

Exception for first case

image

image

Versions and main components

  • PyMC/PyMC3 Version: Main at 620546b
  • Aesara/Theano Version:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions