[Scipy-svn] r3393 - in trunk/scipy/stats/models: . family tests

scipy-svn@scip... scipy-svn@scip...
Wed Oct 3 01:19:20 CDT 2007


Author: jarrod.millman
Date: 2007-10-03 01:19:08 -0500 (Wed, 03 Oct 2007)
New Revision: 3393

Modified:
   trunk/scipy/stats/models/__init__.py
   trunk/scipy/stats/models/cox.py
   trunk/scipy/stats/models/family/links.py
   trunk/scipy/stats/models/formula.py
   trunk/scipy/stats/models/gam.py
   trunk/scipy/stats/models/glm.py
   trunk/scipy/stats/models/info.py
   trunk/scipy/stats/models/model.py
   trunk/scipy/stats/models/regression.py
   trunk/scipy/stats/models/rlm.py
   trunk/scipy/stats/models/smoothers.py
   trunk/scipy/stats/models/survival.py
   trunk/scipy/stats/models/tests/test_bspline.py
   trunk/scipy/stats/models/tests/test_formula.py
   trunk/scipy/stats/models/tests/test_glm.py
   trunk/scipy/stats/models/tests/test_regression.py
Log:
updating statistical models to use CapWords for class names


Modified: trunk/scipy/stats/models/__init__.py
===================================================================
--- trunk/scipy/stats/models/__init__.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/__init__.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -11,8 +11,8 @@
 import scipy.stats.models.regression
 import scipy.stats.models.robust
 import scipy.stats.models.family
-from scipy.stats.models.glm import model as glm
-from scipy.stats.models.rlm import model as rlm
+from scipy.stats.models.glm import Model as glm
+from scipy.stats.models.rlm import Model as rlm
 
 __all__ = filter(lambda s:not s.startswith('_'),dir())
 

Modified: trunk/scipy/stats/models/cox.py
===================================================================
--- trunk/scipy/stats/models/cox.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/cox.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -5,7 +5,7 @@
 
 from scipy.stats.models import survival, model
 
-class discrete:
+class Discrete:
 
     """
     A simple little class for working with discrete random vectors.
@@ -37,7 +37,7 @@
         dx = self.x - N.multiply.outer(mu, self.x.shape[1])
         return N.dot(dx, N.transpose(dx))
 
-class observation(survival.right_censored):
+class Observation(survival.RightCensored):
 
     def __getitem__(self, item):
         if self.namespace is not None:
@@ -47,12 +47,13 @@
 
     def __init__(self, time, delta, namespace=None):
         self.namespace = namespace
-        survival.right_censored.__init__(self, time, delta)
+        survival.RightCensored.__init__(self, time, delta)
 
     def __call__(self, formula, time=None, **extra):
         return formula(namespace=self, time=time, **extra)
 
-class coxph(model.likelihood_model):
+class CoxPH(model.LikelihoodModel):
+    """Cox proportional hazards regression model."""
 
     def __init__(self, subjects, formula, time_dependent=False):
         self.subjects, self.formula = subjects, formula

Modified: trunk/scipy/stats/models/family/links.py
===================================================================
--- trunk/scipy/stats/models/family/links.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/family/links.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -134,7 +134,7 @@
         g(x) = x**(1/self.power)
 
         INPUTS:
-           z   -- linear predictors in glm
+           z   -- linear predictors in GLM
 
         OUTPUTS: x
            x   -- mean parameters
@@ -227,7 +227,7 @@
         g(x) = exp(x)
 
         INPUTS:
-           z   -- linear predictors in glm
+           z   -- linear predictors in GLM
 
         OUTPUTS: x
            x   -- exp(z)
@@ -289,7 +289,7 @@
         g(z) = self.dbn.cdf(z)
 
         INPUTS:
-           z   -- linear predictors in glm
+           z   -- linear predictors in GLM
 
         OUTPUTS: p
            p   -- inverse of CDF link of z

Modified: trunk/scipy/stats/models/formula.py
===================================================================
--- trunk/scipy/stats/models/formula.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/formula.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -9,7 +9,7 @@
 
 default_namespace = {}
 
-class term(object):
+class Term(object):
     """
     This class is very simple: it is just a named term in a model formula.
 
@@ -35,7 +35,7 @@
         else:
             name = '%s^%0.2f' % (self.name, power)
 
-        value = quantitative(name, func=self, transform=lambda x: N.power(x, power))
+        value = Quantitative(name, func=self, transform=lambda x: N.power(x, power))
         value.power = power
         value.namespace = self.namespace
         return value
@@ -73,24 +73,24 @@
 
     def __add__(self, other):
         """
-        formula(self) + formula(other)
+        Formula(self) + Formula(other)
         """
