API reference

Base Classes

SpatialModel([formula, data, y, X, W, ...])

Base class for Bayesian spatial regression models.

SpatialPanelModel([formula, data, y, X, W, ...])

Base class for static spatial panel models with FE transforms.

Cross Sectional Spatial Models

OLS([formula, data, y, X, W, priors, ...])

Bayesian ordinary least squares cross-sectional regression.

SAR([formula, data, y, X, W, priors, ...])

Bayesian Spatial Autoregressive (Spatial Lag) model.

SEM([formula, data, y, X, W, priors, ...])

Bayesian Spatial Error Model.

SLX([formula, data, y, X, W, priors, ...])

Bayesian SLX (Spatial Lag X) model.

SDM([formula, data, y, X, W, priors, ...])

Bayesian Spatial Durbin Model.

SDEM([formula, data, y, X, W, priors, ...])

Bayesian Spatial Durbin Error Model.

Panel Spatial Models

OLSPanelFE([formula, data, y, X, W, ...])

Bayesian pooled and fixed-effects linear panel regression.

SARPanelFE([formula, data, y, X, W, ...])

Bayesian spatial-lag panel regression.

SEMPanelFE([formula, data, y, X, W, ...])

Bayesian spatial-error panel regression.

SDMPanelFE([formula, data, y, X, W, ...])

Bayesian spatial Durbin panel regression.

SDEMPanelFE([formula, data, y, X, W, ...])

Bayesian spatial Durbin error panel regression.

SLXPanelFE([formula, data, y, X, W, ...])

Bayesian SLX panel regression.

Panel Spatial Models (Random Effects)

OLSPanelRE(**kwargs)

Bayesian random effects panel regression (non-spatial).

SARPanelRE(**kwargs)

Bayesian spatial lag panel model with unit random effects.

SEMPanelRE(**kwargs)

Bayesian spatial error panel model with unit random effects.

SDEMPanelRE(**kwargs)

Bayesian spatial Durbin error panel model with unit random effects.

Dynamic Panel Spatial Models

OLSPanelDynamic(*args[, model])

SDMRPanelDynamic(*args[, model])

SDMUPanelDynamic(*args[, model])

SARPanelDynamic(*args[, model])

SEMPanelDynamic(*args[, model])

SDEMPanelDynamic(*args[, model])

SLXPanelDynamic(*args[, model])

Non-Linear Spatial Models

SpatialProbit([formula, data, y, X, W, ...])

Bayesian spatial probit with regional random effects.

SARTobit(*args[, censoring])

Bayesian spatial autoregressive Tobit model.

SEMTobit(*args[, censoring])

Bayesian spatial error Tobit model.

SDMTobit(*args[, censoring])

Bayesian spatial Durbin Tobit model.

Panel Spatial Models (Tobit)

SARPanelTobit(*args[, censoring])

SEMPanelTobit(*args[, censoring])

Flow Models

FlowModel(y, G, X[, col_names, k, priors, ...])

Abstract base class for Bayesian spatial flow regression models.

OLSFlow(y, G, X, **kwargs)

Non-spatial Bayesian OD-flow gravity model (independence baseline).

PoissonFlow(y, G, X, **kwargs)

Non-spatial Bayesian OD-flow Poisson gravity model (count baseline).

SARFlow(y, G, X[, col_names, k, priors, ...])

Bayesian SAR flow model with three free spatial autoregressive parameters.

SARFlowSeparable(y, G, X, **kwargs)

Bayesian separable SAR flow model with ρ_w = −ρ_d · ρ_o.

PoissonSARFlow(y, G, X, **kwargs)

Bayesian SAR flow model with a Poisson observation distribution.

PoissonSARFlowSeparable(y, G, X, **kwargs)

Bayesian separable SAR flow model with a Poisson observation distribution.

SEMFlow(y, G, X, **kwargs)

Bayesian spatial-error flow model with three free spatial parameters.

SEMFlowSeparable(y, G, X, **kwargs)

Bayesian separable spatial-error flow model with \(\lambda_w = -\lambda_d \lambda_o\).

Panel Flow Models

FlowPanelModel(y, G, X, T[, col_names, k, ...])

Abstract base class for balanced panel spatial flow models.

OLSFlowPanel(y, G, X, T, **kwargs)

Non-spatial Bayesian OD-flow gravity model for balanced panel data.

PoissonFlowPanel(y, G, X, T, **kwargs)

Non-spatial Bayesian OD-flow Poisson gravity model for balanced panel data.

SARFlowPanel(y, G, X, T[, col_names, k, ...])

