bayespecon.models.SpatialProbit

class bayespecon.models.SpatialProbit(formula=None, data=None, y=None, X=None, W=None, region_col=None, region_ids=None, mobs=None, priors=None, robust=False)[source]

Bayesian spatial probit with regional random effects.

Parameters:
formula : str, optional

Formula for the binary response model, e.g. "y ~ x1 + x2". Requires data and region_col.

data : pandas.DataFrame, optional

Data source used with formula mode.

y : array-like, optional

Binary dependent variable (0/1), required in matrix mode.

X : array-like or pandas.DataFrame, optional

Covariate matrix, required in matrix mode.

W : libpysal.graph.Graph or scipy.sparse matrix

Region-level m x m spatial weights matrix. Accepts a libpysal.graph.Graph (the modern libpysal graph API) or any scipy.sparse matrix. The legacy libpysal.weights.W object is not accepted directly; pass w.sparse or convert with libpysal.graph.Graph.from_W(w). W should be row-standardised; a UserWarning is raised if not.

region_col : str, optional

Region identifier column in data (formula mode).

region_ids : array-like, optional

Region identifier per observation (matrix mode).

mobs : array-like, optional

Region observation counts (m,) in sorted region order (matrix mode alternative to region_ids).

priors : dict, optional

Prior overrides.

Notes

This class follows the core semip_g structure (binary response with spatially dependent regional effects). It uses a standard probit link with unit observation-level variance and does not currently sample the v_i/ r heteroskedastic hierarchy from MATLAB semip_g.

Priors (priors keys):

  • rho_lower, rho_upper: bounds for rho (default -0.95, 0.95)

  • beta_mu, beta_sigma: Normal prior for beta

  • sigma_a_sigma: HalfNormal scale for sigma_a

Robust regression

robust=True is not supported for SpatialProbit. The probit link function uses a Normal CDF; a robust version would require a Student-t CDF link, which is not yet implemented. Use robust=True with Gaussian models (OLS, SAR, SEM, etc.) instead.

__init__(formula=None, data=None, y=None, X=None, W=None, region_col=None, region_ids=None, mobs=None, priors=None, robust=False)[source]

Methods

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

fit([draws, tune, chains, target_accept, ...])

Draw samples from the posterior.

fitted_probabilities()

Return posterior mean fitted probabilities for observed data.

random_effects_mean()

Return posterior mean regional effects.

summary([var_names])

Return posterior summary table.

Attributes

pymc_model

Return the PyMC model object built for the most recent fit.

fit(draws=2000, tune=1000, chains=4, target_accept=0.9, random_seed=None, **sample_kwargs)[source]

Draw samples from the posterior.

fitted_probabilities()[source]

Return posterior mean fitted probabilities for observed data.

property pymc_model : pymc.model.core.Model | None[source]

Return the PyMC model object built for the most recent fit.

Returns:

The model object used by fit(), or None if the instance has not been fit yet.

Return type:

pymc.Model or None

random_effects_mean()[source]

Return posterior mean regional effects.

summary(var_names=None, **kwargs)[source]

Return posterior summary table.