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])

Dynamic panel regression without contemporaneous spatial dependence.

SDMRPanelDynamic(*args[, model])

Dynamic restricted spatial Durbin panel regression.

SDMUPanelDynamic(*args[, model])

Dynamic unrestricted spatial Durbin panel regression.

SARPanelDynamic(*args[, model])

Dynamic spatial-lag panel regression.

SEMPanelDynamic(*args[, model])

Dynamic spatial-error panel regression.

SDEMPanelDynamic(*args[, model])

Dynamic spatial Durbin error panel regression.

SLXPanelDynamic(*args[, model])

Dynamic SLX panel regression.

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])

Bayesian spatial lag panel Tobit model.

SEMPanelTobit(*args[, censoring])

Bayesian spatial error panel Tobit model.

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).

bayesian_lm_sdm_joint_test(model)

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

bayesian_lm_slx_error_joint_test(model)

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

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 γ).

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_robust_lm_lag_sdm_test(model)

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

bayesian_panel_robust_lm_wx_test(model)

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

bayesian_panel_robust_lm_error_sdem_test(model)

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

bayesian_panel_lm_wx_sem_test(model)

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

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

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

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

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|.

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 ILU-based approximate log-determinant grid (MATLAB lndetichol analog).

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

Compute exact sparse-LU log-determinant grid (MATLAB lndetfull style).

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

Compute spline-interpolated log-determinant grid (MATLAB lndetint style).

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\).