Panel spatial-lag origin-destination flow model with unrestricted dependence.

SARFlowSeparablePanel(y, G, X, **kwargs)

Panel separable spatial-lag flow model with \(\rho_w = -\rho_d \rho_o\).

PoissonSARFlowPanel(y, G, X, **kwargs)

Panel Poisson spatial-lag flow model with unrestricted dependence.

PoissonSARFlowSeparablePanel(y, G, X, **kwargs)

Panel separable Poisson spatial-lag flow model.

SEMFlowPanel(y, G, X, T, **kwargs)

Panel spatial-error flow model with three free spatial parameters.

SEMFlowSeparablePanel(y, G, X, T, **kwargs)

Panel separable spatial-error flow model with \(\lambda_w = -\lambda_d \lambda_o\).

Bayesian Diagnostics

BayesianLMTestResult(lm_samples, mean, ...)

Container for Bayesian LM test results.

bayesian_lm_lag_test(model)

Bayesian LM test for omitted spatial lag (SAR) model.

bayesian_lm_error_test(model)

Bayesian LM test for omitted spatial error (SEM) model.

bayesian_lm_wx_test(model)

Bayesian LM test for WX coefficients (H₀: γ = 0 | SAR).

bayesian_lm_sdm_joint_test(model)

Bayesian joint LM test for SDM (H₀: ρ = 0 AND γ = 0 | OLS).

bayesian_lm_slx_error_joint_test(model)

Bayesian joint LM test for SDEM (H₀: λ = 0 AND γ = 0 | OLS).

bayesian_lm_error_from_sar_test(model)

Bayesian LM-Error test from a SAR posterior (H₀: λ = 0 | SAR).

bayesian_lm_error_sdm_test(model)

Bayesian LM-Error test from an SDM posterior (H₀: λ = 0 | SDM).

bayesian_lm_lag_sdem_test(model)

Bayesian LM-Lag test from an SDEM posterior (H₀: ρ = 0 | SDEM).

bayesian_lm_wx_sem_test(model)

Bayesian LM test for WX coefficients in SEM (H₀: γ = 0 | SEM).

bayesian_robust_lm_lag_test(model)

Bayesian robust LM-Lag test (H₀: ρ = 0, robust to local λ).

bayesian_robust_lm_error_test(model)

Bayesian robust LM-Error test (H₀: λ = 0, robust to local ρ).

bayesian_robust_lm_lag_sdm_test(model)

Bayesian robust LM-Lag test in SDM context (H₀: ρ = 0, robust to γ).

bayesian_robust_lm_wx_test(model)

Bayesian robust LM-WX test (H₀: γ = 0, robust to ρ).

bayesian_robust_lm_error_sdem_test(model)

Bayesian robust LM-Error test in SDEM context (H₀: λ = 0, robust to γ).

bayesian_robust_lm_error_sar_test(model)

Bayesian robust LM-Error test in SAR context (H₀: λ = 0 | SAR).

bayesian_robust_lm_error_sdm_test(model)

Bayesian robust LM-Error test in SDM context (H₀: λ = 0 | SDM).

bayesian_robust_lm_lag_sdem_test(model)

Bayesian robust LM-Lag test in SDEM context (H₀: ρ = 0 | SDEM).

bayesian_robust_lm_lag_sem_test(model)

Bayesian robust LM-Lag test in SEM context (H₀: ρ = 0 | SEM).

bayesian_robust_lm_wx_sem_test(model)

Bayesian robust LM-WX test in SEM context (H₀: γ = 0 | SEM).

Panel Bayesian LM Tests

bayesian_panel_lm_lag_test(model)

Bayesian panel LM test for omitted spatial lag (H₀: ρ = 0).

bayesian_panel_lm_error_test(model)

Bayesian panel LM test for omitted spatial error (H₀: λ = 0).

bayesian_panel_robust_lm_lag_test(model)

Bayesian panel robust LM-Lag test (H₀: ρ = 0, robust to λ).

bayesian_panel_robust_lm_error_test(model)

Bayesian panel robust LM-Error test (H₀: λ = 0, robust to ρ).

bayesian_panel_lm_wx_test(model)

Bayesian panel LM test for WX coefficients (H₀: γ = 0).

bayesian_panel_lm_sdm_joint_test(model)

Bayesian panel joint LM test for SDM (H₀: ρ = 0 AND γ = 0).

bayesian_panel_lm_slx_error_joint_test(model)

Bayesian panel joint LM test for SDEM (H₀: λ = 0 AND γ = 0).

