neighbayes.dgp.simulate_sar_zinb

neighbayes.dgp.simulate_sar_zinb(n=None, W=None, gdf=None, rho=0.5, lam=0.3, beta=None, gamma=None, alpha=2.0, Z=None, X=None, W_sel=None, rng=None, seed=None, contiguity='queen', target_pi=None, err_hetero=False, create_gdf=False, geometry_type='polygon')[source]

Simulate data from a zero-inflated SAR-NB DGP.

Two-equation model:

Selection (corridor activity — SAR-logit):

\[d_i \sim \text{Bernoulli}(\text{logit}^{-1}(\eta^{\text{sel}}_i)), \quad \eta^{\text{sel}} = (I - \lambda W_{\text{sel}})^{-1}(Z\gamma + \nu)\]

where \(\nu \sim N(0, I)\).

Count (flow volume — reduced-form SAR-NB):

\[y_i \mid d_i = 1 \sim \text{NegBin}(\exp(\eta^{\text{cnt}}_i), \alpha), \quad \eta^{\text{cnt}} = (I - \rho W_{\text{cnt}})^{-1} X\beta\]

Observation:

\[y_i = 0 \text{ if } d_i = 0, \quad y_i \sim \text{NegBin}(\cdot) \text{ if } d_i = 1\]
Parameters:
n : int, optional

Square-grid side length. Generates n * n observations.

W : Graph or array-like, optional

Spatial weights for the count equation. Also used for the selection equation when W_sel is not provided.

gdf : GeoDataFrame, optional

Geodataframe used to construct weights.

rho : float, default 0.5

Spatial autoregressive parameter for the count equation.

lam : float, default 0.3

Spatial autoregressive parameter for the selection equation.

beta : ndarray, optional

Count equation coefficients (including intercept). Defaults to [1.0, 0.6].

gamma : ndarray, optional

Selection equation coefficients (including intercept). Defaults to [0.3, 1.0].

alpha : float, default 2.0

NB2 dispersion parameter. Must be strictly positive.

Z : ndarray, optional

Selection covariate matrix of shape (nobs, p). If not provided, a random design matrix is generated from gamma.

X : ndarray, optional

Count covariate matrix of shape (nobs, k). If not provided, a random design matrix is generated from beta.

W_sel : Graph or array-like, optional

Spatial weights for the selection equation. If None, uses W (same weights for both equations).

rng : numpy.random.Generator, optional

Random number generator.

seed : int, optional

Random seed (used only if rng is None).

contiguity : str, default "queen"

Contiguity type for constructing W when n is given.

target_pi : float, optional

If given, an intercept shift is solved so that the marginal corridor activation probability mean(pi) == target_pi. The shift is added to gamma[0].

err_hetero : bool, default False

Not implemented for ZINB models. If True, a warning is issued and the parameter is ignored (homoskedastic errors are used).

create_gdf : bool, default False

Whether to attach a GeoDataFrame to the output.

geometry_type : str, default "polygon"

Type of geometry for the GeoDataFrame.

Returns:

Keys: y, d, X, Z, eta_cnt, eta_sel, W_dense, W_graph, W_sel_dense, W_sel_graph, params_true.

Return type:

dict