pysal / gwr

This is a repository for the geographically-weighted regression submodule of the Python Spatial Analysis Library
BSD 2-Clause "Simplified" License
16 stars 16 forks source link

Possibility for adding a summary text for GWR diagnostics #5

Open Ziqi-Li opened 6 years ago

Ziqi-Li commented 6 years ago

Like what statsmodel.OLS.fit.summary() does? Can follow GWR4's summary .txt.

TaylorOshan commented 6 years ago

Definitely possible. Might be helpful to use the summary statement that is available in some of the spreg functions. Running the following two stage least squares code example:

import numpy as np
import pysal
db = pysal.open(pysal.examples.get_path("columbus.dbf"), 'r')
y_var = 'CRIME'
y = np.array([db.by_col(y_var)]).reshape(49, 1)
x_var = ['INC']
x = np.array([db.by_col(name) for name in x_var]).T
yd_var = ['HOVAL']
yd = np.array([db.by_col(name) for name in yd_var]).T
q_var = ['DISCBD']
q = np.array([db.by_col(name) for name in q_var]).T
w = pysal.rook_from_shapefile(pysal.examples.get_path("columbus.shp"))
w.transform = 'r'
tsls = TSLS(y, x, yd, q, w=w, spat_diag=True, name_y=y_var, name_x=x_var,
                name_yend=yd_var, name_q=q_var, name_ds='columbus', name_w='columbus.gal')
print tsls.summary

produces the following output:

REGRESSION
----------
SUMMARY OF OUTPUT: TWO STAGE LEAST SQUARES
------------------------------------------
Data set            :    columbus
Weights matrix      :columbus.gal
Dependent Variable  :       CRIME                Number of Observations:          49
Mean dependent var  :     35.1288                Number of Variables   :           3
S.D. dependent var  :     16.7321                Degrees of Freedom    :          46
Pseudo R-squared    :      0.2794

------------------------------------------------------------------------------------
            Variable     Coefficient       Std.Error     z-Statistic     Probability
------------------------------------------------------------------------------------
            CONSTANT      88.4657958      15.1346096       5.8452645       0.0000000
                 INC       0.5200379       1.4146781       0.3676016       0.7131703
               HOVAL      -1.5821659       0.7931892      -1.9946891       0.0460768
------------------------------------------------------------------------------------
Instrumented: HOVAL
Instruments: DISCBD

DIAGNOSTICS FOR SPATIAL DEPENDENCE
TEST                           MI/DF       VALUE           PROB
Anselin-Kelejian Test             1           1.158          0.2820
================================ END OF REPORT =====================================
ljwolf commented 6 years ago

If you look into that summary-table-building code in spreg, it's.... a bit hairy. I'd highly recommend we try something like a jinja template rather than doing a ton of string munging.