Seemingly unrelated regression

80 views
Skip to first unread message

Anand Govindarajan

unread,
Aug 19, 2017, 11:50:28 PM8/19/17
to pystatsmodels
Hello,

I am trying to use statsmodels package to develop a seemingly unrelated regression model. 

A simple overview of the model - There are 14 equations with 1 endogenous and 2 exogenous variables ( A ~ B + C). 

As explained in here (http://www.statsmodels.org/dev/generated/statsmodels.sandbox.sysreg.SUR.html), I develop a list of the size (2*14).  The items in the list alternate between
endogenous and exogenous variables. Below is the code. 

There are 14 zones which represent the 14 equations. data is the dataframe with data for all 14 equations/zones. y_vars, x1_vars and x2_vars are lists of the column names which represent the endog and exog variables.  

        sur_list=[]
        sur_array=np.empty(shape=(len(data),3))
        
        for z,zone in enumerate(zones):
            
            sur_array[:,0]=data[y_vars[z]]
            sur_array[:,1]=data[x2_vars[z]]
            sur_array[:,2]=data[x1_vars[z]]
            
            sur_list+=[sur_array[:,0].astype(int)]
            sur_list+=[sur_array[:,1:3].astype(int)]


        sur_mod = SUR(sur_list)
        sur_res = sur_mod.fit()

I'm getting the following error. 

  File "<ipython-input-22-ae788a9d656c>", line 31, in <module>
    sur_mod = SUR(sur_list)

  File "C:\Users\Anand Govindarajan\Anaconda3\lib\site-packages\statsmodels\sandbox\sysreg.py", line 129, in __init__
    self._cols[i]:self._cols[i+1]] = sys[1::2][i]

  File "C:\Users\Anand Govindarajan\Anaconda3\lib\site-packages\scipy\sparse\lil.py", line 363, in __setitem__
    i, j = self._index_to_arrays(i, j)

  File "C:\Users\Anand Govindarajan\Anaconda3\lib\site-packages\scipy\sparse\sputils.py", line 356, in _index_to_arrays
    i = self._slicetoarange(i, self.shape[0])[:, None]

  File "C:\Users\Anand Govindarajan\Anaconda3\lib\site-packages\scipy\sparse\sputils.py", line 262, in _slicetoarange
    start, stop, step = j.indices(shape)

TypeError: slice indices must be integers or None or have an __index__ method


Any help will be appreciated. There is not much documentation on SUR estimation in Python. Please let me know if you need more information. Thanks

josef...@gmail.com

unread,
Aug 20, 2017, 10:28:25 AM8/20/17
to pystatsmodels
bitrot

This is a prototype function that hasn't been maintained, there are no unit tests to alert to compatibility/refactoring errors.
Specifically, I think the class uses float as indices which are not allowed anymore by numpy, and consequently by scipy.
(i.e. an astype(int) needs to be added to the slice indices.)

I guess Kevin's linearmodel package provides a more complete, and better maintained SUR class (at least for now)

Josef



Reply all
Reply to author
Forward
0 new messages