0

I have the following data set and I wanted to run a mixed effects linear model as below:

 Type    Season    Price     Sales
  A       Fall      34        500
  A       Winter    20        300
  B       Fall      15        100
  B       Winter    10        150

fm = model = smf.mixedlm("Sales ~ Price", df, groups = df[["Type","Season"]], 
                re_formula = "~Price")

However, I am getting the following error:

unhashable type: 'numpy.ndarray'

Could you please help me with this issue. This model can be easily done in R but I was not able to find a compatible example in python.

user36729
  • 545
  • 5
  • 30
  • It looks like the issue is with your `re_formula`. From the documentation (emphasis mine): "random_effects – A _dictionary_ mapping the distinct group values to the conditional means of the random effects for the group given the data." Because it was expecting a dict, and dict keys must be hashable, you can't pass in a column or ndarray – G. Anderson Mar 07 '19 at 18:59
  • It looks like there's a discussion on using this interface in [this question](https://stackoverflow.com/questions/47502398/python-statsmodels-mixedlm-mixed-linear-model-random-effects) – G. Anderson Mar 07 '19 at 18:59
  • Do you mean that I need to pass random effects like this: {"Type": "1", "Season": 1}? – user36729 Mar 07 '19 at 19:16
  • Unfortunately I've never used it myself, so I don;t know exactly how it needs to be entered, but you can try that and see if it prevents the error – G. Anderson Mar 07 '19 at 20:39

0 Answers0