Indicies Error using the GLS example

757 views
Skip to first unread message

C Kirby

unread,
Jul 29, 2014, 2:32:45 PM7/29/14
to pystat...@googlegroups.com
I am trying to generate a GLS following the example on http://statsmodels.sourceforge.net/stable/examples/generated/example_gls.html

The line
>>>resid_fit = sm.OLS(ols_resid[1:], sm.add_constant(ols_resid[:-1])).fit()

is causing a  ValueError("The indices for endog and exog are not aligned")
I did a quick check on ols_resid[1:] vs ols_resid[:-1] and the :-1 is one element shorter than the 1:

Any thoughts on how to get it to work?

Thanks

josef...@gmail.com

unread,
Jul 29, 2014, 2:41:31 PM7/29/14
to pystatsmodels
I guess you are using a pandas DataFrame as the data to OLS. In this
case several or most of the results are wrapped again in pandas
DataFrames or Series.

solution is to
either use the shift/lag features for pandas series to get the lagged residuals,
or to use the slicing as you have it with numpy ndarrays, e.g. with
old_resid.values

Another way that we use internally is to access the results without
wrapping which returns ndarrays. The unwrapped results instance is
available as `_results` attribute.

results = OLS(....).fit()
raw_results = results._results
raw_results.resid

Josef


>
> Thanks

C Kirby

unread,
Jul 29, 2014, 3:26:03 PM7/29/14
to pystat...@googlegroups.com
I used the unwrapped results _results. Looks like it worked perfectly. Thanks for the quick response.

Kirby
Reply all
Reply to author
Forward
0 new messages