spreg.diagnostics.t_stat¶
-
spreg.diagnostics.
t_stat
(reg, z_stat=False)[source]¶ Calculates the t-statistics (or z-statistics) and associated p-values. [Gre03]
- Parameters
- regregression object
output instance from a regression model
- z_statboolean
If True run z-stat instead of t-stat
- Returns
- ts_resultlist of tuples
each tuple includes value of t statistic (or z statistic) and associated p-value
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.open(libpysal.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 t-statistics for the regression coefficients.
>>> testresult = diagnostics.t_stat(reg)
Print the tuples that contain the t-statistics and their significances.
>>> print("%12.12f"%testresult[0][0], "%12.12f"%testresult[0][1], "%12.12f"%testresult[1][0], "%12.12f"%testresult[1][1], "%12.12f"%testresult[2][0], "%12.12f"%testresult[2][1]) ('14.490373143689', '0.000000000000', '-4.780496191297', '0.000018289595', '-2.654408642718', '0.010874504910')