pymc2 icon indicating copy to clipboard operation
pymc2 copied to clipboard

BUG: AttributeError: module 'pymc' has no attribute 'diagnostics'

Open moxtoby opened this issue 1 year ago • 5 comments

Describe the issue:

I have been running Gelman Rubin convergence tests after running the HDDM function. and they were working fine up until 13th October 2023. I have in the last week tried to run the same script again in Jupyter Notebook (from Anaconda) and after the HDDM iterations are complete, the Gelman Rubin test fails, citing the reason as "AttributeError: module 'pymc' has not attribute 'diagnostics'. I have not changed the code or the python environment. I have however updated the Anaconda software version recently, but not sure if this would have had an effect. I have tried to rebuild the python environment multiple times, and compared the packages list/versions, but I can't see anything has changed. The reason I am using an older version of Python and pymc is because they are compatible with HDDM 0.8.0. I have attached the conda list to show the packages and versions in the python environment.

hddm conda list.docx

Reproduceable code example:

from patsy import dmatrix 
import numpy as np         
from pandas import Series 
import matplotlib.pyplot as plt
import pymc as pm
#import arviz as az
import hddm

mydata = hddm.load_csv('JLM_stroopdata.csv')

models = []
for i in range(3):
    StroopModel1=hddm.HDDMRegressor(mydata,"v~C(cond,Treatment('Con'))",group_only_regressors=False,p_outlier=.05)
    StroopModel1.find_starting_values()
    StroopModel1.sample(2000, burn=200)
    models.append(StroopModel1)
from kabuki.analyze import gelman_rubin
gelman_rubin(models)

Error message:

Adding these covariates:
['v_Intercept', "v_C(cond, Treatment('Con'))[T.Inc]"]

C:\Users\m_oxt\anaconda3_newnew\envs\hddm2\lib\site-packages\scipy\optimize\optimize.py:2116: RuntimeWarning: invalid value encountered in double_scalars
  tmp2 = (x - v) * (fx - fw)

 [-----------------100%-----------------] 2000 of 2000 complete in 114.3 secAdding these covariates:
['v_Intercept', "v_C(cond, Treatment('Con'))[T.Inc]"]

C:\Users\m_oxt\anaconda3_newnew\envs\hddm2\lib\site-packages\scipy\optimize\optimize.py:2116: RuntimeWarning: invalid value encountered in double_scalars
  tmp2 = (x - v) * (fx - fw)

 [-----------------100%-----------------] 2000 of 2000 complete in 115.4 secAdding these covariates:
['v_Intercept', "v_C(cond, Treatment('Con'))[T.Inc]"]

C:\Users\m_oxt\anaconda3_newnew\envs\hddm2\lib\site-packages\scipy\optimize\optimize.py:2116: RuntimeWarning: invalid value encountered in double_scalars
  tmp2 = (x - v) * (fx - fw)

 [-----------------100%-----------------] 2000 of 2000 complete in 116.7 sec

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-ca3fd1f2572c> in <module>
      6     models.append(StroopModel1)
      7 from kabuki.analyze import gelman_rubin
----> 8 gelman_rubin(models)

~\anaconda3_newnew\envs\hddm2\lib\site-packages\kabuki\analyze.py in gelman_rubin(models)
    154             samples[i, :] = model.nodes_db.loc[name, "node"].trace()
    155 
--> 156         R_hat_dict[name] = pm.diagnostics.gelman_rubin(samples)
    157 
    158     return R_hat_dict

AttributeError: module 'pymc' has no attribute 'diagnostics'

PyMC version information:

I have attached the conda list below. hddm conda list.docx

Context for the issue:

I am using HDDM to estimate parameters for three tasks (Stroop, Go/NoGo and Stop Signal tasks), and needs to use the Gelman-Rubin convergence test to ensure the parameter estimation iterations converge. As the Gelman-Rubin test was working up until mid-October, I am relying on it to ensure my experiment analysis can be completed. I do not know of any other way to do the Gelman-Rubin test without using the pymc package. Any ideas why this error occurs now (and not before), and what I can do to work around it? Thank you.

moxtoby avatar Nov 21 '23 17:11 moxtoby