spreg.breusch_pagan

spreg.breusch_pagan(reg, z=None)[source]

Calculates the Breusch-Pagan test statistic to check for heteroscedasticity. [BP79]

Parameters:
regregression object

output instance from a regression model

zarray

optional input for specifying an alternative set of variables (Z) to explain the observed variance. By default this is a matrix of the squared explanatory variables (X**2) with a constant added to the first column if not already present. In the default case, the explanatory variables are squared to eliminate negative values.

Returns:
bp_resultdictionary

contains the statistic (bp) for the test and the associated p-value (p-value)

bpfloat

scalar value for the Breusch-Pagan test statistic

dfinteger

degrees of freedom associated with the test (k)

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 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 Breusch-Pagan test for heteroscedasticity.

>>> testresult = spreg.breusch_pagan(reg)

Print the degrees of freedom for the test.

>>> testresult['df']
2

Print the test statistic.

>>> print("%1.3f"%testresult['bp'])
7.900

Print the associated p-value.

>>> print("%1.4f"%testresult['pvalue'])
0.0193