-        other = formula(other, namespace=self.namespace)
+        other = Formula(other, namespace=self.namespace)
         f = other + self
         f.namespace = self.namespace
         return f
 
     def __mul__(self, other):
         """
-        formula(self) * formula(other)
+        Formula(self) * Formula(other)
         """
 
         if other.name is 'intercept':
-            f = formula(self, namespace=self.namespace)
+            f = Formula(self, namespace=self.namespace)
         elif self.name is 'intercept':
-            f = formula(other, namespace=other.namespace)
+            f = Formula(other, namespace=other.namespace)
         else:
-            other = formula(other, namespace=self.namespace)
+            other = Formula(other, namespace=self.namespace)
             f = other * self
         f.namespace = self.namespace
         return f
@@ -126,14 +126,9 @@
         val = N.asarray(val)
         return N.squeeze(val)
 
-class factor(term):
+class Factor(Term):
+    """A categorical factor."""
 
-    """
-    A categorical factor.
-    """
-
-
-
     def __init__(self, termname, keys, ordinal=False):
         """
         factor is initialized with keys, representing all valid
@@ -151,7 +146,7 @@
         else:
             name = ['(%s==%s)' % (self.termname, str(key)) for key in self.keys]
 
-        term.__init__(self, name, termname=self.termname, func=self.get_columns)
+        Term.__init__(self, name, termname=self.termname, func=self.get_columns)
 
     def get_columns(self, *args, **kw):
         """
@@ -199,18 +194,18 @@
 
     def __add__(self, other):
         """
-        formula(self) + formula(other)
+        Formula(self) + Formula(other)
 
         When adding \'intercept\' to a factor, this just returns 
 
-        formula(self, namespace=self.namespace)
+        Formula(self, namespace=self.namespace)
 
         """
         
         if other.name is 'intercept':
-            return formula(self, namespace=self.namespace)
+            return Formula(self, namespace=self.namespace)
         else:
-            return term.__add__(self, other)
+            return Term.__add__(self, other)
 
     def main_effect(self, reference=None):
         """
@@ -235,13 +230,13 @@
         keep.pop(reference)
         __names = self.names()
         _names = ['%s-%s' % (__names[keep[i]], __names[reference]) for i in range(len(keep))]
-        value = quantitative(_names, func=self, 
+        value = Quantitative(_names, func=self, 
                      termname='%s:maineffect' % self.termname,
                      transform=maineffect_func)
         value.namespace = self.namespace
         return value
 
-class quantitative(term):
+class Quantitative(Term):
     """
     A subclass of term that can be used to apply point transformations
     of another term, i.e. to take powers:
@@ -249,29 +244,31 @@
     >>> import numpy as N
     >>> from scipy.stats.models import formula
     >>> X = N.linspace(0,10,101)
-    >>> x = formula.term('X')
+    >>> x = formula.Term('X')
     >>> x.namespace={'X':X}
     >>> x2 = x**2
     >>> print N.allclose(x()**2, x2())
     True
-    >>> x3 = formula.quantitative('x2', func=x, transform=lambda x: x**2)
+    >>> x3 = formula.Quantitative('x2', func=x, transform=lambda x: x**2)
     >>> x3.namespace = x.namespace
     >>> print N.allclose(x()**2, x3())
     True
+
     """
 
     def __init__(self, name, func=None, termname=None, transform=lambda x: x):
         self.transform = transform
-        term.__init__(self, name, func=func, termname=termname)
+        Term.__init__(self, name, func=func, termname=termname)
 
     def __call__(self, *args, **kw):
         """
         A quantitative is just like term, except there is an additional
         transformation: self.transform.
+
         """
-        return self.transform(term.__call__(self, *args, **kw))
+        return self.transform(Term.__call__(self, *args, **kw))
 
-class formula(object):
+class Formula(object):
     """
     A formula object for manipulating design matrices in regression models,
     essentially consisting of a list of term instances.
@@ -279,6 +276,7 @@
     The object supports addition and multiplication which correspond
     to concatenation and pairwise multiplication, respectively,
     of the columns of the two formulas.
+
     """
     
     def _get_namespace(self): 
@@ -304,11 +302,11 @@
 
 
         self.__namespace = namespace
-        if isinstance(termlist, formula):
+        if isinstance(termlist, Formula):
             self.terms = copy.copy(list(termlist.terms))
         elif type(termlist) is types.ListType:
             self.terms = termlist
-        elif isinstance(termlist, term):
+        elif isinstance(termlist, Term):
             self.terms = [termlist]
         else: 
             raise ValueError
@@ -388,11 +386,11 @@
         Determine whether a given term is in a formula.
         """
 
-        if not isinstance(query_term, formula):
+        if not isinstance(query_term, Formula):
             if type(query_term) == type("name"):
                 try: query = self[query_term]
                 except: return False
-            elif isinstance(query_term, term):
+            elif isinstance(query_term, Term):
                 return query_term.termname in self.termnames()
         elif len(query_term.terms) == 1:
             query_term = query_term.terms[0]
