ergmx.ErgmFit#

class ergmx.ErgmFit(model, estimate, mple, control, seed)[source]#

A fitted ERGM, as returned by ergmx.ergm().

Print summary() for the table of coefficients, like R’s summary(fit); check the fit with mcmc_diagnostics() and gof(); compare it with others with ergmx.compare().

save(path)[source]#

Save the fit to a file, to reload with ergmx.load_fit(): its model and network, estimates, MCMC sample and settings, with Python’s pickle (so only load files you trust).

property names#

Names of the coefficients, as in ergm.

property params#

The estimated coefficients.

property coef#

The estimated coefficients by name.

property cov#

Covariance matrix of the estimates, including MCMC error.

property stderr#

Standard errors by name, including MCMC error (NaN for fixed coefficients).

property offset#

Whether each coefficient is fixed by offset() rather than estimated.

property constraints#

The model’s sample space constraints.

property mple#

The maximum pseudo-likelihood estimate, the starting point of the MCMC MLE.

property method#

"MLE" (exact, for dyad-independent models), "MCMLE", "MPLE" or "CD".

property iterations#

Iterations of the Monte Carlo MLE (or of contrastive divergence).

property converged#

Whether the estimation met its convergence criterion.

property loglik#

exact for dyad-independent models, estimated by path sampling for the others (None if fitted with eval_loglik=False).

Type:

Log-likelihood

property loglik_se#

Monte Carlo standard error of the log-likelihood (0 if exact).

property loglik_relative#

Whether the log-likelihood is relative to the null model (the uniform distribution on the networks the constraints allow), as with dyad-dependent constraints in ergm. Relative log-likelihoods compare models with the same constraints.

property df#

Number of estimated coefficients (offsets and constant statistics excluded).

property formula#

The model’s terms.

property aic#

Akaike’s information criterion, -2 loglik + 2 p.

property bic#

Bayesian information criterion, -2 loglik + p log(number of free observed dyads), as in ergm.

property sample#

Statistics sampled in the last iteration (chains x samples x statistics).

property observed#

Statistics of the observed network (for curved terms, the counts their parameters weight).

simulate(nsim=1, *, seed=None, output='network', time_slices=None, nw_start='last', **options)[source]#

Simulate networks from the fitted model, starting from the observed one.

See ergmx.simulate(). For a model fitted to a series of networks (ergmx.tergm()), time_slices= simulates the process forward in time from the network nw_start instead, as tergm’s simulate(fit, nw.start=, time.slices=): "last" (the default) or "first" network of the series, its 1-based position, or a network. See ergmx.simulate_dynamic(), whose options apply.

mcmc_diagnostics()[source]#

Diagnostics of the MCMC sample of the last iteration, like R’s mcmc.diagnostics(). Print the result, or call its plot().

gof(nsim=100, **options)[source]#

Goodness of fit of the model. See ergmx.gof().

summary()[source]#

The table of coefficients, standard errors and tests, with the log-likelihood, AIC and BIC. Print it (it prints itself in notebooks).

to_frame()[source]#

The table of coefficients as a pandas DataFrame (needs pandas), with R’s columns: Estimate, Std. Error, MCMC %, z value and Pr(>|z|).

predict(conditional=True, type='response', nsim=100, *, seed=None, **options)[source]#

Tie probabilities of every dyad, as R’s predict(fit).

With conditional=True, each dyad’s probability of a tie given the rest of the observed network, computed exactly from its change statistics (type="link" for the log-odds); with conditional=False, the share of nsim networks simulated from the model in which the dyad is a tie. As in ergm, conditional probabilities ignore the sample space constraints, and dyads whose value is missing are predicted too; unconditional ones are simulated with the model’s constraints (ergm ignores them).

Returns:

TiePredictions – tail, head and p arrays, with .matrix(), .mean_by(attribute) and .to_frame().

marginal_effects()[source]#

Average marginal effects on the tie probability, as R’s ergMargins (ergm.AME()): for each estimated parameter, the change in a dyad’s conditional tie probability per unit of the term’s statistic, theta * p (1 - p), averaged over the dyads, with its delta-method standard error. (ergMargins holds the probabilities fixed in the delta method; ergmx also counts how they change with the parameters.) Curved terms’ decays have no marginal effect.

Returns:

NumericTable – Columns AME, Delta SE, Z and P; .to_frame() for pandas.

odds_ratios(level=0.95)[source]#

Odds ratios, exp(coefficient), with Wald confidence intervals: the factor by which a unit increase in a term’s statistic multiplies the conditional odds of a tie.

confint(level=0.95)[source]#

Wald confidence intervals of the estimated coefficients, as R’s confint(fit).