API reference¶
Models¶
A model class names a process and a family: SAR, SARLogit,
SARNegBinFlow. Panel structure, effects, dynamics, and the flow restriction
are arguments to the same class:
time_col(formula mode) orT(matrix mode) makes the model a panel;unit_effects(pair_effectsfor flows) isNone,"fixed", or"random", andtime_effects=Trueadds fixed time effects;dynamic=Trueadds the time lag \(y_{t-1}\), anddynamic="restricted"gives the restricted dynamic SDM;separable=Truepins \(\rho_w = -\rho_o \rho_d\) in a flow model.
A combination the package does not implement raises when the model is constructed.
Gaussian¶
|
Bayesian ordinary least squares cross-sectional regression. |
|
Bayesian SLX (Spatial Lag X) model. |
|
Bayesian Spatial Autoregressive (Spatial Lag) model. |
|
Bayesian Spatial Error Model. |
|
Bayesian Spatial Durbin Model. |
|
Bayesian Spatial Durbin Error Model. |
Censored and binary¶
|
Bayesian spatial autoregressive Tobit model. |
|
Bayesian spatial error Tobit model. |
|
Bayesian spatial Durbin Tobit model. |
|
Bayesian (non-spatial) logistic regression. |
|
Bayesian SAR logit: the latent SAR, or the reduced form with |
|
Bayesian latent SEM logit, sampled by an exact Gibbs sweep. |
|
Bayesian latent SDEM logit, sampled by the latent logit's exact Gibbs sweep. |
|
Bayesian (non-spatial) probit regression. |
|
Bayesian SAR probit: the latent SAR, or the reduced form with |
|
Bayesian latent SEM probit, or the SEM probit with random unit effects. |
|
Bayesian latent SDEM probit, sampled by the latent probit's exact Gibbs sweep. |
Counts¶
|
Bayesian (non-spatial) Negative Binomial regression. |
|
Bayesian SAR negative binomial: the latent SAR, or the reduced form with |
|
Bayesian latent SEM negative binomial, sampled by an exact Gibbs sweep. |
|
Bayesian latent SDEM negative binomial, sampled as |
|
Zero-inflated negative binomial panel without spatial dependence. |
|
Bayesian zero-inflated SAR negative binomial: latent, or reduced with |
|
Hurdle negative binomial panel without spatial dependence. |
|
Bayesian SAR hurdle NB2: the latent model, or the reduced form with |
Flows¶
|
Non-spatial Bayesian origin-destination gravity model. |
|
Bayesian SAR origin-destination flow model. |
|
Bayesian spatial-error origin-destination flow model. |
|
Aspatial negative binomial (NB2) origin-destination gravity model. |
|
Reduced-form SAR negative binomial (NB2) origin-destination flow model. |
|
Reduced-form SAR Poisson origin-destination flow model (cross-section). |
|
Zero-inflated negative binomial SAR flow model (separable). |
|
Reduced-form SAR hurdle negative binomial flow model (separable). |
Multilevel¶
|
Bayesian spatial multilevel model with a graph and a process at each level. |
|
One level's equation for |
Default Gibbs Priors¶
|
Base priors for all Gibbs samplers. |
|
Prior hyperparameters for Gaussian spatial Gibbs. |
|
Prior hyperparameters for the reduced-form SAR-NB sampler. |
|
Prior hyperparameters for the reduced-form flow NB sampler. |
|
Prior hyperparameters for the ZINB Gibbs sampler. |
|
Prior hyperparameters for the SAR-logit Gibbs sampler. |
|
Prior hyperparameters for RE panel Gibbs sampler. |
Default NUTS Priors¶
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors shared by every panel model. |
|
The base of |
|
Panel priors with |
|
Panel priors with |
|
The base of |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for |
|
Priors for the count panels ( |
|
Priors for the ZINB panels ( |
|
Priors for |
|
Priors for the hurdle panels ( |
|
Priors for the hurdle flow panels ( |
|
Priors for |
|
Priors for |
|
Priors shared by every dynamic panel model. |
|
Priors for the dynamic panel of |
|
Priors for the dynamic panel of |
|
Priors for the dynamic panel of |
|
Priors for the dynamic panel of |
|
Priors for the restricted dynamic panel of |
|
Priors for the dynamic panel of |
|
Priors for the dynamic panel of |
Bayesian Diagnostics¶
|
Container for Bayesian LM test results. |
|
LM test for an omitted spatial lag (H₀: ρ = 0). |
|
LM test for an omitted spatial error process (H₀: λ = 0). |
|
LM test for omitted \(WX\) at an OLS or SAR fit (H₀: θ = 0). |
|
Joint LM test for the SDM at an OLS fit (H₀: ρ = 0 and θ = 0). |
Joint LM test for the SDEM at an OLS fit (H₀: λ = 0 and θ = 0). |
|
LM test for a spatial error process at a SAR fit (H₀: λ = 0 | SAR). |
|
|
LM test for a spatial error process at an SDM fit (H₀: λ = 0 | SDM). |
|
LM test for a spatial lag at an SDEM fit (H₀: ρ = 0 | SDEM). |
|
LM test for omitted \(WX\) at a SEM fit (H₀: θ = 0 | SEM). |
|
Robust LM-lag at an OLS fit (H₀: ρ = 0, robust to a local λ). |
Robust LM-error at an OLS fit (H₀: λ = 0, robust to a local ρ). |
|
Robust LM-lag at an SLX fit (H₀: ρ = 0, robust to a local λ). |
|
|
Robust LM-WX at a SAR fit (H₀: θ = 0, robust to a local λ). |
Robust LM-error at an SLX fit (H₀: λ = 0, robust to a local ρ). |
|
Robust LM-error at a SAR fit (H₀: λ = 0, robust to a local θ). |
|
Robust LM-lag at an OLS or SEM fit (H₀: ρ = 0, robust to a local θ). |
|
Robust LM-WX at an OLS or SEM fit (H₀: θ = 0, robust to a local ρ). |
GLM Bayesian LM Tests¶
LM tests for the logit, probit and NB families: the latent SAR and SEM score tests at the GLM null (Logit, Probit, NegBin), the error and WX tests at a reduced-form SAR null (SARLogit(latent=False), SARProbit(latent=False), SARNegBin(latent=False)), and a Moran diagnostic on working residuals.
|
LM test for the latent SAR at the GLM null. |
|
LM test for a latent error process. |
Robust LM test for the spillover at the GLM null. |
|
Robust LM test for the error term at the GLM null. |
|
|
Joint LM test for spillover and error at the GLM null. |
|
LM test for omitted \(WX\) (H₀: θ = 0). |
Moran diagnostic on the working residuals at the GLM null. |
Panel Bayesian LM Tests¶
|
LM test for an omitted spatial lag in a panel (H₀: ρ = 0). |
|
LM test for an omitted spatial error process in a panel (H₀: λ = 0). |
Robust panel LM-lag (H₀: ρ = 0, robust to a local λ). |
|
Robust panel LM-error (H₀: λ = 0, robust to a local ρ). |
|
|
Panel LM test for omitted \(WX\) at an OLS or SAR panel (H₀: θ = 0). |
Joint panel LM test for the SDM at an OLS panel (H₀: ρ = 0 and θ = 0). |
|
Joint panel LM test for the SDEM at an OLS panel (H₀: λ = 0 and θ = 0). |
|
Panel LM test for a spatial error process at an SDM panel (H₀: λ = 0 | SDM). |
|
Panel LM test for a spatial lag at an SEM or SDEM panel (H₀: ρ = 0). |
|
Panel LM test for omitted \(WX\) at a SEM panel (H₀: θ = 0 | SEM). |
|
Robust panel LM-lag at an SLX panel (H₀: ρ = 0, robust to a local λ). |
|
Robust panel LM-WX at a SAR panel (H₀: θ = 0, robust to a local λ). |
|
Robust panel LM-error at an SLX panel (H₀: λ = 0, robust to a local ρ). |
|
Robust panel LM-error at a SAR panel (H₀: λ = 0, robust to a local θ). |
|
Robust panel LM-lag at an OLS or SEM panel (H₀: ρ = 0, robust to a local θ). |
|
Robust panel LM-WX at an OLS or SEM panel (H₀: θ = 0, robust to a local ρ). |
Flow Bayesian LM Tests¶
LM test for an omitted destination lag at an OLSFlow fit (H₀: ρ_d = 0). |
|
|
LM test for an omitted origin lag at an OLSFlow fit (H₀: ρ_o = 0). |
|
LM test for an omitted network lag at an OLSFlow fit (H₀: ρ_w = 0). |
|
Joint LM test at an OLSFlow fit (H₀: ρ_d = ρ_o = ρ_w = 0). |
Robust LM test for the destination lag at an OLSFlow fit. |
|
Robust LM test for the origin lag at an OLSFlow fit. |
|
Robust LM test for the network lag at an OLSFlow fit. |
|
LM test for an omitted destination lag at an |
|
LM test for an omitted origin lag at an |
|
LM test for an omitted network lag at an |
|
Joint LM test at an |
|
Robust LM test for the destination lag at an |
|
Robust LM test for the origin lag at an |
|
Robust LM test for the network lag at an |
Diagnostic Test Suites¶
Pre-bundled collections of LM tests used by model.spatial_diagnostics()
and the decision-tree renderers.
|
Named, immutable registry of Bayesian LM specification tests. |
|
Return the |
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
|
Named, immutable registry of Bayesian LM specification tests. |
Bayesian Model Comparison¶
|
Compare a collection of fitted Bayesian models. |
|
Compute all pairwise Bayes factors for a set of Bayesian models. |
MCMC Efficiency¶
|
Summary of MCMC sampling-efficiency checks for a spatial model. |
|
Run MCMC adequacy checks on a fitted Bayesian spatial model. |
Spatial Cross-Validation¶
|
Result of |
|
Spatial block cross-validation for a fitted Bayesian spatial model. |
Data Generating Processes¶
Note
The cross-sectional and (scalar) panel DGP simulators accept W
(Graph/sparse/dense) and gdf inputs. You may provide both
together; in that case W is used for simulation and is checked
against gdf for dimensional compatibility (a ValueError is
raised when they do not describe the same number of spatial units).
The flow DGPs below take G (libpysal Graph), gdf, n, and
knn_k instead. All four are optional: when none is supplied the
DGP synthesises a point grid via
synth_point_geodataframe() and builds a
row-standardised KNN graph automatically.
Each simulator draws from the model class it is named for and takes the
same design arguments: T (with N) for a panel, unit_effects and
time_effects (scaled by unit_effect_sd and time_effect_sd,
default 0.5), and dynamic. Fixed and random unit effects draw the same
data; the distinction belongs to the model.
|
Simulate data from a non-spatial OLS DGP |
|
Simulate data from SLX DGP |
|
Simulate data from SAR DGP |
|
Simulate data from SEM DGP |
|
Simulate data from SDM DGP |
|
Simulate data from SDEM DGP |
|
Simulate left-censored SAR Tobit data. |
|
Simulate left-censored SEM Tobit data. |
|
Simulate left-censored SDM Tobit data. |
|
Simulate an aspatial logit: |
|
Simulate SAR-logit binary outcome data. |
|
Simulate the latent SEM logit that |
|
Simulate the latent SDEM logit that |
|
Simulate an aspatial probit: |
|
Simulate the SAR probit that |
|
Simulate the SEM probit that |
|
Simulate the latent SDEM probit that |
|
Simulate an aspatial NB2 regression: |
|
Simulate data from the reduced-form SAR-NB2 that |
|
Simulate the latent SEM negative binomial that |
|
Simulate the latent SDEM negative binomial that |
|
Simulate an aspatial ZINB panel: |
|
Simulate data from a zero-inflated SAR-NB DGP. |
|
Simulate an aspatial hurdle NB panel: |
|
Simulate a reduced-form SAR hurdle NB cross-section. |
|
Simulate nested levels with a graph and a process at each. |
Flow Data Generating Processes¶
Each flow DGP accepts n, G, gdf, and knn_k as optional
arguments and (unless gamma_dist=0.0) appends a log_distance
column log(1 + d_{ij}) with default coefficient gamma_dist=-0.5.
Each flow simulator takes separable, T, pair_effects, and
time_effects as its model class does. The Gaussian flow DGPs
(simulate_sar_flow and simulate_sem_flow) default to
distribution="lognormal", returning strictly-positive flows
y = exp(eta) where eta is the latent SAR-filtered linear
predictor (also exposed in the result dict as "eta_vec" /
"eta"). Pass distribution="normal" to recover the legacy
Gaussian-on-y behaviour. The Gaussian-likelihood flow models in
neighbayes.models.flow operate on the latent scale, so fit on
np.log(y) to recover the SAR parameters. The Negative
Binomial DGPs are unchanged.
|
Simulate an aspatial Gaussian flow model: |
|
Simulate flow data from a SAR flow model. |
|
Simulate flow data from a spatial-error (SEM) flow model. |
|
Simulate an aspatial NB flow model: |
|
Generate synthetic O-D flow counts from an NB2 SAR flow DGP. |
|
Generate synthetic O-D flow counts from a Poisson SAR flow DGP. |
|
Simulate the ZINB flow model with SAR dependence. |
|
Simulate the hurdle NB flow model with SAR dependence. |
Graph Utilities¶
|
Combined design matrix for an O-D flow regression. |
|
Build a flow regression design matrix from regional attribute data. |
|
Build a flow design matrix with different numbers of dest/origin variables. |
|
Build a flow design matrix with separate destination and origin data. |
Build all three N×N flow weight matrices from a single Graph. |
|
Build the N×N destination weight matrix \(W_d = I_n \otimes W\). |
|
Build the N×N origin weight matrix \(W_o = W \otimes I_n\). |
|
|
Build the N×N origin–destination weight matrix \(W_w = W \otimes W\). |
Runtime Configuration¶
Opt-in helpers that change how fits run, not what they estimate: a persistent compile cache, and on-disk checkpoints that let a long JAX Gibbs fit resume after a crash with the draws it would have returned uninterrupted.
|
Save long JAX Gibbs fits to disk as they run, and resume them after a crash. |
|
Enable persistent on-disk compile caches for JAX and PyTensor. |