ConsiderationSetMixedLogit#
- class pymc_marketing.customer_choice.consideration_set_logit.ConsiderationSetMixedLogit(choice_df, utility_equations, depvar, covariates, consideration_instruments, consideration_intercept=False, random_consideration=False, model_config=None, sampler_config=None, group_id=None, instrumental_vars=None, non_centered=True)[source]#
Consideration Set Mixed Logit with optional random consideration intercepts.
Extends
MixedLogitwith a two-stage structure that separates who gets considered from who is preferred conditional on consideration:- Stage 1 (Consideration):
pi_nj = sigmoid([gamma_0j +] sum_k gamma_zjk * z_tilde_njk [+ eta_n])
- Stage 2 (Choice):
P(j | n) = softmax(log(pi_nj) + V_nj)
where V_nj is the standard mixed logit utility from the parent class.
The consideration instruments Z must satisfy an exclusion restriction: they must be structurally separate from the utility covariates X. This is the discrete choice analogue of K != V in transformer attention.
- Parameters:
- choice_df
pd.DataFrame Wide DataFrame where each row is a choice scenario.
- utility_equations
listofstr Utility formulas in Wilkinson notation (see MixedLogit).
- depvar
str Name of the dependent variable column.
- covariates
listofstr Base covariate names (e.g., [‘price’, ‘time’]).
- consideration_instruments
ConsiderationInstruments TypedDict that must contain
'Z_tilde': np.ndarray of shape (N, J) for a single instrument per alternative, or (N, J, K_z) for multiple instruments per alternative. Mean-centring is the caller’s responsibility. Atz_tilde = 0,pi = sigmoid(0) = 0.5. Optionally contains'z_instrument_names': list of str of length K_z for labelling the instrument dimensions.- consideration_interceptbool, optional
If True, adds alternative-specific intercepts gamma_0j to the consideration stage. Default False. When True, gamma_0j and alpha_j (utility intercept) are not jointly identifiable without further constraints; use informative priors or fix one set of intercepts.
- random_considerationbool, optional
If True, adds a random intercept eta_n to the consideration stage, capturing unobserved individual-level variation in “visibility” across all alternatives. Default False.
- model_config
dict, optional Model configuration with Prior specifications.
- sampler_config
dict, optional Sampler configuration for pm.sample().
- group_id
str, optional Column name for group identifier (panel data).
- instrumental_vars
dict, optional Instrumental variables for price endogeneity (inherited).
- non_centeredbool, optional
Non-centered parameterization for random coefficients.
- choice_df
Notes
Identification design:
By default (consideration_intercept=False), there is no consideration intercept: gamma_0j is aliased with alpha_j. The utility intercept alpha_j absorbs both baseline preference and baseline consideration for each alternative.
When consideration_intercept=True, gamma_0j is estimated separately. This requires care: gamma_0j and alpha_j compete to explain baseline alternative-specific effects. Use informative priors or constrain one set to zero.
Z_tilde is mean-centred: at average screening (z_tilde = 0), pi = sigmoid(0) = 0.5. Only the deviation from population-mean screening drives consideration. This is the exclusion restriction.
When random_consideration=True, the random intercept eta_n has zero mean (not identifiable separately from alpha_j). Only sigma_consider is identified, capturing between-individual dispersion in consideration probability.
Methods
ConsiderationSetMixedLogit.__init__(...[, ...])Initialize model configuration and sampler configuration for the model.
Apply intervention, optionally updating consideration instruments.
Convert the model configuration and sampler configuration from the attributes to keyword arguments.
Build model from loaded InferenceData.
ConsiderationSetMixedLogit.build_model(**kwargs)Build model using stored choice_df and utility_equations.
Calculate difference in market share due to intervention.
Create attributes for the InferenceData object.
ConsiderationSetMixedLogit.fit([choice_df, ...])Fit the discrete choice model.
ConsiderationSetMixedLogit.graphviz(**kwargs)Get the graphviz representation of the model.
Create the model configuration and sampler configuration from the InferenceData to keyword arguments.
ConsiderationSetMixedLogit.load(fname[, check])Create a ModelBuilder instance from a file.
Create a ModelBuilder instance from an InferenceData object.
Combine random and non-random coefficients into full coefficient matrix.
Compute choice probabilities via softmax transformation.
Compute consideration probabilities via independent sigmoid per alternative.
Create control function for price endogeneity correction.
Create alternative-varying coefficients for fixed (non-varying) covariates.
Create alternative-specific intercepts with reference alternative set to zero.
Build consideration set mixed logit model.
Create coefficients for non-random alternative-specific covariates.
Create random coefficients that vary across individuals.
Compute total systematic utility for each alternative.
Parse the three-part structure of a mixed logit formula specification.
ConsiderationSetMixedLogit.plot_change(change_df)Plot change induced by a market intervention.
Prepare the design matrices for the utility equations.
Pre-process the model initiation inputs into PyMC-ready format.
Sample all the things.
ConsiderationSetMixedLogit.sample_posterior_predictive([...])Sample from posterior predictive, updating consideration instruments if needed.
Sample from prior predictive distribution.
ConsiderationSetMixedLogit.save(fname, **kwargs)Save the model's inference data to a file.
Set attributes on an InferenceData object.
Get the summary table of the model.
Attributes
default_model_configDefault model configuration including consideration stage priors.
default_sampler_configDefault sampler configuration.
fit_resultGet the posterior fit_result.
idGenerate a unique hash value for the model.
output_varThe output variable of the model.
posteriorAccess the 'posterior' attribute of the InferenceData object.
posterior_predictiveAccess the 'posterior_predictive' attribute of the InferenceData object.
predictionsAccess the 'predictions' attribute of the InferenceData object.
priorAccess the 'prior' attribute of the InferenceData object.
prior_predictiveAccess the 'prior_predictive' attribute of the InferenceData object.
versionidatasampler_configmodel_config