Re: [pystatsmodels] 'keyword can't be an expression' for GLM specification

24 views
Skip to first unread message

josef...@gmail.com

unread,
Apr 28, 2013, 5:53:45 PM4/28/13
to pystatsmodels


On Sun, Apr 28, 2013 at 5:46 PM, Brian Keegan <bke...@gmail.com> wrote:
Total noob to statsmodels (using fresh install of 0.5.0, patsy 0.1.0, pandas 0.9, python 2.7.3) here. I'm trying to follow the documentation for GLMs (http://statsmodels.sourceforge.net/devel/examples/generated/example_glm.html) to estimate some version of a binomial model and getting a cryptic error message: "keyword can't be an expression". The input is a 1239-row, 11-column pandas dataframe from which I'm specifying the model below. A normal OLS estimates correctly, but any GLM family I specify doesn't estimate. Any help would be appreciated! Thanks


In [100]:
df_paper_coauthorship = pd.DataFrame(data=d.values(),index=d.keys(),columns=d.values()[0].keys())
df_paper_coauthorship.head(1).T
Out[100]:
192858
degree 30
downloads 948
authors 3
closeness 0.245614
node_type paper
year 1994
clustering 1
name Life and death of new technology: task, utilit...
betweenness 0
citations 13
publications -1

In [122]:
y1,X1 = dmatrices('downloads ~ authors + year + degree',data=df_paper_coauthorship,return_type='dataframe')
In [120]:
X1.head()
Out[120]:
Interceptauthors yeardegree
192858 1 31994 30
192878 11 19942
2441981 1 42013 11
1180956 12 200612
1180955 1 12006 7
In [119]:
y1.head()
Out[119]:
downloads
192858 948
192878 1483
2441981 45
1180956 1765
1180955 653
In [121]:
mod1 = sm.GLM(y1,X1.family=sm.families.Binomial())
res1 = mod1.fit()
pprint(res1.summary())
  File "<ipython-input-121-0b7ad9bf1600>", line 1
SyntaxError: keyword can't be an expression

 

Hi,
Can you post the full traceback?  Or is that all?
 
can you try regular print instead of pprint?
 
Josef

Wes McKinney

unread,
Apr 29, 2013, 5:37:11 PM4/29/13
to pystat...@googlegroups.com
Hi Brian,

you have a typo in the line:


mod1 = sm.GLM(y1,X1.family=sm.families.Binomial())

it should be

mod1 = sm.GLM(y1,X1, family=sm.families.Binomial())

N.B.
In [1]: def f(a, b=None):
   ...:     pass
   ...: 

In [2]: f(a, x.y=2)
  File "<ipython-input-2-124d23405480>", line 1
    f(a, x.y=2)
SyntaxError: keyword can't be an expression

Reply all
Reply to author
Forward
0 new messages