Problem with stimulus coding with HDDMRegression

392 views
Skip to first unread message

Dan Bang

unread,
Jan 26, 2016, 6:57:07 AM1/26/16
to hddm-users
I've followed the online tutorial, but I still can't get the code to run properly.

Here's the details for my study: 
- Subjects have to chose whether a grating is tilted Left or Right.
- Subjects receive a cue saying Left or Right. The cue is correct 75% of the time.

My data (attached) has the following columns: subj_idx, response [accuracy], rt, stimulus [1: left, 2: right], choice [1: left, 2: right] and condition [1: cue says left, 2: cue says right].

I can run everything smoothly, but when I try to set up the regression model, then I get the error: "After 7.000000 retries, still no good fit found." It prevents me from continuing to sampling from the model.

I attach the my script below [basically a copy from online tutorial], which should run straight out of box together with data file, as well as complete error description.

ANY HELP WOULD BE MUCH APPRECIATED!


SCRIPT

import hddm from patsy import dmatrix import pandas as pd import numpy as np import matplotlib.pyplot as plt mydata = hddm.load_csv('dan_data.csv') def z_link_func(x, data=mydata): stim = (np.asarray(dmatrix('0 + C(s, [[1], [-1]])', {'s': data.stimulus.ix[x.index]}))) return 1 / (1 + np.exp(-(x * stim))) z_reg = {'model': 'z ~ 1 + C(condition)', 'link_func': z_link_func} reg_descr = [z_reg] m_reg = hddm.HDDMRegressor(mydata, reg_descr, include='z')

ERROR

Adding these covariates:
['z_Intercept', 'z_C(condition)[T.2]']
After 7.000000 retries, still no good fit found.
---------------------------------------------------------------------------
ZeroProbability                           Traceback (most recent call last)
<ipython-input-46-fb5a198a7982> in <module>()
----> 1 m_reg = hddm.HDDMRegressor(mydata, reg_descr, include='z')

//anaconda/lib/python3.5/site-packages/hddm/models/hddm_regression.py in __init__(self, data, models, group_only_regressors, keep_regressor_trace, **kwargs)
    201         self.wfpt_reg_class = deepcopy(wfpt_reg_like)
    202 
--> 203         super(HDDMRegressor, self).__init__(data, **kwargs)
    204 
    205         # Sanity checks

//anaconda/lib/python3.5/site-packages/hddm/models/hddm_info.py in __init__(self, *args, **kwargs)
    111         self.is_informative = kwargs.pop('informative', True)
    112 
--> 113         super(HDDM, self).__init__(*args, **kwargs)
    114 
    115     def _create_stochastic_knodes(self, include):

//anaconda/lib/python3.5/site-packages/hddm/models/base.py in __init__(self, data, bias, include, wiener_params, p_outlier, **kwargs)
    687         self.wfpt_class = hddm.likelihoods.generate_wfpt_stochastic_class(wp, cdf_range=self.cdf_range)
    688 
--> 689         super(HDDMBase, self).__init__(data, **kwargs)
    690 
    691     def __getstate__(self):

//anaconda/lib/python3.5/site-packages/hddm/models/base.py in __init__(self, data, **kwargs)
     38         self.std_depends = kwargs.pop('std_depends', False)
     39 
---> 40         super(AccumulatorModel, self).__init__(data, **kwargs)
     41 
     42 

//anaconda/lib/python3.5/site-packages/kabuki/hierarchical.py in __init__(self, data, is_group_model, depends_on, trace_subjs, plot_subjs, plot_var, group_only_nodes)
    346         self.db = None
    347 
--> 348         self._setup_model()
    349 
    350     def _setup_model(self):

//anaconda/lib/python3.5/site-packages/kabuki/hierarchical.py in _setup_model(self)
    357 
    358         # constructs pymc nodes etc and connects them appropriately
--> 359         self.create_model()
    360 
    361     def __getstate__(self):

//anaconda/lib/python3.5/site-packages/kabuki/hierarchical.py in create_model(self, max_retries)
    437         else:
    438             print("After %f retries, still no good fit found." %(tries))
--> 439             _create()
    440 
    441         # create node container

//anaconda/lib/python3.5/site-packages/kabuki/hierarchical.py in _create()
    427         def _create():
    428             for knode in self.knodes:
--> 429                 knode.create()
    430 
    431         for tries in range(max_retries):

//anaconda/lib/python3.5/site-packages/kabuki/hierarchical.py in create(self)
    166                 kwargs['doc'] = node_name
    167 
--> 168             node = self.create_node(node_name, kwargs, grouped_data)
    169 
    170             if node is not None:

//anaconda/lib/python3.5/site-packages/kabuki/hierarchical.py in create_node(self, node_name, kwargs, data)
    174     def create_node(self, node_name, kwargs, data):
    175         #actually create the node
--> 176         return self.pymc_node(name=node_name, **kwargs)
    177 
    178     def create_tag_and_subj_idx(self, cols, uniq_elem):

//anaconda/lib/python3.5/site-packages/pymc/distributions.py in __init__(self, *args, **kwds)
    318                     logp_partial_gradients=logp_partial_gradients,
    319                     dtype=dtype,
--> 320                     **arg_dict_out)
    321 
    322     new_class.__name__ = name

//anaconda/lib/python3.5/site-packages/pymc/PyMCObjects.py in __init__(self, logp, doc, name, parents, random, trace, value, dtype, rseed, observed, cache_depth, plot, verbose, isdata, check_logp, logp_partial_gradients)
    773         if check_logp:
    774             # Check initial value
--> 775             if not isinstance(self.logp, float):
    776                 raise ValueError(
    777                     "Stochastic " +

//anaconda/lib/python3.5/site-packages/pymc/PyMCObjects.py in get_logp(self)
    930                     (self._value, self._parents.value))
    931             else:
--> 932                 raise ZeroProbability(self.errmsg)
    933 
    934         return logp

ZeroProbability: Stochastic wfpt.3's value is outside its support,
 or it forbids its parents' current values.

Thomas Wiecki

unread,
Jan 26, 2016, 7:05:36 AM1/26/16
to hddm-...@googlegroups.com
Usually the cause are outliers, either in your RTs (either remove or set p_outlier=0.05) or in our regressor. Specifically, take a look at the data from subject 3.

--
You received this message because you are subscribed to the Google Groups "hddm-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hddm-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Bang

unread,
Jan 26, 2016, 7:47:29 AM1/26/16
to hddm-users
Thanks, Thomas! Yes, that seemed to be problem. I had to cut both ends of RT distribution -- but now it seems to work!
Reply all
Reply to author
Forward
0 new messages