[SciPy-user] boxcar problem
Stephen Walton
stephen.walton at csun.edu
Thu Dec 22 21:10:44 EST 2005
John Hunter wrote:
>Any ideas on this one?
>
>
>In [1]: import scipy
>
>In [2]: scipy.__version__
>Out[2]: '0.3.0_266.4239'
>
>In [3]: scipy.stats.boxcox(scipy.rand(100))
>---------------------------------------------------------------------------
>exceptions.ValueError Traceback (most
>recent call last)
>
>/home/titan/johnh/<console>
>
>/opt/lang/python-2.3.4/lib/python2.3/site-packages/scipy/stats/morestats.py
>in boxcox(x, lmbda, alpha)
> 279 return -boxcox_llf(lmb,data)
> 280 lmax = optimize.brent(tempfunc,
> brack=(-2.0,2.0),args=(x,))
>--> 281 y, lmax = boxcox(x, lmax)
> 282 if alpha is None:
> 283 return y, lmax
>
>ValueError: too many values to unpack
>
>
I'm practicing my Python debugging skills ;-) . It looks to me like the
problem is a few lines before:
if lmbda is not None: # single transformation
lmbda = lmbda*(x==x)
y = where(lmbda == 0, log(x), (x**lmbda - 1)/lmbda)
return y
So, what happens is that you call boxcox() with no lmbda value (so it
defaults to none), boxcox determines lmax, calls itself as
boxcox(y,lmax) but because of the code copied above the recursive call
only returns the value y. Hence there is no lmax value to unpack.
I think the fix is simple: change line 354 to
y = boxcox(x, lmax)
Steve
(I'm not sure why the offending line is listed as line 281 in John's
output; it is line 354 on my machine.)
More information about the SciPy-User
mailing list