" index must be integers" for Rugby model

Hi, I am trying to replicate Ruby Hierarchical model and get an error: “index must be integers”. I was following the example step by step, just with the newer data and not quite sure what is happening.

here model:

with pm.Model() as model:
     # global model parameters
     home = pm.Flat("home")
     sd_att = pm.HalfStudentT("sd_att", nu=3, sigma=2.5)
     sd_def = pm.HalfStudentT("sd_def", nu=3, sigma=2.5)
     intercept = pm.Flat("intercept")

# team-specific model parameters
atts_star = pm.Normal("atts_star", mu=0, sigma=sd_att, shape=num_teams)
defs_star = pm.Normal("defs_star", mu=0, sigma=sd_def, shape=num_teams)

atts = pm.Deterministic("atts", atts_star - tt.mean(atts_star))
defs = pm.Deterministic("defs", defs_star - tt.mean(defs_star))
home_theta = tt.exp(intercept + home + atts[home_team] + defs[away_team])
away_theta = tt.exp(intercept + atts[away_team] + defs[home_team])

# likelihood of observed data
home_points = pm.Poisson("home_points", mu=home_theta, observed=observed_home_goals)
away_points = pm.Poisson("away_points", mu=away_theta, observed=observed_away_goals)

and here is the error I’m getting:

1 Like

It looks like an issue with how the new data is loaded. Check that home_team and away_time have both integer dtype. You can make sure they are integers with home_team.astype(int)

Also, side note, the rugby example was updated recently but the docs have not been updated with that yet. You may want to also take a look at https://nbviewer.jupyter.org/github/pymc-devs/pymc-examples/blob/main/examples/case_studies/rugby_analytics.ipynb

Thank you for your reply and the updated version!!!

question: both home_team and away_team are objects. How can I convert them to int if technically they are strings?

1 Like

The newer version actually worked!!! thank you so much again!!!

1 Like