spreg.diagnostics.white¶
-
spreg.diagnostics.
white
(reg)[source]¶ Calculates the White test to check for heteroscedasticity. [Whi80]
- Parameters
- regregression object
output instance from a regression model
- Returns
- white_resultdictionary
contains the statistic (white), degrees of freedom (df) and the associated p-value (pvalue) for the White test.
- whitefloat
scalar value for the White test statistic.
- dfinteger
degrees of freedom associated with the test
- pvaluefloat
p-value associated with the statistic (chi^2 distributed with k df)
Notes
x attribute in the reg object must have a constant term included. This is standard for spreg.OLS so no testing done to confirm constant.
Examples
>>> import numpy as np >>> import libpysal >>> from libpysal import examples >>> import diagnostics >>> from ols import OLS
Read the DBF associated with the Columbus data.
>>> db = libpysal.io.open(examples.get_path("columbus.dbf"),"r")
Create the dependent variable vector.
>>> y = np.array(db.by_col("CRIME")) >>> y = np.reshape(y, (49,1))
Create the matrix of independent variables.
>>> X = [] >>> X.append(db.by_col("INC")) >>> X.append(db.by_col("HOVAL")) >>> X = np.array(X).T
Run an OLS regression.
>>> reg = OLS(y,X)
Calculate the White test for heteroscedasticity.
>>> testresult = diagnostics.white(reg)
Print the degrees of freedom for the test.
>>> print testresult['df'] 5
Print the test statistic.
>>> print("%1.3f"%testresult['wh']) 19.946
Print the associated p-value.
>>> print("%1.4f"%testresult['pvalue']) 0.0013