OLS fails with 1 exogenous variable

Bug #618283 reported by Chang She
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
statsmodels
Invalid
Undecided
Unassigned

Bug Description

In [1]: import numpy as np

In [2]: import numpy.random as rand

In [3]: x, y = rand.normal(0.5, 1.3, 1200), rand.normal(1.3, 2.5, 1200)

In [4]: from scikits.statsmodels.regression import OLS

In [5]: OLS(y, x).fit()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)

H:\Workspace\Python\src\<ipython console> in <module>()

Q:\GAARD\Prod\Apps\PythonRuntime\1.9\lib\site-packages\scikits.statsmodels-0.1.0b1-py2.5
\statsmodels\regression.pyc in fit(self)
    226 #TODO: add a full_output keyword so that only light results needed for
    227 # IRLS are calculated?
--> 228 beta = np.dot(self.pinv_wexog, self.wendog)
    229 # should this use lstsq instead?
    230 # worth a comparison at least...though this is readable

ValueError: matrices are not aligned

In [6]: %debug
> q:\gaard\prod\apps\pythonruntime\1.6\lib\site-packages\scikits.statsmodels-0.1.0b1-py2.5.egg\scikits\statsmodels\regression.py(228)fit()
    227 # IRLS are calculated?
--> 228 beta = np.dot(self.pinv_wexog, self.wendog)
    229 # should this use lstsq instead?

ipdb> self.pinv_wexog.shape
(1200, 1)
ipdb> self.wendog.shape
(1200,)
ipdb>

Revision history for this message
Chang She (changshe) wrote :

nevermind

I missed the part in the notes where it assumes the design matrix contains a constant :)

Changed in statsmodels:
status: New → Invalid
Revision history for this message
Skipper Seabold (jsseabold) wrote :

What version are you using? The code you write should still work in the most recent release.

The assumption about the constant is only for post-estimation statistics.

Revision history for this message
Chang She (changshe) wrote : Re: [Bug 618283] Re: OLS fails with 1 exogenous variable

Good point. It looks like I'm on 0.1.0b1.

On Sun, Aug 15, 2010 at 1:36 PM, Skipper Seabold <email address hidden>wrote:

> What version are you using? The code you write should still work in the
> most recent release.
>
> The assumption about the constant is only for post-estimation
> statistics.
>
> --
> OLS fails with 1 exogenous variable
> https://bugs.launchpad.net/bugs/618283
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in scikits.statsmodels: Invalid
>
> Bug description:
> In [1]: import numpy as np
>
> In [2]: import numpy.random as rand
>
> In [3]: x, y = rand.normal(0.5, 1.3, 1200), rand.normal(1.3, 2.5, 1200)
>
> In [4]: from scikits.statsmodels.regression import OLS
>
> In [5]: OLS(y, x).fit()
> ---------------------------------------------------------------------------
> ValueError Traceback (most recent call last)
>
> H:\Workspace\Python\src\<ipython console> in <module>()
>
>
> Q:\GAARD\Prod\Apps\PythonRuntime\1.9\lib\site-packages\scikits.statsmodels-0.1.0b1-py2.5
> \statsmodels\regression.pyc in fit(self)
> 226 #TODO: add a full_output keyword so that only light results needed
> for
> 227 # IRLS are calculated?
> --> 228 beta = np.dot(self.pinv_wexog, self.wendog)
> 229 # should this use lstsq instead?
> 230 # worth a comparison at least...though this is readable
>
> ValueError: matrices are not aligned
>
> In [6]: %debug
> >
> q:\gaard\prod\apps\pythonruntime\1.6\lib\site-packages\scikits.statsmodels-0.1.0b1-py2.5.egg\scikits\statsmodels\regression.py(228)fit()
> 227 # IRLS are calculated?
> --> 228 beta = np.dot(self.pinv_wexog, self.wendog)
> 229 # should this use lstsq instead?
>
> ipdb> self.pinv_wexog.shape
> (1200, 1)
> ipdb> self.wendog.shape
> (1200,)
> ipdb>
>
> To unsubscribe from this bug, go to:
> https://bugs.launchpad.net/statsmodels/+bug/618283/+subscribe
>

Revision history for this message
Chang She (changshe) wrote : RE: 618283

hi 618283 i feel like this is my calling you know you have what it takes http://t.co/q5VyCXjh

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.