Skip to content

Commit

Permalink
MAINT: Fix missed usage of deprecated tools.rank
Browse files Browse the repository at this point in the history
  • Loading branch information
jseabold committed Apr 3, 2014
1 parent 29a3bce commit 82bdf87
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
14 changes: 7 additions & 7 deletions statsmodels/regression/linear_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
from scipy import optimize
from scipy.stats import chi2

from statsmodels.tools.tools import (add_constant, rank,
recipr, chain_dot, pinv_extended)
from statsmodels.compatnp.np_compat import np_matrix_rank
from statsmodels.tools.tools import add_constant, chain_dot, pinv_extended
from statsmodels.tools.decorators import (resettable_cache,
cache_readonly,
cache_writable)
Expand Down Expand Up @@ -110,7 +110,7 @@ def df_model(self):
"""
if self._df_model is None:
if self.rank is None:
self.rank = rank(self.exog)
self.rank = np_matrix_rank(self.exog)
self._df_model = float(self.rank - self.k_constant)
return self._df_model

Expand All @@ -127,7 +127,7 @@ def df_resid(self):

if self._df_resid is None:
if self.rank is None:
self.rank = rank(self.exog)
self.rank = np_matrix_rank(self.exog)
self._df_resid = self.nobs - self.rank
return self._df_resid

Expand All @@ -151,7 +151,7 @@ def _has_constant(self):
return True
# Compute rank of augmented matrix
augmented_exog = add_constant(self.exog)
return rank(augmented_exog)==rank(self.exog)
return np_matrix_rank(augmented_exog) == np_matrix_rank(self.exog)

def whiten(self, X):
raise NotImplementedError("Subclasses should implement.")
Expand Down Expand Up @@ -194,7 +194,7 @@ def fit(self, method="pinv", **kwargs):

# Cache these singular values for use later.
self.wexog_singular_values = singular_values
self.rank = rank(np.diag(singular_values))
self.rank = np_matrix_rank(np.diag(singular_values))

beta = np.dot(self.pinv_wexog, self.wendog)

Expand All @@ -209,7 +209,7 @@ def fit(self, method="pinv", **kwargs):

# Cache singular values from R.
self.wexog_singular_values = np.linalg.svd(R, 0, 0)
self.rank = rank(R)
self.rank = np_matrix_rank(R)
else:
Q, R = self.exog_Q, self.exog_R

Expand Down
5 changes: 3 additions & 2 deletions statsmodels/regression/quantile_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import scipy.stats as stats
from scipy.linalg import pinv
from scipy.stats import norm
from statsmodels.tools.tools import chain_dot, rank
from statsmodels.tools.tools import chain_dot
from statsmodels.compatnp.np_compat import np_matrix_rank
from statsmodels.tools.decorators import cache_readonly
from statsmodels.regression.linear_model import (RegressionModel,
RegressionResults,
Expand Down Expand Up @@ -137,7 +138,7 @@ def fit(self, q=.5, vcov='robust', kernel='epa', bandwidth='hsheather',
endog = self.endog
exog = self.exog
nobs = self.nobs
exog_rank = rank(self.exog)
exog_rank = np_matrix_rank(self.exog)
self.rank = exog_rank
self.df_model = float(self.rank - self.k_constant)
self.df_resid = self.nobs - self.rank
Expand Down
5 changes: 3 additions & 2 deletions statsmodels/regression/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from numpy.testing import (assert_almost_equal, assert_approx_equal,
assert_raises, assert_equal, assert_allclose)
from scipy.linalg import toeplitz
from statsmodels.tools.tools import add_constant, categorical, rank
from statsmodels.tools.tools import add_constant, categorical
from statsmodels.compatnp.np_compat import np_matrix_rank
from statsmodels.regression.linear_model import OLS, WLS, GLS, yule_walker
from statsmodels.datasets import longley
from scipy.stats import t as student_t
Expand Down Expand Up @@ -162,7 +163,7 @@ def setupClass(cls):
Q, R = np.linalg.qr(data.exog)
model_qr.exog_Q, model_qr.exog_R = Q, R
model_qr.normalized_cov_params = np.linalg.inv(np.dot(R.T, R))
model_qr.rank = rank(R)
model_qr.rank = np_matrix_rank(R)
res_qr2 = model_qr.fit(method="qr")

cls.res_qr = res_qr
Expand Down
5 changes: 3 additions & 2 deletions statsmodels/stats/contrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from scipy.stats import f as fdist
from scipy.stats import t as student_t
from scipy import stats
from statsmodels.tools.tools import clean0, rank, fullrank
from statsmodels.tools.tools import clean0, fullrank
from statsmodels.compatnp.np_compat import np_matrix_rank


#TODO: should this be public if it's just a container?
Expand Down Expand Up @@ -285,7 +286,7 @@ def contrastfromcols(L, D, pseudo=None):
if len(Lp.shape) == 1:
Lp.shape = (n, 1)

if rank(Lp) != Lp.shape[1]:
if np_matrix_rank(Lp) != Lp.shape[1]:
Lp = fullrank(Lp)
C = np.dot(pseudo, Lp).T

Expand Down
6 changes: 2 additions & 4 deletions statsmodels/tools/catadd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@


import numpy as np
from statsmodels.tools.tools import rank as smrank
from statsmodels.compatnp.np_compat import np_matrix_rank


def add_indep(x, varnames, dtype=None):
Expand Down Expand Up @@ -31,7 +29,7 @@ def add_indep(x, varnames, dtype=None):
for (xi, ni) in zip(x, varnames):
#print xi.shape, xout.shape
xout[:,count] = xi
rank_new = smrank(xout)
rank_new = np_matrix_rank(xout)
#print rank_new
if rank_new > rank_old:
varnames_new.append(ni)
Expand Down

0 comments on commit 82bdf87

Please sign in to comment.