Utils¶
General utilities for xlogit library.
- xlogit.utils.wide_to_long(dataframe, id_col, alt_list, alt_name, varying=None, sep='_', alt_is_prefix=False, empty_val=nan)¶
Reshapes pandas DataFrame from wide to long format.
- Parameters
dataframe (pandas DataFrame) – The wide-format DataFrame.
id_col (str) – Column that uniquely identifies each sample.
alt_list (list-like) – List of choice alternatives.
alt_name (str) – Name of the alternatives column in returned dataset.
varying (list-like) – List of column names that vary across alternatives.
sep (str, default='_') – Separator of column names that vary across alternatives.
avail (array-like, shape (n_samples,), default=None) – Availability of alternatives for the choice situations. One when available or zero otherwise.
alt_is_prefix (bool) – True if alternative is prefix of the variable name or False if it is suffix.
empty_val (int, float or str, default=np.nan) – Value to fill when alternative not available for a certain variable.
- Returns
- Return type
DataFrame in long format.
- xlogit.utils.lrtest(general_model, restricted_model)¶
Conducts likelihood-ratio test.
- Parameters
general_model (xlogit Model) – Fitted model that contains all parameters (unrestricted)
restricted_model (xlogit Model) – Fitted model with less parameters than
general_model.
- Returns
lrtest_result – p-value result, chisq statistic, and degrees of freedom used in test
- Return type
dict