MutinomialLogit

Implements all the logic for multinomial and conditional logit models.

class xlogit.multinomial_logit.MultinomialLogit

Class for estimation of Multinomial and Conditional Logit Models.

coeff_

Estimated coefficients

Type

numpy array, shape (n_variables)

coeff_names

Names of the estimated coefficients

Type

numpy array, shape (n_variables)

stderr

Standard errors of the estimated coefficients

Type

numpy array, shape (n_variables)

zvalues

Z-values for t-distribution of the estimated coefficients

Type

numpy array, shape (n_variables)

pvalues

P-values of the estimated coefficients

Type

numpy array, shape (n_variables)

loglikelihood

Log-likelihood at the end of the estimation

Type

float

convergence

Whether convergence was reached during estimation

Type

bool

total_iter

Total number of iterations executed during estimation

Type

int

estim_time_sec

Estimation time in seconds

Type

float

sample_size

Number of samples used for estimation

Type

int

aic

Akaike information criteria of the estimated model

Type

float

bic

Bayesian information criteria of the estimated model

Type

float

fit(X, y, varnames, alts, ids, isvars=None, weights=None, avail=None, base_alt=None, fit_intercept=False, init_coeff=None, maxiter=2000, random_state=None, tol_opts=None, verbose=1, robust=False, num_hess=True, scale_factor=None, addit=None, skip_std_errs=False)

Fit multinomial and/or conditional logit models.

Parameters
  • X (array-like, shape (n_samples*n_alts, n_variables)) – Input data for explanatory variables in long format

  • y (array-like, shape (n_samples*n_alts,)) – Chosen alternatives or one-hot encoded representation of the choices

  • varnames (list, shape (n_variables,)) – Names of explanatory variables that must match the number and order of columns in X

  • alts (array-like, shape (n_samples*n_alts,)) – Alternative values in long format

  • ids (array-like, shape (n_samples*n_alts,)) – Identifiers for the samples in long format.

  • isvars (list, default=None) – Names of individual-specific variables in varnames

  • weights (array-like, shape (n_variables,), default=None) – Weights for the choice situations in long format.

  • avail (array-like, shape (n_samples*n_alts,), default=None) – Availability of alternatives for the samples. One when available or zero otherwise.

  • addit (array-like, shape (n_samples*n_alts, ), default=None) – Additive term to model coefficients kept fixed during estimation.

  • base_alt (int, float or str, default=None) – Base alternative

  • fit_intercept (bool, default=False) – Whether to include an intercept in the model.

  • init_coeff (numpy array, shape (n_variables,), default=None) – Initial coefficients for estimation.

  • maxiter (int, default=200) – Maximum number of iterations

  • robust (bool, default=False) – Whether robust standard errors should be computed

  • num_hess (bool, default=False) – Whether numerical hessian should be used for estimation of standard errors

  • skip_std_errs (bool, default=False) – Whether estimation of standard errors should be skipped

  • random_state (int, default=None) – Random seed for numpy random generator

  • tol_opts (dict, default=None) –

    Options for tolerance of optimization routine. The dictionary accepts the following options (keys):

    ftolfloat, default=1e-10

    Tolerance for objective function (log-likelihood)

  • verbose (int, default=1) – Verbosity of messages to show during estimation. 0: No messages, 1: Some messages, 2: All messages

Returns

Return type

None.

predict(X, varnames, alts, ids, isvars=None, weights=None, avail=None, random_state=None, verbose=1, return_proba=False, return_freq=False, scale_factor=None, addit=None)

Predict chosen alternatives.

Parameters
  • X (array-like, shape (n_samples*n_alts, n_variables)) – Input data for explanatory variables in long format

  • varnames (list, shape (n_variables,)) – Names of explanatory variables that must match the number and order of columns in X

  • alts (array-like, shape (n_samples*n_alts,)) – Alternative values in long format

  • ids (array-like, shape (n_samples*n_alts,)) – Identifiers for the samples in long format.

  • isvars (list) – Names of individual-specific variables in varnames

  • weights (array-like, shape (n_variables,), default=None) – Sample weights in long format.

  • avail (array-like, shape (n_samples*n_alts,), default=None) – Availability of alternatives for the samples. One when available or zero otherwise.

  • addit (array-like, shape (n_samples*n_alts, ), default=None) – Additive term to model coefficients kept fixed during estimation.

  • random_state (int, default=None) – Random seed for numpy random generator

  • verbose (int, default=1) – Verbosity of messages to show during estimation. 0: No messages, 1: Some messages, 2: All messages

  • return_proba (bool, default=False) – If True, also return the choice probabilities

  • return_freq (bool, default=False) – If True, also return the choice frequency for the alternatives

Returns

  • choices (array-like, shape (n_samples, )) – Chosen alternative for every sample in the dataset.

  • proba (array-like, shape (n_samples, n_alts), optional) – Choice probabilities for each sample in the dataset. The alternatives are ordered (in the columns) as they appear in self.alternatives. Only provided if return_proba is True.

  • freq (dict, optional) – Choice frequency for each alternative. Only provided if return_freq is True.

summary()

Show estimation results in console.