spreg.LMtests

class spreg.LMtests(ols, w, tests=['all'])[source]

Lagrange Multiplier tests. Implemented as presented in [ABFY96] and []

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 ‘sarma’ or ‘all’ was in tests). Pair of statistic and p-value for the SARMA test.

lmwxtuple

(Only if ‘lmwx’ or ‘all’ was in tests). Pair of statistic and p-value for the LM test for WX.

rlmwxtuple

(Only if ‘rlmwx’ or ‘all’ was in tests). Pair of statistic and p-value for the Robust LM WX test.

rlmdurlagtuple

(Only if ‘rlmdurlag’ or ‘all’ was in tests). Pair of statistic and p-value for the Robust LM Lag - SDM test.

lmspdurbintuple

(Only if ‘lmspdurbin’ or ‘all’ was in tests). Pair of statistic and p-value for the Joint test for SDM.

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
LM test for WX:
>>> print(round(lms.lmwx[0],4), round(lms.lmwx[1],4))
1.3377 0.5123
Robust LM WX test:
>>> print(round(lms.rlmwx[0],4), round(lms.rlmwx[1],4))
3.4532 0.1779
Robust LM Lag - SDM:
>>> print(round(lms.rlmdurlag[0],4), round(lms.rlmdurlag[1],4))
3.0971 0.0784
Joint test for SDM:
>>> print(round(lms.lmspdurbin[0],4), round(lms.lmspdurbin[1],4))
4.4348 0.2182
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

  • ‘sarma’: LM SARMA test

  • ‘lmwx’: LM test for WX

  • ‘rlmwx’: Robust LM WX test

  • ‘lmspdurbin’: Joint test for SDM

  • ‘rlmdurlag’: Robust LM Lag - SDM

__init__(ols, w, tests=['all'])[source]

Methods

__init__(ols, w[, tests])