ChoiceModels.jl is a Julia package designed for flexible and symbolic specification of Discrete Choice Models (DCM). Inspired by Biogeme and Apollo, it uses symbolic algebra, modular architecture, and Julia's type system to allow rapid prototyping and estimation of models like Logit and Mixed Logit.
- Symbolic utility expressions using
Parameter,Variable, and algebraic operators. - Multinomial Logit and Mixed Logit estimation with availability conditions.
- Integration with
DataFrames.jlfor data handling. - Estimation via
Optim.jl, supporting automatic or analytic gradients. - Prediction tools for probabilities and most likely alternatives.
- Extensibility for new models (e.g., Latent Class, Nested Logit).
using ChoiceModels, CSV, DataFrames
df = CSV.read("my_data.csv", DataFrame)
asc_car = Parameter(:asc_car, value=0.0)
β_time = Parameter(:β_time, value=0.0)
β_cost = Parameter(:β_cost, value=0.0)
V_car = asc_car + β_time * Variable(:time_car) + β_cost * Variable(:cost_car)
V_bus = β_time * Variable(:time_bus) + β_cost * Variable(:cost_bus)
model = LogitModel([V_car, V_bus]; data=df, availability=[trues(nrow(df)), trues(nrow(df))])
results = estimate(model, :choice)
probs = predict(model, results)using ChoiceModels, CSV, DataFrames
df = CSV.read("my_data.csv", DataFrame)
asc_car = Parameter(:asc_car, value=0.0)
β_time = Parameter(:β_time, value=0.0)
σ_time = Parameter(:σ_time, value=1.0)
draw = Draw(:time_rnd)
V_car = asc_car + (β_time + σ_time * draw) * Variable(:time_car)
V_bus = (β_time + σ_time * draw) * Variable(:time_bus)
model = MixedLogitModel([V_car, V_bus];
data=df,
idvar=:id,
R=500,
draw_scheme=:mlhs,
availability=[trues(nrow(df)), trues(nrow(df))])
results = estimate(model, :choice)
P = predict(model, results)] dev https://github.com/ighdez/ChoiceModels.jl- Expressions:
Parameter,Variable,Draw, and algebraic combinators - Models:
LogitModel,MixedLogitModel(more to come!) - Estimation:
estimate(model, choices)usingOptim.jl - Prediction:
predict(model, results)returns probabilities
All public functions are documented via Julia docstrings. Use ?estimate in the REPL to see inline help. Full documentation will be published using Documenter.jl soon.
MIT License
Built with ♥ and ChatGPT pair-programming.