bayesian_panel_lm_error_sdm_test(model)

Panel LM-Error test from an SDM panel posterior (H₀: λ = 0 | SDM).

bayesian_panel_lm_lag_sdem_test(model)

Panel LM-Lag test from an SDEM panel posterior (H₀: ρ = 0 | SDEM).

bayesian_panel_lm_wx_sem_test(model)

Bayesian panel LM test for WX coefficients in SEM (H₀: γ = 0 | SEM).

bayesian_panel_robust_lm_lag_sdm_test(model)

Bayesian panel robust LM-Lag in SDM context (H₀: ρ = 0 | SLX panel).

bayesian_panel_robust_lm_wx_test(model)

Bayesian panel robust LM-WX (H₀: γ = 0 | SAR panel, robust to ρ).

bayesian_panel_robust_lm_error_sdem_test(model)

Bayesian panel robust LM-Error in SDEM context (H₀: λ = 0 | SLX panel).

Flow Bayesian LM Tests

bayesian_lm_flow_dest_test(model)

Bayesian LM test for an omitted destination-side spatial lag.

bayesian_lm_flow_orig_test(model)

Bayesian LM test for an omitted origin-side spatial lag (\(H_0\colon \rho_o = 0\)).

bayesian_lm_flow_network_test(model)

Bayesian LM test for an omitted network spatial lag (\(H_0\colon \rho_w = 0\)).

bayesian_lm_flow_intra_test(model)

Bayesian LM (WX-style) test for the intra block in an OLSFlow null.

bayesian_lm_flow_joint_test(model)

Joint Bayesian LM test for the SARFlow filter (\(H_0\colon \rho_d = \rho_o = \rho_w = 0\)).

bayesian_robust_lm_flow_dest_test(sarflow_model)

Robust Bayesian LM test for \(\rho_d\) adjusting for \((\rho_o, \rho_w)\) nuisance via the Neyman-orthogonal score (Bera and Yoon [1993], Anselin et al. [1996], Doğan et al. [2021]).

bayesian_robust_lm_flow_orig_test(sarflow_model)

Robust Bayesian LM test for \(\rho_o\) adjusting for \((\rho_d, \rho_w)\) nuisance.

bayesian_robust_lm_flow_network_test(...)

Robust Bayesian LM test for \(\rho_w\) adjusting for \((\rho_d, \rho_o)\) nuisance.

bayesian_panel_lm_flow_dest_test(model)

Panel analogue of bayesian_lm_flow_dest_test() operating on a fitted OLSFlowPanel.

bayesian_panel_lm_flow_orig_test(model)

Panel analogue of bayesian_lm_flow_orig_test() (\(H_0\colon \rho_o = 0\)).

bayesian_panel_lm_flow_network_test(model)

Panel analogue of bayesian_lm_flow_network_test() (\(H_0\colon \rho_w = 0\)).

bayesian_panel_lm_flow_intra_test(model)

Panel analogue of bayesian_lm_flow_intra_test() on OLSFlowPanel.

bayesian_panel_lm_flow_joint_test(model)

Panel analogue of bayesian_lm_flow_joint_test() on OLSFlowPanel.

Diagnostic Test Suites

Pre-bundled collections of LM tests used by model.spatial_diagnostics() and the decision-tree renderers.

DiagnosticSuite(name, tests)

Named, immutable registry of Bayesian LM specification tests.

OLS_SUITE

Named, immutable registry of Bayesian LM specification tests.

OLS_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

SAR_SUITE

Named, immutable registry of Bayesian LM specification tests.

SAR_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

SAR_NEGBIN_SUITE

Named, immutable registry of Bayesian LM specification tests.

SAR_TOBIT_SUITE

Named, immutable registry of Bayesian LM specification tests.

SEM_SUITE

Named, immutable registry of Bayesian LM specification tests.

SEM_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

SEM_PANEL_DYNAMIC_SUITE

Named, immutable registry of Bayesian LM specification tests.

SLX_SUITE

Named, immutable registry of Bayesian LM specification tests.

SLX_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

SLX_PANEL_DYNAMIC_SUITE

Named, immutable registry of Bayesian LM specification tests.

SDM_SUITE

Named, immutable registry of Bayesian LM specification tests.

SDM_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

SDM_TOBIT_SUITE

Named, immutable registry of Bayesian LM specification tests.

SDEM_SUITE

Named, immutable registry of Bayesian LM specification tests.

SDEM_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

FLOW_SUITE

Named, immutable registry of Bayesian LM specification tests.

