spreg.LMtests¶
-
class
spreg.
LMtests
(ols, w, tests=['all'])[source]¶ Lagrange Multiplier tests. Implemented as presented in [ABFY96]
- Parameters
- lmetuple
(Only if ‘lme’ or ‘all’ was in tests). Pair of statistic and p-value for the LM error test.
- lmltuple
(Only if ‘lml’ or ‘all’ was in tests). Pair of statistic and p-value for the LM lag test.
- rlmetuple
(Only if ‘rlme’ or ‘all’ was in tests). Pair of statistic and p-value for the Robust LM error test.
- rlmltuple
(Only if ‘rlml’ or ‘all’ was in tests). Pair of statistic and p-value for the Robust LM lag test.
- sarmatuple
(Only if ‘rlml’ or ‘all’ was in tests). Pair of statistic and p-value for the SARMA test.
Examples
>>> import numpy as np >>> import libpysal >>> from spreg import OLS >>> import spreg
Open the csv file to access the data for analysis
>>> csv = libpysal.io.open(libpysal.examples.get_path('columbus.dbf'),'r')
Pull out from the csv the files we need (‘HOVAL’ as dependent as well as ‘INC’ and ‘CRIME’ as independent) and directly transform them into nx1 and nx2 arrays, respectively
>>> y = np.array([csv.by_col('HOVAL')]).T >>> x = np.array([csv.by_col('INC'), csv.by_col('CRIME')]).T
Create the weights object from existing .gal file
>>> w = libpysal.io.open(libpysal.examples.get_path('columbus.gal'), 'r').read()
Row-standardize the weight object (not required although desirable in some cases)
>>> w.transform='r'
Run an OLS regression
>>> ols = OLS(y, x)
Run all the LM tests in the residuals. These diagnostics test for the presence of remaining spatial autocorrelation in the residuals of an OLS model and give indication about the type of spatial model. There are five types: presence of a spatial lag model (simple and robust version), presence of a spatial error model (simple and robust version) and joint presence of both a spatial lag as well as a spatial error model.
>>> lms = spreg.LMtests(ols, w)
LM error test:
>>> print(round(lms.lme[0],4), round(lms.lme[1],4)) 3.0971 0.0784
LM lag test:
>>> print(round(lms.lml[0],4), round(lms.lml[1],4)) 0.9816 0.3218
Robust LM error test:
>>> print(round(lms.rlme[0],4), round(lms.rlme[1],4)) 3.2092 0.0732
Robust LM lag test:
>>> print(round(lms.rlml[0],4), round(lms.rlml[1],4)) 1.0936 0.2957
LM SARMA test:
>>> print(round(lms.sarma[0],4), round(lms.sarma[1],4)) 4.1907 0.123
- Attributes
- olsOLS
OLS regression object
- wW
Spatial weights instance
- testslist
Lists of strings with the tests desired to be performed. Values may be:
‘all’: runs all the options (default)
‘lme’: LM error test
‘rlme’: Robust LM error test
‘lml’ : LM lag test
‘rlml’: Robust LM lag test
-
__init__
(ols, w, tests=['all'])[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(ols, w[, tests])Initialize self.