@@ -462,7 +460,7 @@
         TO DO: check for nesting relationship. Should not be too difficult.
         """
 
-        other = formula(other, namespace=self.namespace)
+        other = Formula(other, namespace=self.namespace)
 
         selftermnames = self.termnames()
         othertermnames = other.termnames()
@@ -517,14 +515,14 @@
                     sumterms.terms = [self, other] # enforce the order we want
                     sumterms.namespace = self.namespace
 
-                    _term = quantitative(names, func=sumterms, termname=termname,
+                    _term = Quantitative(names, func=sumterms, termname=termname,
                                          transform=product_func)
                     _term.namespace = self.namespace
 
 
                 terms.append(_term)
 
-        return formula(terms, namespace=self.namespace)
+        return Formula(terms, namespace=self.namespace)
     
     def __add__(self, other):
 
@@ -535,12 +533,12 @@
         terms in the formula are sorted alphabetically.
         """
 
-        other = formula(other, namespace=self.namespace)
+        other = Formula(other, namespace=self.namespace)
         terms = self.terms + other.terms
         pieces = [(term.name, term) for term in terms]
         pieces.sort()
         terms = [piece[1] for piece in pieces]
-        return formula(terms, namespace=self.namespace)
+        return Formula(terms, namespace=self.namespace)
 
     def __sub__(self, other):
 
@@ -550,7 +548,7 @@
         function does not raise an exception.
         """
 
-        other = formula(other, namespace=self.namespace)
+        other = Formula(other, namespace=self.namespace)
         terms = copy.copy(self.terms)
 
         for term in other.terms:
@@ -558,7 +556,7 @@
                 if terms[i].termname == term.termname:
                     terms.pop(i)
                     break 
-        return formula(terms, namespace=self.namespace)
+        return Formula(terms, namespace=self.namespace)
 
 def isnested(A, B, namespace=globals()):
     """
@@ -594,18 +592,19 @@
 
 def _intercept_fn(nrow=1, **extra):
     return N.ones((1,nrow))
-I = term('intercept', func=_intercept_fn)
+
+I = Term('intercept', func=_intercept_fn)
 I.__doc__ = """
 Intercept term in a formula. If intercept is the
 only term in the formula, then a keywords argument
 \'nrow\' is needed.
 
->>> from scipy.stats.models.formula import formula, I
+>>> from scipy.stats.models.formula import Formula, I
 >>> I()
 array(1.0)
 >>> I(nrow=5)
 array([ 1.,  1.,  1.,  1.,  1.])
->>> f=formula(I)
+>>> f=Formula(I)
 >>> f(nrow=5)
 array([1, 1, 1, 1, 1])
 

Modified: trunk/scipy/stats/models/gam.py
===================================================================
--- trunk/scipy/stats/models/gam.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/gam.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -7,7 +7,7 @@
 
 from scipy.stats.models import family
 from scipy.stats.models.bspline import SmoothingSpline
-from scipy.stats.models.glm import model as glm
+from scipy.stats.models.glm import Model as GLM
 
 def default_smoother(x):
     _x = x.copy()
@@ -37,7 +37,7 @@
     s.target_df = 5
     return s
 
-class offset:
+class Offset:
 
     def __init__(self, fn, offset):
         self.fn = fn
@@ -46,7 +46,7 @@
     def __call__(self, *args, **kw):
         return self.fn(*args, **kw) + self.offset
 
-class results:
+class Results:
 
     def __init__(self, Y, alpha, design, smoothers, family, offset):
         self.Y = Y
@@ -67,7 +67,7 @@
     def smoothed(self, design):
         return N.array([self.smoothers[i]() + self.offset[i] for i in range(design.shape[1])])
 
-class additive_model:
+class AdditiveModel:
 
     def __init__(self, design, smoothers=None, weights=None):
         self.design = design
@@ -141,13 +141,13 @@
 
         return self.results 
 
-class model(glm, additive_model):
+class Model(GLM, AdditiveModel):
 
     niter = 10
 
     def __init__(self, design, smoothers=None, family=family.Gaussian()):
-        glm.__init__(self, design, family=family)
-        additive_model.__init__(self, design, smoothers=smoothers)
+        GLM.__init__(self, design, family=family)
+        AdditiveModel.__init__(self, design, smoothers=smoothers)
         self.family = family
 
     def next(self):
@@ -155,7 +155,7 @@
         _results.mu = self.family.link.inverse(_results.predict(self.design))
         self.weights = self.family.weights(_results.mu)
         Z = _results.predict(self.design) + self.family.link.deriv(_results.mu) * (Y - _results.mu)
-        m = additive_model(self.design, smoothers=self.smoothers, weights=self.weights)
+        m = AdditiveModel(self.design, smoothers=self.smoothers, weights=self.weights)
         _results = m.fit(Z) 
         _results.Y = Y
         _results.mu = self.family.link.inverse(_results.predict(self.design))
@@ -172,7 +172,7 @@
         if Y is None:
             Y = self.Y
         resid = Y - self.results.mu
-        return (N.power(resid, 2) / self.family.variance(self.results.mu)).sum() / additive_model.df_resid(self)
+        return (N.power(resid, 2) / self.family.variance(self.results.mu)).sum() / AdditiveModel.df_resid(self)
     
     def fit(self, Y):
         self.Y = N.asarray(Y, N.float64)
@@ -180,7 +180,7 @@
         iter(self)
         alpha = self.Y.mean()
         Z = self.family.link(alpha) + self.family.link.deriv(alpha) * (Y - alpha)
-        m = additive_model(self.design, smoothers=self.smoothers)
+        m = AdditiveModel(self.design, smoothers=self.smoothers)
         self.results = m.fit(Z) 
         self.results.mu = self.family.link.inverse(self.results.predict(self.design))
         self.results.Y = Y
@@ -209,7 +209,7 @@
 
     y += z
     d = N.array([x1,x2]).T
-    m = additive_model(d)
+    m = AdditiveModel(d)
     m.fit(y)
     x = N.linspace(-2,2,50)
 

Modified: trunk/scipy/stats/models/glm.py
===================================================================
--- trunk/scipy/stats/models/glm.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/glm.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -1,18 +1,20 @@
 """
 General linear models
 --------------------