FLOW_INTRA_SUITE

Named, immutable registry of Bayesian LM specification tests.

FLOW_PANEL_SUITE

Named, immutable registry of Bayesian LM specification tests.

Bayesian Model Comparison

bayes_factor_compare_models(models[, ...])

Compute all pairwise Bayes factors for a set of Bayesian models.

bic_to_bf(bic_values[, denominator, log])

Convert BIC values to Bayes factors via the BIC-approximation method.

compile_log_posterior(pymc_model)

Compile a PyMC model's log-posterior into a callable for bridge sampling.

post_prob(logml_list[, model_names, prior_prob])

Compute posterior model probabilities from marginal likelihoods.

Log-Determinant Methods

Method resolution and bound handling

Positive-only methods (sparse_spline, grid_mc) auto-restrict the rho/lambda support to [1e-5, 1.0] when the prior or method default would otherwise admit negative values. Explicit rho_min/rho_max overrides still raise.

LogDetMethod(*values)

Canonical names for the log-determinant approximation methods.

LogdetBounds(method, rho_min, rho_max, source)

Resolved logdet method and rho interval used for approximation.

resolve_logdet_method(method, *, n)

Validate method and auto-select when None.

resolve_logdet_bounds(method, *, n[, eigs, ...])

Resolve method-specific rho bounds from defaults, priors, or overrides.

Builders

make_logdet_fn(W[, method, rho_min, rho_max, T])

Return a function (rho) -> pytensor log|I - rho*W| expression.

make_logdet_numpy_fn(W_sparse, eigs, method)

Return a pure-numpy (rho: float) -> float logdet evaluator.

make_logdet_numpy_vec_fn(W_sparse, eigs, method)

Return a vectorized numpy (rho_arr: np.ndarray) -> np.ndarray logdet evaluator.

Kernel evaluators and approximations

logdet_eigenvalue(rho, eigs)

Eigenvalue-based log|I - rho*W|.

logdet_exact(rho, W_dense)

Exact log|I - rho*W| as a pytensor expression.

logdet_chebyshev(rho, coeffs[, rmin, rmax])

Evaluate Chebyshev approximation of log|I - rho*W| symbolically.

logdet_interpolated(rho, W_dense[, rho_min, ...])

Cubic spline interpolation of log|I - rho*W|.

logdet_mc_poly_pytensor(rho, traces)

Evaluate Barry-Pace trace polynomial approximation of log|I - rho*W| symbolically.

mc(order, iter, W[, rmin, rmax, grid, ...])

Compute Monte Carlo log-determinant approximation (Barry and Kelley Pace [1999]).

chebyshev(W[, order, rmin, rmax, ...])

Compute Chebyshev approximation of log|I - rho*W| ([Pace and LeSage, 2004]).

ilu(W, lmin, lmax[, grid, drop_tol, fill_factor])

Compute an ILU-based approximate log-determinant grid.

sparse_grid(W, lmin, lmax[, grid])

Compute an exact sparse-LU log-determinant grid.

spline(W[, rmin, rmax, n_grid])

Compute a spline-interpolated log-determinant grid.

Flow log-determinants

flow_logdet_pytensor(rho_d, rho_o, rho_w, ...)

Differentiable PyTensor log-determinant for the flow SAR model.

flow_logdet_numpy(rho_d, rho_o, rho_w, ...)

Vectorised numpy port of flow_logdet_pytensor().

compute_flow_traces(W_sparse[, miter, ...])

Estimate tr(W^k) for k=1..miter via Barry-Pace stochastic traces.

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.

simulate_sar([n, W, gdf, rho, beta, sigma, ...])

Simulate data from SAR DGP y = (I-rho W)^(-1)(X beta + eps).

simulate_ols([n, W, gdf, beta, sigma, ...])

Simulate data from a non-spatial OLS DGP y = X beta + eps.

simulate_sem([n, W, gdf, lam, beta, sigma, ...])

Simulate data from SEM DGP y = X beta + (I-lam W)^(-1) eps.

simulate_slx([n, W, gdf, beta1, beta2, ...])

Simulate data from SLX DGP y = X beta1 + W X_no_intercept beta2 + eps.

simulate_sdm([n, W, gdf, rho, beta1, beta2, ...])

Simulate data from SDM DGP y = (I-rho W)^(-1)(Xb1 + WXb2 + eps).

simulate_sdem([n, W, gdf, lam, beta1, ...])

Simulate data from SDEM DGP y = Xb1 + WXb2 + (I-lam W)^(-1)eps.

