neighbayes.dgp.simulate_sar_negbin

neighbayes.dgp.simulate_sar_negbin(n_side=None, W=None, gdf=None, rho=0.5, beta=None, alpha=2.0, err_hetero=False, rng=None, seed=None, contiguity='queen', create_gdf=False, geometry_type='polygon', latent=True, *, T=None, N=None, unit_effects=None, time_effects=False, unit_effect_sd=None, time_effect_sd=None)[source]

Simulate data from the reduced-form SAR-NB2 that SARNegBin fits.

\[\eta = (I - \rho W)^{-1} X\beta, \quad \mu = \exp(\eta)\]

With T (and N) it draws the SARNegBin panel, whose random unit effects (unit_effects="random") enter inside the filter. With latent=True, the default, it draws the latent SAR that the unmarked SARNegBin fits, whose filter propagates the negative binomial’s gamma disturbance:

\[\eta = (I - \rho W)^{-1}(X\beta + \varepsilon), \quad \varepsilon_i = \log\gamma_i,\; \gamma_i \sim \mathrm{Gamma}(\alpha, \alpha), \quad y_i \sim \mathrm{Poisson}(e^{\eta_i}).\]

Counts are sampled as NB2:

\[y_i \sim \mathrm{NegBin}(\mu_i, \alpha), \;\;\mathrm{Var}(y_i)=\mu_i+\mu_i^2/\alpha.\]
Parameters:
n_side : int, optional

Side length of the square rook grid used when neither W nor gdf is supplied; the grid has n_side**2 observations. When W or gdf is provided, n_side**2 (if given) must match the number of units.

W : Graph or array-like, optional

Spatial weights.

gdf : GeoDataFrame, optional

Geodataframe used to construct weights.

rho : float, default 0.5

Spatial autoregressive parameter.

beta : ndarray, optional

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

alpha : float, default 2.0

NB2 dispersion parameter. Must be strictly positive.

err_hetero : bool, default False

Scale the latent SAR’s disturbances by the norm of each row of X. The reduced form has no disturbance, so it ignores the flag with a warning.

rng : numpy.random.Generator, optional

Random number generator.

seed : int, optional

Random seed (used only if rng is None).

contiguity : str, default "queen"

Neighbor rule used when W is built from gdf.

create_gdf : bool, default False

Whether to attach a GeoDataFrame to the output.

geometry_type : str, default "polygon"

Type of geometry for the GeoDataFrame.

latent : bool, default True

The latent SAR, whose eta_true is the log-mean; False draws the reduced form.

Returns:

Dictionary with keys y, X, mu, W_sparse, W_graph, and params_true (and eta_true when latent).

Return type:

dict