+
 """
+
 import numpy as N
 from scipy.stats.models import family
-from scipy.stats.models.regression import wls_model
+from scipy.stats.models.regression import WLSModel
 
-class model(wls_model):
+class Model(WLSModel):
 
     niter = 10
     
     def __init__(self, design, family=family.Gaussian()):
         self.family = family
-        super(model, self).__init__(design, weights=1)
+        super(Model, self).__init__(design, weights=1)
 
     def __iter__(self):                                                   
         self.iter = 0
@@ -21,7 +23,7 @@
 
     def deviance(self, Y=None, results=None, scale = 1.):
         """
-        Return (unnormalized) log-likelihood for glm.
+        Return (unnormalized) log-likelihood for GLM.
 
         Note that self.scale is interpreted as a variance in old_model, so
         we divide the residuals by its sqrt.
@@ -38,7 +40,7 @@
         self.weights = self.family.weights(results.mu)
         self.initialize(self.design)
         Z = results.predict + self.family.link.deriv(results.mu) * (Y - results.mu)
-        newresults = super(model, self).fit(self, Z)
+        newresults = super(Model, self).fit(self, Z)
         newresults.Y = Y
         newresults.mu = self.family.link.inverse(newresults.predict)
         self.iter += 1
@@ -48,7 +50,7 @@
         """
         Continue iterating, or has convergence been obtained?
         """
-        if self.iter >= model.niter:
+        if self.iter >= Model.niter:
             return False
 
         curdev = self.deviance(results=self.results)
@@ -75,7 +77,7 @@
     def fit(self, Y):
         self.Y = N.asarray(Y, N.float64)
         iter(self)