simulate_sar_tobit(*[, censoring, err_hetero])

Simulate left-censored SAR Tobit data.

simulate_sem_tobit(*[, censoring, err_hetero])

Simulate left-censored SEM Tobit data.

simulate_sdm_tobit(*[, censoring, err_hetero])

Simulate left-censored SDM Tobit data.

simulate_spatial_probit([W, gdf, n, rho, ...])

Simulate SpatialProbit-style binary outcome data.

simulate_panel_ols_fe(N, T[, beta, sigma, ...])

Simulate pooled data compatible with OLSPanelFE model assumptions.

simulate_panel_sar_fe(N, T[, rho, beta, ...])

Simulate SAR panel data in time-first stacking order.

simulate_panel_sem_fe(N, T[, lam, beta, ...])

Simulate SEM panel data in time-first stacking order.

simulate_panel_sdm_fe(N, T[, rho, beta1, ...])

Simulate SDM panel FE data.

simulate_panel_sdem_fe(N, T[, lam, beta1, ...])

Simulate SDEM panel FE data.

simulate_panel_slx_fe(N, T[, beta1, beta2, ...])

Simulate SLX panel FE data.

simulate_panel_ols_re(*[, err_hetero])

Simulate OLS random-effects panel style data.

simulate_panel_sar_re(*[, err_hetero])

Simulate SAR random-effects panel style data.

simulate_panel_sem_re(*[, err_hetero])

Simulate SEM random-effects panel style data.

simulate_panel_dlm_fe(N, T[, phi, beta, ...])

Simulate dynamic non-spatial panel FE data.

simulate_panel_sdmr_fe(N, T[, rho, phi, ...])

Simulate dynamic restricted SDM panel FE data.

simulate_panel_sdmu_fe(N, T[, rho, phi, ...])

Simulate dynamic unrestricted SDM panel FE data.

simulate_panel_sar_dynamic_fe(N, T[, rho, ...])

Simulate dynamic SAR panel FE data.

simulate_panel_sem_dynamic_fe(N, T[, lam, ...])

Simulate dynamic SEM panel FE data.

simulate_panel_sdem_dynamic_fe(N, T[, lam, ...])

Simulate dynamic SDEM panel FE data.

simulate_panel_slx_dynamic_fe(N, T[, phi, ...])

Simulate dynamic SLX panel FE data.

simulate_panel_sar_tobit_fe(*[, censoring, ...])

Simulate left-censored panel SAR FE data.

simulate_panel_sem_tobit_fe(*[, censoring, ...])

Simulate left-censored panel SEM FE data.

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.

The Gaussian flow DGPs (generate_flow_data, generate_panel_flow_data and their separable variants) 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 bayespecon.models.flow operate on the latent scale, so fit on np.log(y) to recover the SAR parameters. The Poisson DGPs are unchanged.

generate_flow_data([n, G, rho_d, rho_o, ...])

Simulate flow data from a SAR flow model.

generate_flow_data_separable([n, G, rho_d, ...])

Simulate flow data from a separable SAR flow model.

generate_poisson_flow_data([n, k, k_d, k_o, ...])

Generate synthetic origin-destination flow count data for a Poisson spatial autoregressive flow model.

generate_poisson_flow_data_separable([n, k, ...])

Simulate Poisson flow count data from a separable SAR flow model.

generate_panel_flow_data([n, T, G, rho_d, ...])

Simulate panel flow data from a SAR flow model with unit effects.

generate_panel_flow_data_separable([n, T, ...])

Simulate panel flow data from a separable SAR flow model.

generate_panel_poisson_flow_data([n, T, G, ...])

Simulate panel Poisson flow data from a spatial autoregressive model.

generate_panel_poisson_flow_data_separable([...])

Simulate panel Poisson flow data from a separable SAR flow model.

Graph Utilities

FlowDesignMatrix(X_dest, X_orig, X_intra, ...)

Combined design matrix for an O-D flow regression.

flow_design_matrix(X[, col_names, dist, ...])

Build a flow regression design matrix from regional attribute data.

flow_design_matrix_with_orig(Xd, Xo[, ...])

Build a flow design matrix with separate destination and origin data.

flow_weight_matrices(G)

Build all three N×N flow weight matrices from a single Graph.

destination_weights(G)

Build the N×N destination weight matrix \(W_d = I_n \otimes W\).

origin_weights(G)

Build the N×N origin weight matrix \(W_o = W \otimes I_n\).

network_weights(G)

Build the N×N network weight matrix \(W_w = W \otimes W\).