spreg.white¶
- spreg.white(reg)[source]¶
Calculates the White test to check for heteroscedasticity. [Whi80]
- Parameters:
- reg
regression
object
output instance from a regression model
- reg
- Returns:
- white_result
dictionary
contains the statistic (white), degrees of freedom (df) and the associated p-value (pvalue) for the White test.
- white
float
scalar value for the White test statistic.
- df
integer
degrees of freedom associated with the test
- pvalue
float
p-value associated with the statistic (chi^2 distributed with k df)
- white_result
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 spreg >>> from spreg 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 = spreg.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