Conditional logit
The standard McFadden conditional logit, which estimates single vector of taste parameters across the entire sample. Useful both as a baseline against richer models and as the inner kernel of the latent-class M-step.
Model
lcl.conditional_logit.ConditionalLogit(numeraire=None, numeraire_min_abs=DEFAULT_NEGATIVE_MIN_ABS)
Bases: ChoiceModel
Specification and estimation for standard Multinomial Conditional Logit models.
Unlike the Latent Class variant, this model estimates a single vector of homogeneous taste parameters across the entire sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
numeraire
|
str | None
|
The name of the variable (e.g., 'price') to use as the numeraire. If provided, its coefficient is bounded to be strictly negative to ensure logically consistent utility scaling and willingness-to-pay calculations. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
numeraire_idx |
int | None
|
The column index of the numeraire variable in the expanded design matrix. |
Create an unfitted conditional-logit model specification.
Source code in src/lcl/conditional_logit.py
fit(data, alts_col, cases_col, panels_col=None, formula=None, utility_formula=None, choice_col=None, case_varnames=None, weights=None, init_beta=None, mle_config=None, error_config=None)
Fit the conditional logit model via Maximum Likelihood Estimation.
Supports both R-style formulas (via formulaic) and explicit lists of variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame | DataFrame | ArrayLike
|
The main dataset containing choice situations and alternatives in long format. |
required |
alts_col
|
str
|
Name of the column containing alternative identifiers. |
required |
cases_col
|
str
|
Name of the column grouping observations into distinct choice situations. |
required |
panels_col
|
str | None
|
Name of the column mapping observations to specific decision-makers. If provided, the covariance matrix is automatically clustered at the panel level. If omitted, standard Huber-White robust standard errors are computed. |
None
|
formula
|
str | None
|
Backward-compatible Formulaic string, for example
|
None
|
utility_formula
|
str | None
|
Preferred Formulaic string for the alternative-specific utility
specification. If it includes a left-hand side, that outcome is used
as the choice indicator; otherwise |
None
|
choice_col
|
str | None
|
Name of the boolean/binary column indicating chosen alternatives. |
None
|
case_varnames
|
Sequence[str] | None
|
List of alternative-specific variables. |
None
|
weights
|
ArrayLike | None
|
|
None
|
init_beta
|
ArrayLike | None
|
|
None
|
mle_config
|
:class:`~lcl._struct.MleConfig`
|
Configuration for the L-BFGS optimization routine. |
None
|
error_config
|
:class:`~lcl._struct.ErrorConfig`
|
Configuration determining the robust covariance estimation strategy. |
None
|
Returns:
| Type | Description |
|---|---|
class:`~lcl.conditional_logit.CLResults`
|
Results container housing coefficients, robust standard errors, and fit statistics. |
Source code in src/lcl/conditional_logit.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
Results
lcl.conditional_logit.CLResults(model_spec, optim_res, data_struct, error_config, estim_time_sec, has_panels)
Post-estimation results and inference container for Conditional Logit.
Automatically handles the derivation of robust standard errors via the Delta Method if a softplus-constrained numeraire is specified in the model specification.
Compute inference summaries from a fitted conditional-logit model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_spec
|
:class:`~lcl.conditional_logit.ConditionalLogit`
|
Fitted model specification and variable metadata. |
required |
optim_res
|
:class:`~lcl._struct.OptimizeResult`
|
Optimizer output containing parameters, gradients, and Hessian inverse. |
required |
data_struct
|
:class:`~lcl._struct.Data`
|
Encoded estimation data. |
required |
error_config
|
:class:`~lcl._struct.ErrorConfig`
|
Covariance and standard-error configuration. |
required |
estim_time_sec
|
float
|
Wall-clock estimation time in seconds. |
required |
has_panels
|
bool
|
Whether robust covariance should cluster scores at the panel level. |
required |
Source code in src/lcl/conditional_logit.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
predict(data, alts_col, cases_col, panels_col=None)
Predict conditional choice probabilities for a given set of alternatives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame | DataFrame
|
The counterfactual dataset. Must contain all variables specified in the original model (including expanded dummy columns if a formula was used). |
required |
alts_col
|
str
|
Name of the column containing alternative identifiers. |
required |
cases_col
|
str
|
Name of the column grouping observations into distinct choice situations. |
required |
panels_col
|
str | None
|
Name of the column mapping observations to specific decision-makers. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the computed out-of-sample choice probabilities. |
Source code in src/lcl/conditional_logit.py
summarize(num_decimals=3)
summarize_betas(header=('Variable', 'Estimate', 'Std. Error'), num_decimals=3)
Print LaTeX and plain-text tables summarizing parameter estimates and standard errors.