-        self.results = super(model, self).fit(
+        self.results = super(Model, self).fit(
             self.family.link.initialize(Y))
         self.results.mu = self.family.link.inverse(self.results.predict)
         self.scale = self.results.scale = self.estimate_scale()

Modified: trunk/scipy/stats/models/info.py
===================================================================
--- trunk/scipy/stats/models/info.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/info.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -4,14 +4,14 @@
  - model `formula`
  - standard `regression` models
 
-  - `ols_model` (ordinary least square regression)
-  - `wls_model` (weighted least square regression)
-  - `ar_model` (autoregressive model)
+  - `OLSModel` (ordinary least square regression)
+  - `WLSModel` (weighted least square regression)
+  - `ARModel` (autoregressive model)
 
- - `glm.model` (generalized linear models)
+ - `glm.Model` (generalized linear models)
  - robust statistical models
 
-  - `rlm.model` (robust linear models using M estimators)
+  - `rlm.Model` (robust linear models using M estimators)
   - `robust.norms` estimates
   - `robust.scale` estimates (MAD, Huber's proposal 2).
 

Modified: trunk/scipy/stats/models/model.py
===================================================================
--- trunk/scipy/stats/models/model.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/model.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -41,7 +41,7 @@
         """
         raise NotImplementedError
 
-class likelihood_model(Model):
+class LikelihoodModel(Model):
 
     def logL(self, theta):
         """
@@ -69,7 +69,7 @@
 #             return -self.logL(theta)
 #         self.results = optimize.fmin(f, theta)
         
-class likelihood_model_results(object):
+class LikelihoodModelResults(object):
     ''' Class to contain results from likelihood models '''
     def __init__(self, beta, normalized_cov_beta=None, scale=1.):
         ''' Set up results structure

Modified: trunk/scipy/stats/models/regression.py
===================================================================
--- trunk/scipy/stats/models/regression.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/regression.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -22,11 +22,11 @@
 import numpy.linalg as L
 from scipy.linalg import norm, toeplitz
 
-from scipy.stats.models.model import likelihood_model, \
-     likelihood_model_results
+from scipy.stats.models.model import LikelihoodModel, \
+     LikelihoodModelResults
 from scipy.stats.models import utils
 
-class ols_model(likelihood_model):
+class OLSModel(LikelihoodModel):
     """
     A simple ordinary least squares model.
 
@@ -34,15 +34,15 @@
     --------
     >>> import numpy as N
     >>> 
-    >>> from scipy.stats.models.formula import term, I
-    >>> from scipy.stats.models.regression import ols_model
+    >>> from scipy.stats.models.formula import Term, I
+    >>> from scipy.stats.models.regression import OLSModel
     >>> 
     >>> data={'Y':[1,3,4,5,2,3,4],
     ...       'X':range(1,8)}
     >>> f = term("X") + I
     >>> f.namespace = data
     >>> 
-    >>> model = ols_model(f.design())
+    >>> model = OLSModel(f.design())
     >>> results = model.fit(data['Y'])
     >>> 
     >>> results.beta
@@ -60,13 +60,13 @@
 
     def __init__(self, design):
         """
-        Create a `ols_model` from a design.
+        Create a `OLSModel` from a design.
 
         :Parameters:
             design : TODO
                 TODO
         """
-        super(ols_model, self).__init__()
+        super(OLSModel, self).__init__()
         self.initialize(design)
 
     def initialize(self, design):
@@ -100,7 +100,7 @@
         """
         Z = self.whiten(Y)
 
-        lfit = regression_results(L.lstsq(self.wdesign, Z)[0], Y)
+        lfit = RegressionResults(L.lstsq(self.wdesign, Z)[0], Y)
         lfit.predict = N.dot(self.design, lfit.beta)
 
 
@@ -112,7 +112,7 @@
         """
         Z = self.whiten(Y)
 
-        lfit = regression_results(N.dot(self.calc_beta, Z), Y,
+        lfit = RegressionResults(N.dot(self.calc_beta, Z), Y,
                        normalized_cov_beta=self.normalized_cov_beta)
 
         lfit.df_resid = self.df_resid
@@ -124,7 +124,7 @@
         
         return lfit
 
-class ar_model(ols_model):
+class ARModel(OLSModel):
     """
     A regression model with an AR(p) covariance structure.
 
@@ -136,20 +136,20 @@
     >>> import numpy as N
     >>> import numpy.random as R
     >>> 
-    >>> from scipy.stats.models.formula import term, I
-    >>> from scipy.stats.models.regression import ar_model
+    >>> from scipy.stats.models.formula import Term, I
+    >>> from scipy.stats.models.regression import ARModel
     >>> 
     >>> data={'Y':[1,3,4,5,8,10,9],
     ...       'X':range(1,8)}
     >>> f = term("X") + I
     >>> f.namespace = data
     >>> 
-    >>> model = ar_model(f.design(), 2)
+    >>> model = ARModel(f.design(), 2)
     >>> for i in range(6):
     ...     results = model.fit(data['Y'])
     ...     print "AR coefficients:", model.rho
     ...     rho, sigma = model.yule_walker(data["Y"] - results.predict)
-    ...     model = ar_model(model.design, rho)
+    ...     model = ARModel(model.design, rho)
     ... 
     AR coefficients: [ 0.  0.]
     AR coefficients: [-0.52571491 -0.84496178]
@@ -182,7 +182,7 @@
             if self.rho.shape == ():
                 self.rho.shape = (1,)
             self.order = self.rho.shape[0]
-        super(ar_model, self).__init__(design)
+        super(ARModel, self).__init__(design)
 
     def iterative_fit(self, Y, niter=3):
         """
@@ -264,7 +264,7 @@
         sigmasq = r[0] - (r[1:]*rho).sum()
         return rho, N.sqrt(sigmasq)
 
-class wls_model(ols_model):
+class WLSModel(OLSModel):
     """
     A regression model with diagonal but non-identity covariance
     structure. The weights are presumed to be
@@ -273,15 +273,15 @@
 
     >>> import numpy as N
     >>> 
-    >>> from scipy.stats.models.formula import term, I
-    >>> from scipy.stats.models.regression import wls_model
+    >>> from scipy.stats.models.formula import Term, I
+    >>> from scipy.stats.models.regression import WLSModel
     >>> 
     >>> data={'Y':[1,3,4,5,2,3,4],
     ...       'X':range(1,8)}
     >>> f = term("X") + I
     >>> f.namespace = data
     >>> 
-    >>> model = wls_model(f.design(), weights=range(1,8))
+    >>> model = WLSModel(f.design(), weights=range(1,8))
     >>> results = model.fit(data['Y'])
     >>> 
     >>> results.beta
@@ -304,7 +304,7 @@
                 raise ValueError(
                     'Weights must be scalar or same length as design')
             self.weights = weights.reshape(design_rows)
-        super(wls_model, self).__init__(design)
+        super(WLSModel, self).__init__(design)
 
     def whiten(self, X):
         """
@@ -321,7 +321,7 @@
                 v[:,i] = X[:,i] * c
             return v
     
-class regression_results(likelihood_model_results):
+class RegressionResults(LikelihoodModelResults):
     """
     This class summarizes the fit of a linear regression model.
 
@@ -329,7 +329,7 @@
     """
 
     def __init__(self, beta, Y, normalized_cov_beta=None, scale=1.):
-        super(regression_results, self).__init__(beta,
+        super(RegressionResults, self).__init__(beta,
                                                  normalized_cov_beta,
                                                  scale)
         self.Y = Y

Modified: trunk/scipy/stats/models/rlm.py
===================================================================
--- trunk/scipy/stats/models/rlm.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/rlm.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -3,10 +3,10 @@
 """
 import numpy as N
 
-from scipy.stats.models.regression import wls_model
+from scipy.stats.models.regression import WLSModel
 from scipy.stats.models.robust import norms, scale
 
-class model(wls_model):
+class Model(WLSModel):
 
     niter = 20
     scale_est = 'MAD'
@@ -25,7 +25,7 @@
         """
         Return (unnormalized) log-likelihood from M estimator.
 
-        Note that self.scale is interpreted as a variance in ols_model, so
+        Note that self.scale is interpreted as a variance in OLSModel, so
         we divide the residuals by its sqrt.
         """
         if results is None:
@@ -36,7 +36,7 @@
         results = self.results
         self.weights = self.M.weights((results.Y - results.predict) / N.sqrt(results.scale))
         self.initialize(self.design)
-        results = wls_model.fit(self, results.Y)
+        results = WLSModel.fit(self, results.Y)
         self.scale = results.scale = self.estimate_scale(results)
         self.iter += 1
         return results
@@ -45,7 +45,7 @@
         """
         Continue iterating, or has convergence been obtained?
         """
-        if self.iter >= model.niter:
+        if self.iter >= Model.niter:
             return False
 
         curdev = self.deviance(results)
@@ -57,7 +57,7 @@
 
     def estimate_scale(self, results):
         """
-        Note that self.scale is interpreted as a variance in ols_model, so
+        Note that self.scale is interpreted as a variance in OLSModel, so
         we return MAD(resid)**2 by default. 
         """
         resid = results.Y - results.predict
@@ -71,7 +71,7 @@
     def fit(self, Y):
         
         iter(self)
-        self.results = wls_model.fit(self, Y)
+        self.results = WLSModel.fit(self, Y)
         self.scale = self.results.scale = self.estimate_scale(self.results)
         
         while self.cont(self.results):

Modified: trunk/scipy/stats/models/smoothers.py
===================================================================
--- trunk/scipy/stats/models/smoothers.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/smoothers.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -13,7 +13,7 @@
 from scipy.stats.models.bspline import bspline, _band2array
 
 
-class poly_smoother:
+class PolySmoother:
     """
     Polynomial smoother up to a given order.
     Fit based on weighted least squares.
@@ -52,7 +52,7 @@
         _w = N.sqrt(weights)
         if x is None:
             if not hasattr(self, "X"):
-                raise ValueError, "x needed to fit poly_smoother"
+                raise ValueError, "x needed to fit PolySmoother"
         else:
             self.X = N.array([(x**i) for i in range(self.order+1)])
 
@@ -61,7 +61,7 @@
         _y = y * _w
         self.coef = N.dot(L.pinv(X).T, _y)
 
-class smoothing_spline(bspline):
+class SmoothingSpline(bspline):
 
     penmax = 30.
 
@@ -159,7 +159,7 @@
         else:
             return self.rank
 
-class smoothing_spline_fixeddf(smoothing_spline):
+class SmoothingSplineFixedDF(SmoothingSpline):
     """
     Fit smoothing spline with approximately df degrees of freedom
     used in the fit, i.e. so that self.trace() is approximately df.
@@ -187,7 +187,7 @@
         if not self.target_reached:
             while True:
                 curpen = 0.5 * (apen + bpen)
-                smoothing_spline.fit(self, y, x=x, weights=weights, pen=curpen)
+                SmoothingSpline.fit(self, y, x=x, weights=weights, pen=curpen)
                 curdf = self.trace()
                 if curdf > df:
                     apen, bpen = curpen, 2 * curpen
@@ -199,9 +199,9 @@
                     self.target_reached = True
                     break
         else:
-            smoothing_spline.fit(self, y, x=x, weights=weights, pen=self.pen)
+            SmoothingSpline.fit(self, y, x=x, weights=weights, pen=self.pen)
 
-class smoothing_spline_gcv(smoothing_spline):
+class SmoothingSplineGCV(SmoothingSpline):
 
     """
     Fit smoothing spline trying to optimize GCV.
@@ -218,7 +218,7 @@
             bracket=(0,1.0e-03)):
     
         def _gcv(pen, y, x):
-            smoothing_spline.fit(y, x=x, pen=N.exp(pen), weights=weights)
+            SmoothingSpline.fit(y, x=x, pen=N.exp(pen), weights=weights)
             a = self.gcv()
             return a
 

Modified: trunk/scipy/stats/models/survival.py
===================================================================
--- trunk/scipy/stats/models/survival.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/survival.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -1,18 +1,18 @@
 import numpy as N
 
-class survival_time:
+class SurvivalTime:
     def __init__(self, time, delta):
         self.time, self.delta = time, delta
 
     def atrisk(self, time):
         raise NotImplementedError
 
-class right_censored(survival_time):
+class RightCensored(SurvivalTime):
 
     def atrisk(self, time):
         return N.less_equal.outer(time, self.time)
 
-class left_censored(survival_time):
+class LeftCensored(SurvivalTime):
 
     def atrisk(self, time):
         return N.greater_equal.outer(time, self.time)

Modified: trunk/scipy/stats/models/tests/test_bspline.py
===================================================================
--- trunk/scipy/stats/models/tests/test_bspline.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/tests/test_bspline.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -1,5 +1,5 @@
 """
-Test functions for models.glm
+Test functions for models.bspline
 """
 
 import numpy as N

Modified: trunk/scipy/stats/models/tests/test_formula.py
===================================================================
--- trunk/scipy/stats/models/tests/test_formula.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/tests/test_formula.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -14,38 +14,38 @@
 class TestTerm(NumpyTestCase):
 
     def test_init(self):
-        t1 = formula.term("trivial")
+        t1 = formula.Term("trivial")
         sqr = lambda x: x*x
 
-        t2 = formula.term("not_so_trivial", sqr, "sqr")
+        t2 = formula.Term("not_so_trivial", sqr, "sqr")
 
-        self.assertRaises(ValueError, formula.term, "name", termname=0)
+        self.assertRaises(ValueError, formula.Term, "name", termname=0)
 
 
     def test_str(self):
-        t = formula.term("name")
+        t = formula.Term("name")
         s = str(t)
 
     def test_add(self):
-        t1 = formula.term("t1")
-        t2 = formula.term("t2")
+        t1 = formula.Term("t1")
+        t2 = formula.Term("t2")
         f = t1 + t2
-        self.assert_(isinstance(f, formula.formula))
+        self.assert_(isinstance(f, formula.Formula))
         self.assert_(f.hasterm(t1))
         self.assert_(f.hasterm(t2))
 
     def test_mul(self):
-        t1 = formula.term("t1")
-        t2 = formula.term("t2")
+        t1 = formula.Term("t1")
+        t2 = formula.Term("t2")
         f = t1 * t2
-        self.assert_(isinstance(f, formula.formula))
+        self.assert_(isinstance(f, formula.Formula))
 
-        intercept = formula.term("intercept")
+        intercept = formula.Term("intercept")
         f = t1 * intercept
-        self.assertEqual(str(f), str(formula.formula(t1)))
+        self.assertEqual(str(f), str(formula.Formula(t1)))
 
         f = intercept * t1
-        self.assertEqual(str(f), str(formula.formula(t1)))
+        self.assertEqual(str(f), str(formula.Formula(t1)))
 
 class TestFormula(NumpyTestCase):
 
@@ -56,7 +56,7 @@
         for i in range(10):
             name = '%s' % string.uppercase[i]
             self.namespace[name] = self.X[:,i]
-            self.terms.append(formula.term(name))
+            self.terms.append(formula.Term(name))
 
         self.formula = self.terms[0]
         for i in range(1, 10):
@@ -66,8 +66,8 @@
     def test_namespace(self):
         space1 = {'X':N.arange(50), 'Y':N.arange(50)*2}
         space2 = {'X':N.arange(20), 'Y':N.arange(20)*2}
-        X = formula.term('X')
-        Y = formula.term('Y')
+        X = formula.Term('X')
+        Y = formula.Term('Y')
 
         X.namespace = space1 
         assert_almost_equal(X(), N.arange(50))
@@ -89,12 +89,12 @@
 
 
     def test_termcolumns(self):
-        t1 = formula.term("A")
-        t2 = formula.term("B")
+        t1 = formula.Term("A")
+        t2 = formula.Term("B")
         f = t1 + t2 + t1 * t2
         def other(val):
             return N.array([3.2*val,4.342*val**2, 5.234*val**3])
-        q = formula.quantitative(['other%d' % i for i in range(1,4)], termname='other', func=t1, transform=other)
+        q = formula.Quantitative(['other%d' % i for i in range(1,4)], termname='other', func=t1, transform=other)
         f += q
         q.namespace = f.namespace = self.formula.namespace
         assert_almost_equal(q(), f()[f.termcolumns(q)])
@@ -150,7 +150,7 @@
 
     def test_contrast2(self):
     
-        dummy = formula.term('zero')
+        dummy = formula.Term('zero')
         self.namespace['zero'] = N.zeros((40,), N.float64)
         term = dummy + self.terms[2]
         c = contrast.Contrast(term, self.formula)
@@ -163,7 +163,7 @@
         X = self.formula.design()
         P = N.dot(X, L.pinv(X))
         
-        dummy = formula.term('noise')
+        dummy = formula.Term('noise')
         resid = N.identity(40) - P
         self.namespace['noise'] = N.transpose(N.dot(resid, R.standard_normal((40,5))))
         terms = dummy + self.terms[2]
@@ -181,32 +181,32 @@
 
     def test_quantitative(self):
         t = self.terms[2]
-        sint = formula.quantitative('t', func=t, transform=N.sin)
+        sint = formula.Quantitative('t', func=t, transform=N.sin)
         t.namespace = sint.namespace = self.formula.namespace
         assert_almost_equal(N.sin(t()), sint())
 
     def test_factor1(self):
         f = ['a','b','c']*10
-        fac = formula.factor('ff', set(f))
+        fac = formula.Factor('ff', set(f))
         fac.namespace = {'ff':f}
         self.assertEquals(list(fac.values()), f)
 
     def test_factor2(self):
         f = ['a','b','c']*10
-        fac = formula.factor('ff', set(f))
+        fac = formula.Factor('ff', set(f))
         fac.namespace = {'ff':f}
         self.assertEquals(fac().shape, (3,30))
 
     def test_factor3(self):
         f = ['a','b','c']*10
-        fac = formula.factor('ff', set(f))
+        fac = formula.Factor('ff', set(f))
         fac.namespace = {'ff':f}
         m = fac.main_effect(reference=1)
         self.assertEquals(m().shape, (2,30))
 
     def test_factor4(self):
         f = ['a','b','c']*10
-        fac = formula.factor('ff', set(f))
+        fac = formula.Factor('ff', set(f))
         fac.namespace = {'ff':f}
         m = fac.main_effect(reference=2)
         r = N.array([N.identity(3)]*10)

Modified: trunk/scipy/stats/models/tests/test_glm.py
===================================================================
--- trunk/scipy/stats/models/tests/test_glm.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/tests/test_glm.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -1,5 +1,5 @@
 """
-Test functions for models.glm
+Test functions for models.GLM
 """
 
 import numpy as N

Modified: trunk/scipy/stats/models/tests/test_regression.py
===================================================================
--- trunk/scipy/stats/models/tests/test_regression.py	2007-10-03 06:09:25 UTC (rev 3392)
+++ trunk/scipy/stats/models/tests/test_regression.py	2007-10-03 06:19:08 UTC (rev 3393)
@@ -5,7 +5,7 @@
 from numpy.random import standard_normal
 from numpy.testing import NumpyTest, NumpyTestCase
 
-from scipy.stats.models.regression import ols_model, ar_model
+from scipy.stats.models.regression import OLSModel, ARModel
 
 W = standard_normal
 
@@ -14,14 +14,14 @@
     def testOLS(self):
         X = W((40,10))
         Y = W((40,))
-        model = ols_model(design=X)
+        model = OLSModel(design=X)
         results = model.fit(Y)
         self.assertEquals(results.df_resid, 30)
 
     def testAR(self):
         X = W((40,10))
         Y = W((40,))
-        model = ar_model(design=X, rho=0.4)
+        model = ARModel(design=X, rho=0.4)
         results = model.fit(Y)
         self.assertEquals(results.df_resid, 30)
 
@@ -29,7 +29,7 @@
         X = W((40,10))
         X[:,0] = X[:,1] + X[:,2]
         Y = W((40,))
-        model = ols_model(design=X)
+        model = OLSModel(design=X)
         results = model.fit(Y)
         self.assertEquals(results.df_resid, 31)
 
@@ -37,7 +37,7 @@
         X = W((40,10))
         X[:,0] = X[:,1] + X[:,2]
         Y = W((40,))
-        model = ar_model(design=X, rho=0.9)
+        model = ARModel(design=X, rho=0.9)
         results = model.fit(Y)
         self.assertEquals(results.df_resid, 31)
 



More information about the Scipy-svn mailing list