# Multiple predictors, multiple dimensions? Help with model specification?

**URL:** <https://discourse.pymc.io/t/multiple-predictors-multiple-dimensions-help-with-model-specification/10554>\
**Category:** v5\
**Tags:** modeling, prediction\
**Created:** [October 7, 2022, 3:35pm UTC](https://discourse.pymc.io/t/multiple-predictors-multiple-dimensions-help-with-model-specification/10554 "2022-10-07T15:35:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![whatsbehindthisdoor](https://avatars.discourse-cdn.com/v4/letter/w/9d8465/32.png) [@whatsbehindthisdoor](https://discourse.pymc.io/u/whatsbehindthisdoor)\
**Post date:** [October 7, 2022, 3:35pm UTC](https://discourse.pymc.io/t/multiple-predictors-multiple-dimensions-help-with-model-specification/10554/1 "2022-10-07T15:35:54Z")

</div>

Thank you in advance for reading my post; I’m very much a beginner and a bit lost.

My ultimate goal is to predict the “number of fails” for a given player and game difficulty.  
Currently, my model has no predictors, so there is nothing for me to adjust within **pm.set\_data()**.

_I think_ the heart of my issue is that I’m not sure how to specify a model with multiple predictors _and_ multiple dimensions.

This is representative of my data and coordinates:

```auto
# import libraries
import numpy as np
import pandas as pd
import pymc as pm
import arviz as az

RANDOM_SEED = 100
np.random.seed(RANDOM_SEED)
az.style.use("arviz-darkgrid")

# define data
player_list = ['Player1', 'Player1', 'Player1', 'Player1', 'Player2', 'Player2', 'Player2', 'Player2']
difficulty_list = ['Easy', 'Easy', 'Hard', 'Hard', 'Easy', 'Easy', 'Hard', 'Hard']
fails = [3, 2, 4, 4, 4, 4, 5, 4]

df = pd.DataFrame({'Players': player_list, 'Difficulty': difficulty_list, 'Fails': fails})

# create coordinates
player_factor, player_names = pd.factorize(df['Players'], sort=True)
diff_factor, diff_categ = pd.factorize(df['Difficulty'], sort=True)

coords = {
    "obs": df.index.values,  
    "player_names": player_names,
    "diff_categ": diff_categ
}

```

My current model uses a **player** dimension and a **difficulty** dimension:

```auto
with pm.Model(coords=coords) as m1:
    
    # using pm.data
    y = pm.MutableData("y", df['Fails'].to_numpy(), dims="obs")
    
    # Names
    NamesΘα = pm.Gamma("NamesΘα", alpha=3, beta=3, dims="player_names")
    NamesΘβ = pm.Gamma("NamesΘβ", alpha=3, beta=3, dims="player_names")
    
    # Difficulty
    DiffΘα = pm.Gamma("DiffΘα", alpha=3, beta=3, dims="diff_categ")
    DiffΘβ = pm.Gamma("DiffΘβ", alpha=3, beta=3, dims="diff_categ")
    
    # likelihood
    Fails = pm.BetaBinomial(
        "Fails", 
        n=6, 
        alpha=NamesΘα[player_factor] + DiffΘα[diff_factor], 
        beta=NamesΘβ[player_factor] + DiffΘβ[diff_factor], 
        observed=y,
        dims="obs"
    )

```

I tried changing the likelihood to include specific predictors for **player name** , **difficulty** , but it throws an error about shapes (“Input dimension mismatch. One other input has shape[0] = 2, but input[1].shape[0] = 8.”):

```auto
with pm.Model(coords=coords) as m2:
    
    # using pm.data
    x1 = pm.MutableData("x1", player_factor, dims="player_names")
    x2 = pm.MutableData("x2", diff_factor, dims="diff_categ")
    y = pm.MutableData("y", df['Fails'].to_numpy(), dims="obs")
    
    # Names
    NamesΘα = pm.Gamma("NamesΘα", alpha=3, beta=3, dims="player_names")
    NamesΘβ = pm.Gamma("NamesΘβ", alpha=3, beta=3, dims="player_names")
    
    # Difficulty
    DiffΘα = pm.Gamma("DiffΘα", alpha=3, beta=3, dims="diff_categ")
    DiffΘβ = pm.Gamma("DiffΘβ", alpha=3, beta=3, dims="diff_categ")
    
    # likelihood
    Fails = pm.BetaBinomial(
        "Fails", 
        n=6, 
        alpha=NamesΘα * x1 + DiffΘα * x2, 
        beta=NamesΘβ * x1 + DiffΘβ * x2, 
        observed=y,
        dims="obs"
    )

```

To summarize:

1. I want to generate predictions ( either of ‘Fails’ or probability of ‘Fails’ taking a specific value )
2. To accomplish (1), my model requires predictors
3. Not sure how to accomplish (2) and still specify different dimensions for my priors.

Any help/crictism is welcome!
