[Scipy-svn] r3947 - trunk/scipy/stats/models
scipy-svn at scipy.org
scipy-svn at scipy.org
Tue Feb 19 16:06:12 EST 2008
Author: jonathan.taylor
Date: 2008-02-19 15:06:08 -0600 (Tue, 19 Feb 2008)
New Revision: 3947
Modified:
trunk/scipy/stats/models/contrast.py
trunk/scipy/stats/models/utils.py
Log:
fixed a problem in specifying contrasts using "contrast matrices"
rank now correctly identifies rank 1 arrays
Modified: trunk/scipy/stats/models/contrast.py
===================================================================
--- trunk/scipy/stats/models/contrast.py 2008-02-16 20:13:15 UTC (rev 3946)
+++ trunk/scipy/stats/models/contrast.py 2008-02-19 21:06:08 UTC (rev 3947)
@@ -118,6 +118,9 @@
"""
+ T = N.asarray(T)
+ D = N.asarray(D)
+
n, p = D.shape
if T.shape[0] != n and T.shape[1] != p:
@@ -127,14 +130,18 @@
pseudo = pinv(D)
if T.shape[0] == n:
- C = N.transpose(N.dot(pseudo, T))
+ C = N.dot(pseudo, T).T
else:
C = T
+ C = N.dot(pseudo, N.dot(D, C.T)).T
+
+ Tp = N.dot(D, C.T)
- Tp = N.dot(D, N.transpose(C))
-
+ if len(Tp.shape) == 1:
+ Tp.shape = (n, 1)
+
if utils.rank(Tp) != Tp.shape[1]:
Tp = utils.fullrank(Tp)
- C = N.transpose(N.dot(pseudo, Tp))
+ C = N.dot(pseudo, Tp).T
return N.squeeze(C)
Modified: trunk/scipy/stats/models/utils.py
===================================================================
--- trunk/scipy/stats/models/utils.py 2008-02-16 20:13:15 UTC (rev 3946)
+++ trunk/scipy/stats/models/utils.py 2008-02-19 21:06:08 UTC (rev 3947)
@@ -50,8 +50,12 @@
Return the rank of a matrix X based on its generalized inverse,
not the SVD.
"""
- D = scipy.linalg.svdvals(X)
- return int(N.add.reduce(N.greater(D / D.max(), cond).astype(N.int32)))
+ X = N.asarray(X)
+ if len(X.shape) == 2:
+ D = scipy.linalg.svdvals(X)
+ return int(N.add.reduce(N.greater(D / D.max(), cond).astype(N.int32)))
+ else:
+ return int(not N.alltrue(N.equal(X, 0.)))
def fullrank(X, r=None):
"""
More information about the Scipy-svn
mailing list