| Title: | Interface to 'Biogeme' |
|---|---|
| Description: | Uses the 'Python' implementation of 'Biogeme' as the numerical backend for specifying and estimating discrete-choice models in R. The default native requirement is 'biogeme==3.3.5'. |
| Authors: | Michel Bierlaire [aut, cre] |
| Maintainer: | Michel Bierlaire <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.2 |
| Built: | 2026-09-30 11:00:19 UTC |
| Source: | https://github.com/michelbierlaire/rbiogeme |
rbiogeme is a complete R-facing interface to the native Biogeme estimation engine. Data, parameters, expressions, models, estimation controls, and post-estimation operations are specified from R. The bridge compiles the complete expression tree once before native numerical work begins.
Start a new session with biogeme_setup() to provision or verify the
runtime and receive corrective actions. Configure the runtime with
biogeme_config() before the first call that initializes Python when
selecting an existing interpreter. The default runtime is lazy. A typical workflow is
to create a numeric data frame, wrap it with biogeme_database(),
build symbolic expressions with variable() and
biogeme_beta(), construct a specialized or generic model, and call
estimate(). The returned fit supports the ordinary R methods
summary(), coef(), vcov(), logLik(), and
nobs().
Specialized constructors cover multinomial, nested, cross-nested, panel, Bayesian, MDCEV, hybrid-choice, catalog, assisted-specification, and sampled-alternative workflows. Generic models use a complete likelihood expression and can additionally hold a probability, named simulation expressions, weights, panel aggregation, draw metadata, subsets, and parameter overrides.
Expressions are symbolic. Arithmetic, comparisons, logical operators, transformations, probability functions, draws, integration nodes, and derivatives create neutral expression nodes; they do not evaluate a local R likelihood. Native Biogeme performs compilation, differentiation, integration, optimization, simulation, and reporting.
The expression operators +, -, *, /, and
^ build arithmetic nodes. Comparisons ==, !=,
<, <=, >, and >= build indicator nodes.
Logical conjunction, disjunction, and negation use \&, |, and
!. Use logzero() and safe_exp() when the native
numerically safe form is required.
Use estimate() for fresh estimation. Use
estimate_or_load() only when explicit YAML loading or recycling is
desired, and choose a fresh temporary output directory for equivalence tests.
Random-draw and sampling examples should fix the native draw design and seed
and document any remaining simulation noise.
Start with ?biogeme_setup or ?biogeme_check, then read
vignette("getting-started", package = "rbiogeme") and
vignette("modeling-workflows", package = "rbiogeme") for the R
syntax and the complete workflow. Advanced Bayesian, Monte Carlo, MDCEV,
catalog, hybrid-choice, and sampled-alternative examples are in
vignette("advanced-models", package = "rbiogeme").
The whole package was implemented by ChatGPT 5.6 Luna under the supervision of Michel Bierlaire.
Depending on the function, a database, expression, model, diagnostics list, estimation result, or result-derived object.
biogeme_config, biogeme_database,
biogeme_model, logit_model, estimate,
simulate, summary.biogeme_fit, coef.biogeme_fit,
vcov.biogeme_fit, logLik.biogeme_fit
Absolute value of a Biogeme expression
## S3 method for class 'biogeme_expression' abs(x)## S3 method for class 'biogeme_expression' abs(x)
x |
A scalar or Biogeme expression. |
A Biogeme expression.
The complete catalog search, quick-estimation objective evaluation, Pareto persistence, and final re-estimation are delegated to native Biogeme. The R interface accepts named objective and validity descriptors rather than exposing Python callback objects. The selected validity rule is created and executed inside the Python bridge between native estimates.
assisted_specification( model, objectives = "loglikelihood_dimension", pareto_file_name = NULL, model_name = "rbiogeme_assisted", controls = list(), force = TRUE, control = NULL, validity = NULL ) run_assisted_specification( model, objectives = "loglikelihood_dimension", pareto_file_name = NULL, model_name = "rbiogeme_assisted", controls = list(), force = TRUE, control = NULL, validity = NULL )assisted_specification( model, objectives = "loglikelihood_dimension", pareto_file_name = NULL, model_name = "rbiogeme_assisted", controls = list(), force = TRUE, control = NULL, validity = NULL ) run_assisted_specification( model, objectives = "loglikelihood_dimension", pareto_file_name = NULL, model_name = "rbiogeme_assisted", controls = list(), force = TRUE, control = NULL, validity = NULL )
model |
A biogeme_model containing catalog expressions. |
objectives |
Native objective preset. Supported values are "loglikelihood_dimension" and "aic_bic_dimension". |
pareto_file_name |
Explicit path of the native Pareto checkpoint file. It has no default because native checkpoints are persistent files. |
model_name |
Native Biogeme model name prefix. |
controls |
Named list of native Biogeme controls. |
force |
Whether to remove the named Pareto checkpoint and start fresh. |
control |
Optional biogeme_control() object; an alias for controls. |
validity |
Optional native validity-rule name. Currently supported is
|
An object of class biogeme_assisted_fit containing native final results, the summary table, descriptions, and Pareto metadata.
The complete R expression tree is compiled once, then native Biogeme builds and samples the PyMC model. The returned R object contains the native posterior summary and the paths of any generated NetCDF/YAML/HTML files; posterior draws are not represented as manually managed Python objects.
bayesian_estimate( model, model_name = "rbiogeme_model", controls = list(), starting_values = NULL, control = NULL )bayesian_estimate( model, model_name = "rbiogeme_model", controls = list(), starting_values = NULL, control = NULL )
model |
A |
model_name |
Native Biogeme model name. |
controls |
Named native Biogeme controls. |
starting_values |
Optional named numeric vector of starting values. |
control |
Optional |
NetCDF and YAML output are enabled by default for this operation. Additional
Bayesian controls such as bayesian_draws, warmup, chains, target_accept,
calculate_likelihood, calculate_waic, calculate_loo, and
mcmc_sampling_strategy are passed to native Biogeme through controls.
Because those default Bayesian files are persistent, supply an explicit
output_directory through biogeme_control() (or disable both output types
explicitly).
An object of class biogeme_bayesian_fit containing the native
posterior summary and output paths.
Loads the NetCDF result with Biogeme's public BayesianResults API and
delegates the observation-level posterior mean calculation to native Biogeme.
No posterior-draw or ArviZ object is exposed to R.
bayesian_posterior_mean_by_observation(bayesian_results, variable_name, control = NULL)bayesian_posterior_mean_by_observation(bayesian_results, variable_name, control = NULL)
bayesian_results |
A |
variable_name |
Name of a stored posterior variable with one observation dimension in addition to chain and draw. |
control |
Optional native Biogeme control list. Likelihood, WAIC, and LOO calculations are disabled by default. |
A data frame indexed by the native observation coordinate, with one
column named after variable_name.
Returns the serialized result of native Biogeme's
BayesianResultsSummary.report_stored_variables() operation. No PyMC or
ArviZ object is exposed to R.
bayesian_stored_variables(x)bayesian_stored_variables(x)
x |
A |
A data frame describing each native stored variable by result group, variable name, dimensions, and shape.
Create a Biogeme parameter
biogeme_beta( name, start = 0, lower = NULL, upper = NULL, fixed = FALSE, sigma_prior = 5, prior = NULL )biogeme_beta( name, start = 0, lower = NULL, upper = NULL, fixed = FALSE, sigma_prior = 5, prior = NULL )
name |
Parameter name. |
start |
Initial value. |
lower |
Optional lower bound. |
upper |
Optional upper bound. |
fixed |
Logical value indicating whether the parameter is fixed. |
sigma_prior |
Standard deviation of the native default normal prior. |
prior |
Optional declarative prior from |
Parameter names are preserved exactly by the bridge and are therefore part
of the equivalence contract with native Biogeme. Bounds and fixed are
passed to the native parameter definition.
A parameter expression.
b_cost <- biogeme_beta("b_cost", start = -1, upper = 0) b_costb_cost <- biogeme_beta("b_cost", start = -1, upper = 0) b_cost
Create a native-compatible expression catalog
biogeme_catalog(name, expressions, controller = NULL) catalog(name, expressions, controller = NULL)biogeme_catalog(name, expressions, controller = NULL) catalog(name, expressions, controller = NULL)
name |
Catalog name. |
expressions |
Non-empty named list of alternative expressions. |
controller |
Optional |
A catalog expression compiled to native Biogeme.
Catalog controllers select the same named specification in every catalog that shares the controller. The object remains an R specification until the complete expression is compiled to native Biogeme.
biogeme_catalog_controller(name, specification_names, selected_name = NULL) catalog_controller(name, specification_names, selected_name = NULL)biogeme_catalog_controller(name, specification_names, selected_name = NULL) catalog_controller(name, specification_names, selected_name = NULL)
name |
Controller name. |
specification_names |
Ordered, unique catalog specification names. |
selected_name |
Optional specification selected before native compilation. |
A neutral catalog controller.
This is the runtime-only validation used by biogeme_setup() and is also
useful when the environment has already been configured. It initializes the
configured runtime, verifies the minimum R and Python versions, checks that
native Biogeme can be imported, and compares its version with the configured
requirement when that requirement pins an exact version. The check does not
construct or estimate a model.
biogeme_check(verbose = interactive())biogeme_check(verbose = interactive())
verbose |
If |
An object of class biogeme_check with elements ready,
diagnostics, and issues. issues is a data frame with columns
check, status, message, and action.
Native Biogeme performs the repeated simulation and quantile calculation. R supplies ordinary parameter mappings and receives two ordinary data frames; no native simulation or result objects are exposed.
biogeme_confidence_intervals( model, beta_values, expressions = NULL, interval_size = 0.9, control = NULL )biogeme_confidence_intervals( model, beta_values, expressions = NULL, interval_size = 0.9, control = NULL )
model |
A |
beta_values |
A non-empty list of named finite numeric parameter vectors, typically obtained from a fitted result's bootstrap field. |
expressions |
Optional named list of expressions. When omitted, the
model's |
interval_size |
Confidence interval size, strictly between zero and one. The native default is 0.9. |
control |
Optional |
A list with left and right data frames and native metadata.
Configuration must be performed before Python is initialized in the R
session. The default requirement is biogeme==3.3.5; use this function to
select a different compatible Biogeme requirement explicitly.
biogeme_config(python = NULL, biogeme_requirement = NULL, debug = NULL)biogeme_config(python = NULL, biogeme_requirement = NULL, debug = NULL)
python |
Optional Python executable. If |
biogeme_requirement |
Python requirement passed to
|
debug |
If |
biogeme_config(python = ...) selects an existing Python interpreter; it
does not install Biogeme into that interpreter. If python is omitted,
reticulate can provision the configured requirement in its managed
environment.
The current configuration, invisibly when changes are requested and visibly otherwise.
Unspecified fields are omitted so native Biogeme defaults remain in force. Additional named arguments are passed through to the native bridge.
biogeme_control( model_name = NULL, output_directory = NULL, seed = NULL, numerically_safe = NULL, second_derivatives = NULL, second_derivatives_percentage = NULL, optimization_algorithm = NULL, number_of_draws = NULL, draw_type = NULL, draw_seed = NULL, bootstrap_samples = NULL, user_notes = NULL, variance_covariance_type = NULL, save_iterations = NULL, generate_html = NULL, generate_yaml = NULL, validation_folds = NULL, ... )biogeme_control( model_name = NULL, output_directory = NULL, seed = NULL, numerically_safe = NULL, second_derivatives = NULL, second_derivatives_percentage = NULL, optimization_algorithm = NULL, number_of_draws = NULL, draw_type = NULL, draw_seed = NULL, bootstrap_samples = NULL, user_notes = NULL, variance_covariance_type = NULL, save_iterations = NULL, generate_html = NULL, generate_yaml = NULL, validation_folds = NULL, ... )
model_name |
Optional native Biogeme model name. |
output_directory |
Optional explicit directory for native files. It is required whenever a control requests native HTML, YAML, NetCDF, pickle, or iteration output; no operation writes to the working directory by default. |
seed |
Optional random seed. |
numerically_safe |
Optional numerical-safety flag. |
second_derivatives |
Optional second-derivative policy. |
second_derivatives_percentage |
Optional native percentage of iterations using analytical second derivatives. |
optimization_algorithm |
Optional native algorithm name. |
number_of_draws |
Optional number of simulation draws. |
draw_type |
Optional default draw type metadata. |
draw_seed |
Optional draw seed (mapped to native |
bootstrap_samples |
Optional bootstrap sample count. |
user_notes |
Optional notes included in native reports/results. |
variance_covariance_type |
Optional result covariance selection, such
as |
save_iterations |
Optional iteration-file persistence flag. |
generate_html |
Optional HTML-report flag. |
generate_yaml |
Optional YAML-report flag. |
validation_folds |
Optional validation-fold count. |
... |
Additional native Biogeme controls. |
Unspecified values are omitted. This lets native Biogeme apply its normal defaults. The control object can be stored in a model or passed to an estimation or simulation operation; it is not a Python object.
A named list of controls.
biogeme_control( seed = 1234, generate_html = FALSE, generate_yaml = FALSE, save_iterations = FALSE )biogeme_control( seed = 1234, generate_html = FALSE, generate_yaml = FALSE, save_iterations = FALSE )
The database remains an R object until a model is compiled. Data are copied and validated at construction time, so later modifications to the original data frame do not alter the model database.
biogeme_database(name, data)biogeme_database(name, data)
name |
Database name. |
data |
Numeric R data frame. |
The input must contain only numeric, named, non-empty columns. The original row identifiers are retained separately from the data columns and are carried through native filtering and row-extraction operations.
An object of class biogeme_database.
database <- biogeme_database( "demo", data.frame(choice = c(1, 2), income = c(10, 20)) ) biogeme_database_columns(database)database <- biogeme_database( "demo", data.frame(choice = c(1, 2), income = c(10, 20)) ) biogeme_database_columns(database)
Return the columns available in a Biogeme database
biogeme_database_columns(database)biogeme_database_columns(database)
database |
A |
A character vector of column names.
Define a derived database variable using a complete Biogeme expression
biogeme_database_define_variable(database, name, expression) database_define_variable(database, name, expression) define_variable(database, name, expression)biogeme_database_define_variable(database, name, expression) database_define_variable(database, name, expression) define_variable(database, name, expression)
database |
A |
name |
Name of the derived column. |
expression |
Complete Biogeme expression. |
The expression is retained symbolically and is compiled by the Python bridge together with the model. It is not evaluated by an R callback during estimation or simulation.
A new database specification.
database <- biogeme_database( "demo", data.frame(time = c(10, 12), cost = c(5, 6)) ) database <- biogeme_database_define_variable( database, "time_cost", variable("time") / variable("cost") ) biogeme_database_columns(database)database <- biogeme_database( "demo", data.frame(time = c(10, 12), cost = c(5, 6)) ) database <- biogeme_database_define_variable( database, "time_cost", variable("time") / variable("cost") ) biogeme_database_columns(database)
This is the R equivalent of native Database.extract_rows(). Indices are
deliberately one-based, as in the rest of the R interface, and the
original row identifiers are retained in the returned database.
biogeme_database_extract_rows(database, indices) database_extract_rows(database, indices)biogeme_database_extract_rows(database, indices) database_extract_rows(database, indices)
database |
A |
indices |
Unique positive one-based row indices, in the order to keep. |
A new biogeme_database containing the selected observations.
Return the number of observations excluded by native database filters
biogeme_database_filtered_row_count(database)biogeme_database_filtered_row_count(database)
database |
A |
An integer, or NA until lazy filters are materialised.
Test whether a Biogeme database contains a column
biogeme_database_has_column(database, column)biogeme_database_has_column(database, column)
database |
A |
column |
Column name. |
A single logical value.
Return whether a database has a declared panel structure
biogeme_database_is_panel(database)biogeme_database_is_panel(database)
database |
A |
One logical value.
Materialize lazy database operations through native Biogeme
biogeme_database_materialize(database)biogeme_database_materialize(database)
database |
A |
A database with native derived columns and filters applied.
Return the number of rows currently represented by a database
biogeme_database_nrow(database)biogeme_database_nrow(database)
database |
A |
An integer, or NA until lazy native filters are materialised.
Declare and validate a panel identifier
biogeme_database_panel(database, panel_id)biogeme_database_panel(database, panel_id)
database |
A |
panel_id |
Name of the panel identifier column. |
The identifier must be numeric and finite. Observations belonging to one identifier must be contiguous; the constructor rejects interleaved panel rows rather than silently reordering them.
A new panel database specification.
panel_database <- biogeme_panel_database( "panel_demo", data.frame(person = c(1, 1, 2, 2), choice = c(1, 2, 2, 1)), panel_id = "person" ) biogeme_database_is_panel(panel_database)panel_database <- biogeme_panel_database( "panel_demo", data.frame(person = c(1, 1, 2, 2), choice = c(1, 2, 2, 1)), panel_id = "person" ) biogeme_database_is_panel(panel_database)
Remove observations satisfying a Biogeme logical expression
biogeme_database_remove(database, condition) database_remove(database, condition) remove_observations(database, condition)biogeme_database_remove(database, condition) database_remove(database, condition) remove_observations(database, condition)
database |
A |
condition |
Logical Biogeme expression; matching rows are removed. |
condition is a symbolic indicator. Rows for which it is true are removed
when the database is materialized by native Biogeme.
A new database specification.
database <- biogeme_database( "demo", data.frame(choice = c(1, 2, 1), income = c(10, 20, 30)) ) filtered <- biogeme_database_remove(database, variable("income") > 10) biogeme_database_nrow(filtered)database <- biogeme_database( "demo", data.frame(choice = c(1, 2, 1), income = c(10, 20, 30)) ) filtered <- biogeme_database_remove(database, variable("income") > 10) biogeme_database_nrow(filtered)
Return the original row identifiers of a Biogeme database
biogeme_database_row_ids(database)biogeme_database_row_ids(database)
database |
A |
A character vector of row identifiers.
Generate a native-compatible segmentation specification from a database
biogeme_database_segmentation(database, variable, mapping, reference = NULL) database_generate_segmentation(database, variable, mapping, reference = NULL)biogeme_database_segmentation(database, variable, mapping, reference = NULL) database_generate_segmentation(database, variable, mapping, reference = NULL)
database |
A |
variable |
A database variable name or expression. |
mapping |
Named mapping from integer values to segment names. |
reference |
Optional reference segment name. |
A biogeme_segmentation specification.
This function initializes the configured runtime. For a check that catches
initialization failures and returns an actionable status object, use
biogeme_check().
biogeme_diagnostics()biogeme_diagnostics()
A named list containing environment diagnostics.
biogeme_check(), biogeme_config()
Declare first-class draw metadata for a model
biogeme_draws( name, draw_type = "NORMAL", number_of_draws = NULL, seed = NULL, matrix = NULL, generator = NULL )biogeme_draws( name, draw_type = "NORMAL", number_of_draws = NULL, seed = NULL, matrix = NULL, generator = NULL )
name |
Draw variable name. |
draw_type |
Native draw type. |
number_of_draws |
Optional draw count. |
seed |
Optional draw seed. |
matrix |
Optional user-supplied numeric draw matrix. |
generator |
Optional bridge generator name. Supported bridge-owned
generators include |
A biogeme_draws object.
Return the diagnostic details attached to a Biogeme error
biogeme_error_details(error)biogeme_error_details(error)
error |
A condition inheriting from |
A named list with operation, suggestion, parent, and optional Python traceback details.
Return native Biogeme general estimation statistics
biogeme_general_statistics(fit)biogeme_general_statistics(fit)
fit |
A |
A named list of native Biogeme statistics.
This is the neutral R counterpart of native Biogeme's
generic_alt_specific_catalogs(). Each returned element is a named list
of catalogs, one for every alternative. The catalogs share one native
controller with the exact specifications generic and altspec; when
segmentations are supplied, the segmentation catalogs are nested below
that controller in the same order as native Biogeme.
biogeme_generic_alt_specific_catalogs( generic_name, beta_parameters, alternatives, potential_segmentations = NULL, maximum_number = 5L ) generic_alt_specific_catalogs( generic_name, beta_parameters, alternatives, potential_segmentations = NULL, maximum_number = 5L )biogeme_generic_alt_specific_catalogs( generic_name, beta_parameters, alternatives, potential_segmentations = NULL, maximum_number = 5L ) generic_alt_specific_catalogs( generic_name, beta_parameters, alternatives, potential_segmentations = NULL, maximum_number = 5L )
generic_name |
Shared name used for the segmentation and generic/alternative-specific controllers. |
beta_parameters |
Non-empty list of |
alternatives |
At least two unique alternative names. |
potential_segmentations |
Optional non-empty list of segmentation objects. |
maximum_number |
Maximum number of potential segmentations in one option. |
A list of named lists of catalog expressions, one list per Beta.
Maximum of Biogeme expressions
biogeme_max(...)biogeme_max(...)
... |
Scalar values or Biogeme expressions. |
A Biogeme expression.
This is a declarative model object. The alternative utilities, shape parameters, and observed consumptions remain neutral R expression trees until the Python bridge sends the complete specification to the native Biogeme engine. The likelihood and forecasting algorithms are therefore provided by Biogeme itself.
biogeme_mdcev_model( database, model_type = c("gamma_profile", "generalized", "translated", "non_monotonic"), baseline_utilities, gamma_parameters, alpha_parameters = NULL, mu_utilities = NULL, scale_parameter = NULL, prices = NULL, weights = NULL, number_of_chosen_alternatives, consumed_quantities, subset = NULL, control = NULL ) mdcev_model( database, model_type = c("gamma_profile", "generalized", "translated", "non_monotonic"), baseline_utilities, gamma_parameters, alpha_parameters = NULL, mu_utilities = NULL, scale_parameter = NULL, prices = NULL, weights = NULL, number_of_chosen_alternatives, consumed_quantities, subset = NULL, control = NULL )biogeme_mdcev_model( database, model_type = c("gamma_profile", "generalized", "translated", "non_monotonic"), baseline_utilities, gamma_parameters, alpha_parameters = NULL, mu_utilities = NULL, scale_parameter = NULL, prices = NULL, weights = NULL, number_of_chosen_alternatives, consumed_quantities, subset = NULL, control = NULL ) mdcev_model( database, model_type = c("gamma_profile", "generalized", "translated", "non_monotonic"), baseline_utilities, gamma_parameters, alpha_parameters = NULL, mu_utilities = NULL, scale_parameter = NULL, prices = NULL, weights = NULL, number_of_chosen_alternatives, consumed_quantities, subset = NULL, control = NULL )
database |
A |
model_type |
One of |
baseline_utilities |
Non-empty named list of baseline utility expressions, keyed by integer alternative code. |
gamma_parameters |
Named list of gamma expressions, keyed by the same
alternatives. One value may be |
alpha_parameters |
Named list of alpha expressions. Required for the generalized, translated, and non-monotonic variants. |
mu_utilities |
Named list of non-monotonic utility expressions. |
scale_parameter |
Optional scale expression. |
prices |
Optional named list of price expressions. Supported by the gamma-profile and generalized native classes. |
weights |
Optional observation-weight expression. |
number_of_chosen_alternatives |
Expression containing the number of goods chosen in each observation. |
consumed_quantities |
Named list of observed consumption expressions. |
subset |
Optional logical expression selecting observations to remove
when it is false, using the same semantics as |
control |
Optional |
An object of class biogeme_mdcev_model.
Minimum of Biogeme expressions
biogeme_min(...)biogeme_min(...)
... |
Scalar values or Biogeme expressions. |
A Biogeme expression.
The formula is a neutral R expression. It is compiled once into a native Biogeme expression graph before any estimation or simulation starts.
biogeme_model( database, formula = NULL, weight = NULL, probability = NULL, simulations = NULL, panel_trajectory = FALSE, draws = NULL, subset = NULL, parameter_overrides = NULL, control = NULL, availability = NULL )biogeme_model( database, formula = NULL, weight = NULL, probability = NULL, simulations = NULL, panel_trajectory = FALSE, draws = NULL, subset = NULL, parameter_overrides = NULL, control = NULL, availability = NULL )
database |
A |
formula |
A log-likelihood expression, or a named list of formulas.
The names |
weight |
Optional observation-weight expression. |
probability |
Optional probability expression retained for simulation workflows. |
simulations |
Optional named list of expressions to simulate. |
panel_trajectory |
If |
draws |
Optional draw metadata object or list of draw metadata. |
subset |
Optional logical expression selecting observations to retain. |
parameter_overrides |
Optional named list of native parameter replacements, keyed by the original Beta names. |
control |
Optional |
availability |
Optional named list of availability expressions. This metadata is used by native post-estimation operations such as the null log-likelihood calculation for generic catalog models. |
formula is the native log-likelihood expression. A named list may contain
log_like (or loglike) and additional expressions, but a generic model
must still provide a likelihood, probability, or simulation expressions.
simulations is a named list evaluated only when simulate() is called.
An object of class biogeme_model.
database <- biogeme_database("demo", data.frame(choice = c(1, 2), x = c(1, 2))) probability <- logit_probability( utilities = list(`1` = 0, `2` = biogeme_beta("b") * variable("x")), alternative = variable("choice") ) model <- biogeme_model( database, formula = logzero(probability), simulations = list(probability = probability) ) modeldatabase <- biogeme_database("demo", data.frame(choice = c(1, 2), x = c(1, 2))) probability <- logit_probability( utilities = list(`1` = 0, `2` = biogeme_beta("b") * variable("x")), alternative = variable("choice") ) model <- biogeme_model( database, formula = logzero(probability), simulations = list(probability = probability) ) model
Return the parameter definitions in a model
biogeme_model_parameters(model)biogeme_model_parameters(model)
model |
A Biogeme model. |
A data frame of parameter definitions.
Unlike biogeme_model_parameters(), this operation also sees parameters
generated by native helpers such as segmentation and parameters in every
catalog branch. When configuration_id is supplied, native Biogeme first
resolves that configuration and the returned names describe the flattened
selected expression.
biogeme_native_parameter_names( model, configuration_id = NULL, model_name = "rbiogeme_parameters", controls = list() )biogeme_native_parameter_names( model, configuration_id = NULL, model_name = "rbiogeme_parameters", controls = list() )
model |
A Biogeme model. |
configuration_id |
Optional exact native catalog configuration ID. |
model_name |
Temporary native model name used while compiling. |
controls |
Named native Biogeme controls. |
A list with all, free, and fixed character vectors.
Construct a panel database in one call
biogeme_panel_database(name, data, panel_id)biogeme_panel_database(name, data, panel_id)
name |
Database name. |
data |
Numeric data frame. |
panel_id |
Panel identifier column. |
A biogeme_database object.
Creates a data-only prior descriptor. The Python bridge compiles it into a native PyMC prior before estimation; R callbacks are not used by the sampler.
biogeme_prior(distribution = c("normal", "student_t"), sigma = 5, nu = 5)biogeme_prior(distribution = c("normal", "student_t"), sigma = 5, nu = 5)
distribution |
Prior distribution: |
sigma |
Positive scale parameter. |
nu |
Positive degrees of freedom for a Student-t prior. |
A declarative biogeme_prior object.
Initialize and return the Python interpreter used by rbiogeme
biogeme_python()biogeme_python()
A reticulate Python configuration object. If no interpreter was selected, reticulate may provision the configured native requirement in its managed environment.
Stores the strata and sample sizes used by Biogeme's sampling-of-alternatives
API. The segments must cover full_set, and no sample size may exceed
the size of its segment.
biogeme_sampling_partition(segments, sample_sizes, full_set = NULL)biogeme_sampling_partition(segments, sample_sizes, full_set = NULL)
segments |
A non-empty list of disjoint integer alternative-ID vectors. |
sample_sizes |
One positive sample size for each segment. |
full_set |
Optional integer vector containing the complete partition universe. |
A declarative biogeme_sampling_partition object. Native Biogeme
performs the actual random sampling when the model is estimated.
Define a discrete parameter segmentation
biogeme_segmentation(variable, mapping, reference = NULL)biogeme_segmentation(variable, mapping, reference = NULL)
variable |
A data-variable name or expression. |
mapping |
Named mapping from integer values to segment names. |
reference |
Optional reference segment name. |
A biogeme_segmentation specification.
This is the structural counterpart of native Biogeme's
segmentation_catalogs(). It only enumerates catalog names and builds
neutral expression nodes; native Biogeme still creates the segmented
parameters and evaluates the selected specification.
biogeme_segmentation_catalogs( generic_name, beta_parameters, potential_segmentations, maximum_number, selected_name = NULL ) segmentation_catalogs( generic_name, beta_parameters, potential_segmentations, maximum_number, selected_name = NULL )biogeme_segmentation_catalogs( generic_name, beta_parameters, potential_segmentations, maximum_number, selected_name = NULL ) segmentation_catalogs( generic_name, beta_parameters, potential_segmentations, maximum_number, selected_name = NULL )
generic_name |
Shared controller name. |
beta_parameters |
Non-empty list of |
potential_segmentations |
Non-empty list of segmentation objects. |
maximum_number |
Maximum number of segmentations in one option. |
selected_name |
Optional segmentation specification selected before native compilation. |
A list of synchronized catalog expressions, one per beta.
This is the recommended first command for a new user. With no python
argument, reticulate provisions an isolated managed environment containing
the configured Biogeme requirement when the runtime is first initialized.
If python is supplied, that existing interpreter is selected instead and
must already contain the requested Biogeme package. In both cases the
function returns the same actionable status object as biogeme_check().
biogeme_setup( python = NULL, biogeme_requirement = NULL, debug = NULL, verbose = interactive() )biogeme_setup( python = NULL, biogeme_requirement = NULL, debug = NULL, verbose = interactive() )
python |
Optional existing Python executable. If omitted, use the reticulate-managed environment when no user-managed environment has been selected. |
biogeme_requirement |
Python requirement to provision or verify.
Defaults to |
debug |
If |
verbose |
If |
An object of class biogeme_check. Its ready element is TRUE
when the runtime can be used for model operations.
biogeme_check(), biogeme_config()
Box–Cox transformation
boxcox(x, lambda)boxcox(x, lambda)
x |
Expression to transform. |
lambda |
Box–Cox exponent expression. |
A Biogeme expression.
Return catalog configuration identifiers using native Biogeme
catalog_configuration_ids( model, model_name = "rbiogeme_catalog", controls = list(), control = NULL )catalog_configuration_ids( model, model_name = "rbiogeme_catalog", controls = list(), control = NULL )
model |
A |
model_name |
Native Biogeme model name. |
controls |
Named list of native Biogeme controls. |
control |
Optional |
Character vector of exact native configuration identifiers.
This delegates to the public BIOGEME.check_derivatives() operation. The
complete expression tree is compiled first; no R callback is evaluated by
the derivative checker.
check_derivatives( model, model_name = "rbiogeme_model", controls = list(), control = NULL, verbose = FALSE )check_derivatives( model, model_name = "rbiogeme_model", controls = list(), control = NULL, verbose = FALSE )
model |
A |
model_name |
Native Biogeme model name. |
controls |
Named native Biogeme controls. |
control |
Optional |
verbose |
Whether native Biogeme should print the comparison. |
A list containing the native function value, analytical and finite difference gradients and Hessians, and their error vectors.
The model is compiled once and the supplied fixed estimate is passed to
native BIOGEME.check_monte_carlo_stability(). Native Biogeme evaluates the
objective and gradient at fresh draw designs and writes its YAML checkpoint
and Markdown report.
check_monte_carlo_stability( model, fit, model_name = "rbiogeme_model", controls = list(), output_directory = NULL, basename = NULL, resume = TRUE, control = NULL )check_monte_carlo_stability( model, fit, model_name = "rbiogeme_model", controls = list(), output_directory = NULL, basename = NULL, resume = TRUE, control = NULL )
model |
A |
fit |
A |
model_name |
Native Biogeme model name. |
controls |
Named native Biogeme controls. |
output_directory |
Explicit directory for the native diagnostic files. It has no default: the operation refuses to write into the working directory when this argument is omitted. |
basename |
Optional native diagnostic filename prefix. |
resume |
Whether native Biogeme may resume a compatible checkpoint. |
control |
Optional |
An object of class biogeme_monte_carlo_diagnostic containing the
native status, conclusion, recommendation, data, and output paths.
Count catalog specifications using native Biogeme
count_number_of_specifications( model, model_name = "rbiogeme_catalog", controls = list(), control = NULL )count_number_of_specifications( model, model_name = "rbiogeme_catalog", controls = list(), control = NULL )
model |
A |
model_name |
Native Biogeme model name. |
controls |
Named list of native Biogeme controls. |
control |
Optional |
The native number of catalog configurations, or NULL when native
Biogeme cannot determine a count.
Construct a native cross-nested-logit log-probability expression
cross_nested_log_probability( utilities, availability, nests, alternative, alternative_codes = NULL, scale_parameter = NULL )cross_nested_log_probability( utilities, availability, nests, alternative, alternative_codes = NULL, scale_parameter = NULL )
utilities |
Named list of utility expressions. |
availability |
Optional named list of availability expressions. |
nests |
A |
alternative |
Integer-valued alternative or a Biogeme choice expression. |
alternative_codes |
Optional named integer vector mapping utility names. |
scale_parameter |
Optional native CNL scale expression. |
A Biogeme expression compiled to native biogeme.models.logcnl.
Calculate the native cross-nested-logit error-term correlation matrix
cross_nested_logit_correlation( model, beta_values = NULL, alternatives_names = NULL )cross_nested_logit_correlation( model, beta_values = NULL, alternatives_names = NULL )
model |
A |
beta_values |
Optional named estimated or starting parameter values. |
alternatives_names |
Optional named character vector for row/column labels. |
A numeric correlation matrix.
Define a cross-sectional cross-nested-logit model
cross_nested_logit_model( database, choice, utilities, nests, availability = NULL, alternative_codes = NULL, scale_parameter = NULL, control = NULL )cross_nested_logit_model( database, choice, utilities, nests, availability = NULL, alternative_codes = NULL, scale_parameter = NULL, control = NULL )
database |
A |
choice |
Name of the integer-valued choice column. |
utilities |
Named list of utility expressions. |
nests |
A |
availability |
Optional named list of availability expressions. |
alternative_codes |
Optional named integer vector mapping utility names. |
scale_parameter |
Optional native CNL scale expression. |
control |
Optional |
An object of class biogeme_cross_nested_logit_model.
Define one cross-nested-logit nest
cross_nested_nest(nest_parameter, allocation, name = NULL)cross_nested_nest(nest_parameter, allocation, name = NULL)
nest_parameter |
Native nest parameter expression or numeric value. |
allocation |
Named mapping from alternative codes to allocation expressions in this nest. |
name |
Optional native nest name. |
A biogeme_cross_nested_nest specification.
Define the complete cross-nested-logit nest structure
cross_nested_nests(choice_set, nests, sparse = FALSE)cross_nested_nests(choice_set, nests, sparse = FALSE)
choice_set |
All integer alternative codes. |
nests |
A non-empty list of |
sparse |
If |
A biogeme_cross_nested_nests specification.
Construct a native cross-nested-logit probability expression
cross_nested_probability( utilities, availability, nests, alternative, alternative_codes = NULL )cross_nested_probability( utilities, availability, nests, alternative, alternative_codes = NULL )
utilities |
Named list of utility expressions. |
availability |
Optional named list of availability expressions. |
nests |
A |
alternative |
Integer-valued alternative or a Biogeme choice expression. |
alternative_codes |
Optional named integer vector mapping utility names. |
A Biogeme expression compiled to native biogeme.models.cnl.
Summarize the structural sparsity of a CNL nest specification
cross_nested_sparsity_report(nests)cross_nested_sparsity_report(nests)
nests |
A |
A data frame with one row per nest and membership counts.
Represents native Biogeme's CrossVariableTuple. The Python bridge
expands the expression after native choice-set sampling; R callbacks are not
used during estimation.
cross_variable(name, formula)cross_variable(name, formula)
name |
Name of the generated cross-variable. |
formula |
A neutral Biogeme expression involving individual and alternative variables. |
A declarative biogeme_cross_variable object.
Symbolically differentiate an expression with respect to a named variable
derive(expression, name) Derive(expression, name)derive(expression, name) Derive(expression, name)
expression |
Expression to differentiate. |
name |
Variable or parameter name. |
A Biogeme expression.
Wraps a child expression in native Biogeme's
DistributedParameter node. The wrapper preserves the named variable in
Bayesian output and is compiled before native estimation; it is not evaluated
by R during sampling.
distributed_parameter(name, expression)distributed_parameter(name, expression)
name |
Name used for the stored native variable. |
expression |
Child Biogeme expression, usually a location parameter
plus a scale parameter multiplied by |
This helper is a thin interface to native Biogeme and does not implement a sampling or likelihood engine in R.
A symbolic Biogeme expression compiled to native
DistributedParameter.
beta <- biogeme_beta("b_time") random_coefficient <- distributed_parameter( "b_time_rnd", beta + biogeme_beta("b_time_s", start = 1) * draw("b_time_eps", "NORMAL") ) format(random_coefficient)beta <- biogeme_beta("b_time") random_coefficient <- distributed_parameter( "b_time_rnd", beta + biogeme_beta("b_time_s", start = 1) * draw("b_time_eps", "NORMAL") ) format(random_coefficient)
Create a named Biogeme draw node
draw(name, draw_type = "NORMAL")draw(name, draw_type = "NORMAL")
name |
Draw variable name. |
draw_type |
Biogeme draw type, such as |
A Biogeme expression.
Select an expression from a numeric mapping
Elem(mapping, index) elem(mapping, index)Elem(mapping, index) elem(mapping, index)
mapping |
Named list whose names are integer keys. |
index |
Numeric or Biogeme expression used as the key. |
A Biogeme expression.
Estimate a Biogeme model
estimate( model, model_name = "rbiogeme_model", controls = list(), starting_values = NULL, run_bootstrap = FALSE, yaml_file_name = NULL, control = NULL )estimate( model, model_name = "rbiogeme_model", controls = list(), starting_values = NULL, run_bootstrap = FALSE, yaml_file_name = NULL, control = NULL )
model |
A |
model_name |
Output/model name used by Biogeme. |
controls |
Named list of Biogeme controls. |
starting_values |
Optional named numeric vector of starting values. |
run_bootstrap |
Whether to run bootstrap re-estimation. |
yaml_file_name |
Optional path for Biogeme's standard YAML output. |
control |
Optional |
estimate() always requests a fresh native estimation. It does not load a
previous YAML or iteration file implicitly. Use estimate_or_load() when
explicit result loading or recycling is required.
An object of class biogeme_fit.
## Not run: fit <- estimate( model, model_name = "demo", control = biogeme_control( output_directory = tempfile("rbiogeme-estimate-"), generate_html = FALSE, generate_yaml = FALSE, save_iterations = FALSE ) ) summary(fit) ## End(Not run)## Not run: fit <- estimate( model, model_name = "demo", control = biogeme_control( output_directory = tempfile("rbiogeme-estimate-"), generate_html = FALSE, generate_yaml = FALSE, save_iterations = FALSE ) ) summary(fit) ## End(Not run)
Catalog choices, synchronized controllers, estimation, result summaries, Pareto selection, and parameter comparison are all handled by native Biogeme. The returned object only contains ordinary R representations of those native results.
estimate_catalog( model, model_name = "rbiogeme_catalog", controls = list(), quick_estimate = FALSE, run_bootstrap = FALSE, force = TRUE, control = NULL )estimate_catalog( model, model_name = "rbiogeme_catalog", controls = list(), quick_estimate = FALSE, run_bootstrap = FALSE, force = TRUE, control = NULL )
model |
A |
model_name |
Native Biogeme model name prefix. |
controls |
Named list of native Biogeme controls. |
quick_estimate |
Whether to use native quick estimation. |
run_bootstrap |
Whether to run native bootstrap re-estimation. |
force |
Whether to estimate afresh rather than recycle native files. |
control |
Optional |
An object of class biogeme_catalog_fit containing native model
results, summaries, Pareto-optimal specifications, and LaTeX comparison.
The configuration identifier is resolved by native
BIOGEME.from_configuration(). R only supplies the compiled expression
tree and receives ordinary serialized estimation results; no R expression
or callback is evaluated during estimation.
estimate_configuration( model, configuration_id, model_name = "rbiogeme_configuration", controls = list(), starting_values = NULL, run_bootstrap = FALSE, yaml_file_name = NULL, control = NULL )estimate_configuration( model, configuration_id, model_name = "rbiogeme_configuration", controls = list(), starting_values = NULL, run_bootstrap = FALSE, yaml_file_name = NULL, control = NULL )
model |
A |
configuration_id |
Exact native configuration identifier, for example
|
model_name |
Native Biogeme model name. |
controls |
Named list of native Biogeme controls. |
starting_values |
Optional named numeric vector of starting values. |
run_bootstrap |
Whether to run native bootstrap re-estimation. |
yaml_file_name |
Optional path for native YAML output. |
control |
Optional |
An object of class biogeme_fit containing native results.
force = FALSE permits loading the named YAML file; force = TRUE always
performs fresh estimation. The default estimate() path never recycles an
old result file.
estimate_or_load( model, yaml_file_name, force = FALSE, model_name = "rbiogeme_model", controls = list(), starting_values = NULL, run_bootstrap = FALSE )estimate_or_load( model, yaml_file_name, force = FALSE, model_name = "rbiogeme_model", controls = list(), starting_values = NULL, run_bootstrap = FALSE )
model |
A |
yaml_file_name |
YAML path used for loading or saving. |
force |
Whether to force fresh estimation. |
model_name |
Native Biogeme model name. |
controls |
Named native controls. |
starting_values |
Optional named starting values. |
run_bootstrap |
Whether to run bootstrap estimation. |
A biogeme_fit object.
Regenerates the sampled choice sets with recycling disabled, compiles the sampled likelihood once in native Biogeme, and delegates estimation to the native engine. No Python source is generated by the R interface.
estimate_sampled_alternatives( model, model_name = "rbiogeme_sampled", controls = list(), starting_values = NULL, run_bootstrap = FALSE, control = NULL )estimate_sampled_alternatives( model, model_name = "rbiogeme_sampled", controls = list(), starting_values = NULL, run_bootstrap = FALSE, control = NULL )
model |
A [ |
model_name |
Native Biogeme model name. |
controls |
Named native Biogeme controls. |
starting_values |
Optional named finite numeric vector. |
run_bootstrap |
Whether to run native bootstrap re-estimation. |
control |
Optional [ |
A biogeme_fit object with native sampling-context and sampled-file
metadata attached.
The expression is compiled once by the Python bridge. The initial result
contains the native function value, gradient, Hessian, and BHHH matrix. If
points is supplied, the same compiled native callable evaluates each row
with the requested free-parameter values. R does not evaluate the
expression locally and no Python object is returned.
evaluate_biogeme_expression( expression, beta = NULL, points = NULL, numerically_safe = FALSE, use_jit = TRUE )evaluate_biogeme_expression( expression, beta = NULL, points = NULL, numerically_safe = FALSE, use_jit = TRUE )
expression |
A Biogeme expression. |
beta |
Optional named numeric vector used for the initial evaluation. When omitted, native Beta starting values are used. |
points |
Optional data frame or numeric matrix. Its columns are free parameter names and its rows are the parameter vectors for repeated native evaluations. |
numerically_safe |
Whether to request native numerically safe formulas. |
use_jit |
Whether to use native JAX just-in-time compilation. |
An object of class biogeme_expression_evaluation with initial,
free_beta_names, and evaluations components.
This operation delegates to Biogeme's public get_value_c calculator. The
expression is compiled before the native evaluator runs; R receives only a
numeric vector or scalar.
evaluate_biogeme_expression_c( model, expression, beta, aggregation = FALSE, number_of_draws = 1000L, numerically_safe = FALSE, use_jit = TRUE )evaluate_biogeme_expression_c( model, expression, beta, aggregation = FALSE, number_of_draws = 1000L, numerically_safe = FALSE, use_jit = TRUE )
model |
A |
expression |
A Biogeme expression to evaluate. |
beta |
A |
aggregation |
Whether to return one native aggregated scalar instead of one value per observation. |
number_of_draws |
Positive number of native Monte Carlo draws. |
numerically_safe |
Whether to request native numerically safe formulas. |
use_jit |
Whether to use native JAX just-in-time compilation. |
A numeric vector, or one numeric scalar when aggregation = TRUE.
Integrate an expression over a standard normal random variable
integrate_normal(expression, name, number_of_quadrature_points = 30L)integrate_normal(expression, name, number_of_quadrature_points = 30L)
expression |
Integrand expression. |
name |
Random variable name. |
number_of_quadrature_points |
Number of quadrature points. |
A Biogeme expression.
Define one coefficient-variable term for a linear utility
linear_term(beta, x) LinearTermTuple(beta, x)linear_term(beta, x) LinearTermTuple(beta, x)
beta |
A |
x |
A |
A linear-utility term.
Construct a native linear utility expression
linear_utility(terms) LinearUtility(terms)linear_utility(terms) LinearUtility(terms)
terms |
A non-empty list of |
A Biogeme expression compiled to native LinearUtility.
This is the log-probability counterpart of logit_probability(). It is
compiled directly to Biogeme's public models.loglogit constructor, which
preserves the native numerically stable likelihood used by examples such
as Swissmetro b20.
logit_log_probability( utilities, availability = NULL, alternative, alternative_codes = NULL )logit_log_probability( utilities, availability = NULL, alternative, alternative_codes = NULL )
utilities |
Named list of utility expressions keyed by alternatives. |
availability |
Optional named list of availability expressions. |
alternative |
Integer code or expression for the observed alternative. |
alternative_codes |
Optional named integer codes for the utilities. |
A Biogeme logit log-probability expression.
Define a cross-sectional multinomial logit model
logit_model( database, choice, utilities, availability = NULL, alternative_codes = NULL, weight = NULL )logit_model( database, choice, utilities, availability = NULL, alternative_codes = NULL, weight = NULL )
database |
A |
choice |
Name of the integer-valued choice column. |
utilities |
Named list of utility expressions, one per alternative. |
availability |
Optional named list of availability expressions. |
alternative_codes |
Optional named integer vector mapping utility names to values in the choice column. If omitted, utility names must themselves be integer codes. |
weight |
Optional observation-weight expression. |
The utility list is named by alternative. If the names are not integer
codes, pass alternative_codes as a named integer vector. Availability and
weights may be constants or symbolic expressions.
An object of class biogeme_logit_model.
database <- biogeme_database( "demo", data.frame(choice = c(1, 2), x = c(1, 2)) ) b <- biogeme_beta("b") model <- logit_model( database, choice = "choice", utilities = list(`1` = 0, `2` = b * variable("x")) ) modeldatabase <- biogeme_database( "demo", data.frame(choice = c(1, 2), x = c(1, 2)) ) b <- biogeme_beta("b") model <- logit_model( database, choice = "choice", utilities = list(`1` = 0, `2` = b * variable("x")) ) model
Construct a native logit probability expression
logit_probability( utilities, availability = NULL, alternative, alternative_codes = NULL ) logit(utilities, availability = NULL, alternative, alternative_codes = NULL)logit_probability( utilities, availability = NULL, alternative, alternative_codes = NULL ) logit(utilities, availability = NULL, alternative, alternative_codes = NULL)
utilities |
Named list of utility expressions, one per alternative. |
availability |
Optional named list of availability expressions. |
alternative |
Integer-valued alternative whose probability is returned, or a Biogeme expression selecting the alternative for each observation. |
alternative_codes |
Optional named integer vector when utility names are not themselves integer alternative codes. |
A probability expression compiled to native biogeme.models.logit.
A numerically safe logarithm that returns zero at zero
logzero(x) safe_log(x)logzero(x) safe_log(x)
x |
A scalar or Biogeme expression. |
A Biogeme expression.
The MDCEV likelihood is generated by the native Biogeme MDCEV class after
compilation. This convenience wrapper has the same fresh-estimation
semantics as estimate().
mdcev_estimate( model, model_name = "rbiogeme_mdcev", controls = list(), starting_values = NULL, run_bootstrap = FALSE, yaml_file_name = NULL, control = NULL )mdcev_estimate( model, model_name = "rbiogeme_mdcev", controls = list(), starting_values = NULL, run_bootstrap = FALSE, yaml_file_name = NULL, control = NULL )
model |
A |
model_name |
Native Biogeme model name. |
controls |
Named native Biogeme controls. |
starting_values |
Optional named numeric vector of starting values. |
run_bootstrap |
Whether to run native bootstrap re-estimation. |
yaml_file_name |
Optional path for native YAML output. |
control |
Optional |
A biogeme_fit object.
Forecast MDCEV consumption using native Biogeme algorithms
mdcev_forecast( model, fit, database = NULL, total_budget, epsilons = NULL, number_of_draws = NULL, seed = NULL, brute_force = FALSE, tolerance_dual = 1e-10, tolerance_budget = 1e-10 )mdcev_forecast( model, fit, database = NULL, total_budget, epsilons = NULL, number_of_draws = NULL, seed = NULL, brute_force = FALSE, tolerance_dual = 1e-10, tolerance_budget = 1e-10 )
model |
A |
fit |
A fresh |
database |
Optional database used only for forecasting. This permits forecasting a native row subset without changing the estimation fit. |
total_budget |
Positive total budget. |
epsilons |
Optional list of Gumbel-draw matrices. If omitted, native
draws are generated using |
number_of_draws |
Number of draws when |
seed |
Optional native NumPy seed when draws are generated. |
brute_force |
Whether to use native brute-force optimization. |
tolerance_dual |
Native dual-variable tolerance. |
tolerance_budget |
Native budget-constraint tolerance. |
A biogeme_mdcev_forecast object containing R data frames.
Return native pandas description tables for an MDCEV forecast
mdcev_forecast_describe(forecast)mdcev_forecast_describe(forecast)
forecast |
A |
A list of ordinary R data frames corresponding to native
pandas DataFrame.describe() output.
Generate native MDCEV error-term draws
mdcev_generate_epsilons( model, number_of_observations, number_of_draws, seed = NULL )mdcev_generate_epsilons( model, number_of_observations, number_of_draws, seed = NULL )
model |
A |
number_of_observations |
Number of database observations. |
number_of_draws |
Number of Gumbel draws per observation. |
seed |
Optional native NumPy seed. |
A list of numeric matrices, one matrix per observation.
Return native Biogeme's estimated-parameter table for an MDCEV fit
mdcev_parameter_table(fit, variance_covariance_type = NULL)mdcev_parameter_table(fit, variance_covariance_type = NULL)
fit |
A |
variance_covariance_type |
Optional native covariance type, such as
|
A named list of ordinary R data frames returned by native Biogeme.
Return native Biogeme's compact MDCEV estimation summary
mdcev_short_summary(fit)mdcev_short_summary(fit)
fit |
A |
The native Biogeme summary string.
Validate the two native MDCEV forecasting algorithms
mdcev_validate_forecast( model, fit, database = NULL, total_budget, epsilons = NULL, number_of_draws = NULL, seed = NULL, tolerance_dual = 1e-13, tolerance_budget = 1e-13 )mdcev_validate_forecast( model, fit, database = NULL, total_budget, epsilons = NULL, number_of_draws = NULL, seed = NULL, tolerance_dual = 1e-13, tolerance_budget = 1e-13 )
model |
A |
fit |
A fresh |
database |
Optional database used only for forecast validation. |
total_budget |
Positive total budget. |
epsilons |
Optional list of Gumbel-draw matrices. |
number_of_draws |
Number of native draws when |
seed |
Optional native NumPy seed when draws are generated. |
tolerance_dual |
Native dual-variable tolerance. |
tolerance_budget |
Native budget-constraint tolerance. |
TRUE when native validation completes without an exception.
Monte Carlo average of an expression
monte_carlo(expression)monte_carlo(expression)
expression |
Expression to integrate. |
A Biogeme expression.
Construct a native nested-logit log probability with endogenous-sampling correction
nested_endogenous_sampling_log_probability( utilities, availability, nests, correction, alternative, alternative_codes = NULL )nested_endogenous_sampling_log_probability( utilities, availability, nests, correction, alternative, alternative_codes = NULL )
utilities |
Named list of utility expressions. |
availability |
Optional named list of availability expressions. |
nests |
A |
correction |
Named list of alternative-specific log correction terms. |
alternative |
Integer-valued alternative or a Biogeme choice expression. |
alternative_codes |
Optional named integer vector mapping utility names. |
A Biogeme expression compiled through native get_mev_for_nested
and logmev_endogenous_sampling.
Construct a native nested-logit log-probability expression
nested_log_probability( utilities, availability, nests, alternative, alternative_codes = NULL, scale_parameter = NULL )nested_log_probability( utilities, availability, nests, alternative, alternative_codes = NULL, scale_parameter = NULL )
utilities |
Named list of utility expressions. |
availability |
Optional named list of availability expressions. |
nests |
A |
alternative |
Integer-valued alternative or a Biogeme choice expression. |
alternative_codes |
Optional named integer vector mapping utility names. |
scale_parameter |
Optional native scale expression for bottom normalization. |
A Biogeme expression compiled to native biogeme.models.lognested.
Calculate the native nested-logit error-term correlation matrix
nested_logit_correlation( model, beta_values = NULL, alternatives_names = NULL, mu = 1 )nested_logit_correlation( model, beta_values = NULL, alternatives_names = NULL, mu = 1 )
model |
A |
beta_values |
Optional named estimated or starting parameter values. |
alternatives_names |
Optional named character vector for row/column labels. |
mu |
Overall scale parameter passed to native Biogeme. |
A numeric correlation matrix.
Define a cross-sectional nested-logit model
nested_logit_model( database, choice, utilities, nests, availability = NULL, alternative_codes = NULL, scale_parameter = NULL, control = NULL )nested_logit_model( database, choice, utilities, nests, availability = NULL, alternative_codes = NULL, scale_parameter = NULL, control = NULL )
database |
A |
choice |
Name of the integer-valued choice column. |
utilities |
Named list of utility expressions. |
nests |
A |
availability |
Optional named list of availability expressions. |
alternative_codes |
Optional named integer vector mapping utility names. |
scale_parameter |
Optional native scale expression for bottom normalization. |
control |
Optional |
An object of class biogeme_nested_logit_model.
Define one non-trivial nested-logit nest
nested_nest(nest_parameter, alternatives, name = NULL)nested_nest(nest_parameter, alternatives, name = NULL)
nest_parameter |
Native nest parameter expression or numeric value. |
alternatives |
Integer alternative codes contained in the nest. |
name |
Optional native nest name. |
A biogeme_nested_nest specification.
Alternatives not listed in a non-trivial nest are treated by native Biogeme as trivial nests containing one alternative.
nested_nests(choice_set, nests)nested_nests(choice_set, nests)
choice_set |
All integer alternative codes. |
nests |
A non-empty list of |
A biogeme_nested_nests specification.
Construct a native nested-logit probability expression
nested_probability( utilities, availability, nests, alternative, alternative_codes = NULL )nested_probability( utilities, availability, nests, alternative, alternative_codes = NULL )
utilities |
Named list of utility expressions. |
availability |
Optional named list of availability expressions. |
nests |
A |
alternative |
Integer-valued alternative or a Biogeme choice expression. |
alternative_codes |
Optional named integer vector mapping utility names. |
A Biogeme expression compiled to native biogeme.models.nested.
Normal cumulative distribution function
normal_cdf(x)normal_cdf(x)
x |
A scalar or Biogeme expression. |
A Biogeme expression.
Normal probability density function
normal_pdf(x)normal_pdf(x)
x |
A scalar or Biogeme expression. |
A Biogeme expression.
Constructs a neutral expression node. The complete node is compiled once to Biogeme's public ordered-logit expression before estimation or simulation.
ordered_logit_log_probability(eta, cutpoints, alternative, categories = NULL, neutral_labels = numeric(), enforce_order = TRUE, eps = 1e-12)ordered_logit_log_probability(eta, cutpoints, alternative, categories = NULL, neutral_labels = numeric(), enforce_order = TRUE, eps = 1e-12)
eta |
Latent-index expression. |
cutpoints |
Non-empty list of cutpoint expressions. |
alternative |
Observed response expression. |
categories |
Optional numeric response labels. |
neutral_labels |
Optional numeric labels with unit contribution. |
enforce_order |
Whether native Biogeme enforces ordered cutpoints. |
eps |
Positive numerical lower bound used by native Biogeme. |
A Biogeme expression compiled to native OrderedLogLogit.
Constructs a neutral expression node. The complete node is compiled once to Biogeme's public ordered-probit expression before estimation or simulation.
ordered_probit_log_probability(eta, cutpoints, alternative, categories = NULL, neutral_labels = numeric(), enforce_order = TRUE, eps = 1e-12)ordered_probit_log_probability(eta, cutpoints, alternative, categories = NULL, neutral_labels = numeric(), enforce_order = TRUE, eps = 1e-12)
eta |
Latent-index expression. |
cutpoints |
Non-empty list of cutpoint expressions. |
alternative |
Observed response expression. |
categories |
Optional numeric response labels. |
neutral_labels |
Optional numeric labels with unit contribution. |
enforce_order |
Whether native Biogeme enforces ordered cutpoints. |
eps |
Positive numerical lower bound used by native Biogeme. |
A Biogeme expression compiled to native OrderedLogProbit.
Aggregate an observation-level likelihood over a panel trajectory
panel_likelihood_trajectory(expression)panel_likelihood_trajectory(expression)
expression |
Observation-level likelihood or probability expression. |
A Biogeme expression.
The Pareto file is read by native ParetoPostProcessing. Re-estimation,
summary compilation, model descriptions, and optional Pareto plotting all
remain native operations; the returned object contains ordinary R values.
pareto_post_processing( model, pareto_file_name, model_name = "rbiogeme_pareto", controls = list(), recycle = FALSE, plot_file_name = NULL, objective_x = 0L, objective_y = 1L, label_x = NULL, label_y = NULL, control = NULL )pareto_post_processing( model, pareto_file_name, model_name = "rbiogeme_pareto", controls = list(), recycle = FALSE, plot_file_name = NULL, objective_x = 0L, objective_y = 1L, label_x = NULL, label_y = NULL, control = NULL )
model |
A |
pareto_file_name |
Path to an existing native Pareto file. |
model_name |
Native Biogeme model-name prefix for re-estimation. |
controls |
Named list of native Biogeme controls. |
recycle |
Whether native Biogeme may recycle complete estimation files.
The default is |
plot_file_name |
Optional path where native Pareto plot output is saved. |
objective_x |
Zero-based native Pareto objective index for the plot. |
objective_y |
Zero-based native Pareto objective index for the plot. |
label_x |
Optional native plot x-axis label. |
label_y |
Optional native plot y-axis label. |
control |
Optional |
An object of class biogeme_pareto_fit containing native results,
the compiled summary, descriptions, Pareto statistics, and plot path.
Piecewise-linear expression using native Biogeme naming rules
piecewise( expression, thresholds, betas = NULL, transform = c("formula", "variable") )piecewise( expression, thresholds, betas = NULL, transform = c("formula", "variable") )
expression |
Variable expression. |
thresholds |
Piecewise thresholds; only endpoints may be NULL. |
betas |
Optional list of parameter expressions. |
transform |
Whether to return the full formula or the transformed variable form. |
A Biogeme expression.
Predict native probabilities or simulation expressions
## S3 method for class 'biogeme_fit' predict(object, newdata = NULL, expressions = NULL, control = NULL, ...)## S3 method for class 'biogeme_fit' predict(object, newdata = NULL, expressions = NULL, control = NULL, ...)
object |
A |
newdata |
Optional numeric data frame or |
expressions |
Optional named list of complete symbolic expressions. For logit, nested-logit, and cross-nested-logit fits, omission produces one native probability column per alternative. For a generic model, the model's probability or simulation expressions are used. |
control |
Optional |
... |
Reserved for future prediction options; unsupported arguments are rejected explicitly. |
predict() is a convenience wrapper around simulate(). It does not
calculate probabilities in R and does not refit the model. Use
simulate() directly when several named quantities, posterior draws, or a
custom simulation workflow are needed.
A data frame containing values calculated by native Biogeme.
database <- biogeme_database( "demo", data.frame(choice = c(1, 2), x = c(1, 2)) ) model <- logit_model( database, choice = "choice", utilities = list(`1` = 0, `2` = biogeme_beta("b") * variable("x")) ) # After fitting: predict(fit) or predict(fit, newdata = data.frame(...))database <- biogeme_database( "demo", data.frame(choice = c(1, 2), x = c(1, 2)) ) model <- logit_model( database, choice = "choice", utilities = list(`1` = 0, `2` = biogeme_beta("b") * variable("x")) ) # After fitting: predict(fit) or predict(fit, newdata = data.frame(...))
The complete expression tree is compiled once, then native Biogeme's
CompiledFormulaEvaluator is used for each requested evaluation mode.
Each mode is evaluated twice, matching the native profiling example's first
call and steady-state measurements. Only ordinary environment and timing
summaries cross back to R.
profile_jax( model, beta_values = NULL, cases = list( list( label = "Function only", gradient = FALSE, hessian = FALSE, bhhh = FALSE ), list( label = "Function + gradient", gradient = TRUE, hessian = FALSE, bhhh = FALSE ), list( label = "Function + gradient + Hessian", gradient = TRUE, hessian = TRUE, bhhh = FALSE ), list( label = "Function + gradient + BHHH", gradient = TRUE, hessian = FALSE, bhhh = TRUE ) ), model_name = "rbiogeme_model", controls = list(), numerically_safe = FALSE, control = NULL )profile_jax( model, beta_values = NULL, cases = list( list( label = "Function only", gradient = FALSE, hessian = FALSE, bhhh = FALSE ), list( label = "Function + gradient", gradient = TRUE, hessian = FALSE, bhhh = FALSE ), list( label = "Function + gradient + Hessian", gradient = TRUE, hessian = TRUE, bhhh = FALSE ), list( label = "Function + gradient + BHHH", gradient = TRUE, hessian = FALSE, bhhh = TRUE ) ), model_name = "rbiogeme_model", controls = list(), numerically_safe = FALSE, control = NULL )
model |
A |
beta_values |
Named finite numeric vector of parameter values. If |
cases |
A non-empty list of named case lists. Each case has a non-empty |
model_name |
Native Biogeme model name. |
controls |
Named native Biogeme controls. |
numerically_safe |
Whether native formula evaluation uses numerical-safety transformations. |
control |
Optional |
Timing values depend on the active Python, JAX, hardware, and thread configuration. The operation is a profiling diagnostic, not an estimation operation.
An object of class biogeme_jax_profile containing the native JAX environment and serialized profile data for each case.
biogeme_control
quick_estimate() delegates to native BIOGEME.quick_estimate(). It
returns parameter values and the statistics that native Biogeme makes
available without the ordinary post-estimation derivative calculations.
Use save_results() when a standard YAML result is required.
quick_estimate( model, model_name = "rbiogeme_model", controls = list(), control = NULL )quick_estimate( model, model_name = "rbiogeme_model", controls = list(), control = NULL )
model |
A |
model_name |
Output/model name used by Biogeme. |
controls |
Named list of Biogeme controls. |
control |
Optional |
An object of class biogeme_fit.
Create a random variable for native numerical integration
random_variable(name)random_variable(name)
name |
Random variable name. |
A Biogeme expression.
Read standard Biogeme YAML results
read_results(filename)read_results(filename)
filename |
YAML file generated by Biogeme. |
A biogeme_fit object.
Numerically safe exponential
safe_exp(x)safe_exp(x)
x |
A scalar or Biogeme expression. |
A Biogeme expression.
Defines the protocol for a native sampling-of-alternatives model. Sampling, cross-variable expansion, likelihood construction, differentiation, and optimization are performed by native Biogeme through the Python bridge. Sampling is regenerated with recycling disabled by default.
sampled_alternatives_model( alternatives, individuals, choice_column, id_column, utility, partition, biogeme_file_name, model_type = c("logit", "nested", "cnl"), combined_variables = list(), mev_partition = NULL, mev_sample_sizes = NULL, nests = NULL, control = NULL )sampled_alternatives_model( alternatives, individuals, choice_column, id_column, utility, partition, biogeme_file_name, model_type = c("logit", "nested", "cnl"), combined_variables = list(), mev_partition = NULL, mev_sample_sizes = NULL, nests = NULL, control = NULL )
alternatives |
Numeric data frame with one row per alternative. |
individuals |
Numeric data frame with one row per decision maker. |
choice_column |
Choice column in |
id_column |
Unique alternative-ID column in |
utility |
Complete neutral Biogeme utility expression. |
partition |
Main [ |
biogeme_file_name |
Path for the native sampled-data file. |
model_type |
One of |
combined_variables |
Optional list of [ |
mev_partition |
Optional partition used for MEV terms. |
mev_sample_sizes |
Optional MEV sample sizes. |
nests |
Nested or cross-nested nest object for the selected model type. |
control |
Optional [ |
A biogeme_sampled_alternatives_model object containing ordinary R
data and a neutral expression specification.
estimate_sampled_alternatives()
Creates sampling protocol metadata equivalent to native
generate_segment_size(); native Biogeme still performs validation and
sampling.
sampling_segment_sizes(sample_size, number_of_segments)sampling_segment_sizes(sample_size, number_of_segments)
sample_size |
Total number of alternatives to sample. |
number_of_segments |
Number of sampling segments. |
An integer vector whose entries differ by at most one. Any remainder is assigned to the first segments, matching native Biogeme.
Save standard Biogeme YAML results
save_results(fit, filename)save_results(fit, filename)
fit |
A |
filename |
Destination YAML file. |
fit, invisibly.
The generated native parameters follow Biogeme's public naming contract:
<base>_ref for the reference and <base>_diff_<segment> for differences.
segment_beta(beta, segmentations, prefix = "segmented") segmented_beta(beta, segmentations, prefix = "segmented")segment_beta(beta, segmentations, prefix = "segmented") segmented_beta(beta, segmentations, prefix = "segmented")
beta |
A |
segmentations |
A non-empty list of |
prefix |
Native segmentation expression prefix. |
A Biogeme expression compiled through native Segmentation.
Simulate named native Biogeme expressions at fixed estimates
simulate(model, expressions = NULL, beta, control = NULL, database = NULL)simulate(model, expressions = NULL, beta, control = NULL, database = NULL)
model |
A |
expressions |
Optional named list of expressions. When omitted, the
model's |
beta |
A |
control |
Optional |
database |
Optional scenario database. It may be a
|
expressions is a named list of complete symbolic expressions. When it is
omitted, the model's simulations list is used. Native Biogeme evaluates
these expressions at the supplied parameter values and returns ordinary R
data frames.
A biogeme_simulation object containing a data frame of values.
## Not run: simulation_model <- biogeme_model( database, formula = choice_log_probability, simulations = list(probability = choice_probability) ) simulated <- simulate( simulation_model, beta = fit, control = biogeme_control(output_directory = tempfile("rbiogeme-sim-")) ) as.data.frame(simulated) ## End(Not run)## Not run: simulation_model <- biogeme_model( database, formula = choice_log_probability, simulations = list(probability = choice_probability) ) simulated <- simulate( simulation_model, beta = fit, control = biogeme_control(output_directory = tempfile("rbiogeme-sim-")) ) as.data.frame(simulated) ## End(Not run)
Evaluates named simulation formulas over native Bayesian posterior draws and returns the native mean and quantile summaries without exposing PyMC objects.
simulate_bayesian(model, bayesian_results, expressions = NULL, percentage_of_draws_to_use = 10, lower_quantile = 0.025, upper_quantile = 0.975, control = NULL)simulate_bayesian(model, bayesian_results, expressions = NULL, percentage_of_draws_to_use = 10, lower_quantile = 0.025, upper_quantile = 0.975, control = NULL)
model |
A |
bayesian_results |
A |
expressions |
Optional named list of simulation expressions. |
percentage_of_draws_to_use |
Percentage of posterior draws evaluated by native Biogeme. |
lower_quantile |
Lower posterior-simulation quantile. |
upper_quantile |
Upper posterior-simulation quantile. |
control |
Optional |
A biogeme_simulation object containing native summaries.
This operation delegates to Biogeme's public
calculate_single_formula_from_expression evaluator. Unlike simulate(),
it returns one native aggregated value, which is useful for panel
likelihood formulas.
simulate_single_formula( model, expression, beta, number_of_draws, seed = NULL, numerically_safe = FALSE, use_jit = TRUE )simulate_single_formula( model, expression, beta, number_of_draws, seed = NULL, numerically_safe = FALSE, use_jit = TRUE )
model |
A |
expression |
A Biogeme expression to evaluate. |
beta |
A |
number_of_draws |
Positive number of native Monte Carlo draws. |
seed |
Optional temporary native draw seed. |
numerically_safe |
Whether to request native numerically safe formulas. |
use_jit |
Whether to use native JAX just-in-time compilation. |
One numeric scalar returned by native Biogeme.
Square root of a Biogeme expression
## S3 method for class 'biogeme_expression' sqrt(x)## S3 method for class 'biogeme_expression' sqrt(x)
x |
A scalar or Biogeme expression. |
A Biogeme expression.
This uses native LinearUtility and Segmentation during bridge
compilation. The generated parameter names are asc_*_ref and
asc_*_diff_*, matching the Python example.
swissmetro_b01b_model( database, user_notes = paste0("Example of a logit model with three alternatives: Train, Car and ", "Swissmetro. Same as 01logit and introducing LinearUtility and ", "automatic segmentation of parameters.") )swissmetro_b01b_model( database, user_notes = paste0("Example of a logit model with three alternatives: Train, Car and ", "Swissmetro. Same as 01logit and introducing LinearUtility and ", "automatic segmentation of parameters.") )
database |
A database prepared by |
user_notes |
Optional notes stored in the native estimation result. |
A biogeme_logit_model.
The transformation is deliberately expressed as native database
operations. It removes rows with PURPOSE other than 1 or 3 and rows with
CHOICE == 0, then defines the cost, availability, and /100 scaled
variables used by plot_b01a_logit.py. Row order and original row IDs are
retained. Set panel = TRUE to declare ID as the panel identifier.
swissmetro_data( data, name = "swissmetro", panel = FALSE, filter_purpose = TRUE ) prepare_swissmetro( data, name = "swissmetro", panel = FALSE, filter_purpose = TRUE )swissmetro_data( data, name = "swissmetro", panel = FALSE, filter_purpose = TRUE ) prepare_swissmetro( data, name = "swissmetro", panel = FALSE, filter_purpose = TRUE )
data |
Numeric Swissmetro data frame. |
name |
Database name. |
panel |
Whether to declare the |
filter_purpose |
Whether to retain only observations with |
A biogeme_database specification.
Build the baseline Swissmetro MNL specification
swissmetro_mnl_model(database)swissmetro_mnl_model(database)
database |
A database prepared by |
A biogeme_logit_model.
Validate a model using native Biogeme cross-validation
validate(model, fit, folds = 5L, groups = NULL, seed = NULL, control = NULL)validate(model, fit, folds = 5L, groups = NULL, seed = NULL, control = NULL)
model |
A |
fit |
A |
folds |
Number of validation folds. |
groups |
Optional grouping column. |
seed |
Optional seed controlling native random fold assignment. |
control |
Optional |
A native-bridge validation result.
Model construction, database operations, and native Biogeme model creation are checked without running an optimizer or writing estimation results. The returned diagnostics are ordinary R values; the native model object is created and discarded inside the bridge.
validate_model(model, control = NULL)validate_model(model, control = NULL)
model |
A |
control |
Optional |
This is specification validation, not cross-validation. Use validate()
after estimation when the goal is out-of-sample fold evaluation.
An object of class biogeme_model_validation containing the native
validation status, database information, formula names, and parameter
count.
## Not run: database <- biogeme_database( "demo", data.frame(choice = c(1, 2), x = c(1, 2)) ) model <- logit_model( database, choice = "choice", utilities = list(`1` = 0, `2` = biogeme_beta("b") * variable("x")) ) validate_model(model) ## End(Not run)## Not run: database <- biogeme_database( "demo", data.frame(choice = c(1, 2), x = c(1, 2)) ) model <- logit_model( database, choice = "choice", utilities = list(`1` = 0, `2` = biogeme_beta("b") * variable("x")) ) validate_model(model) ## End(Not run)
Create a Biogeme data variable
variable(name)variable(name)
name |
Column name in the Biogeme database. |
variable() creates a symbolic reference. It does not extract an R column
or calculate a vector immediately. Use it in arithmetic and model
expressions after the corresponding database column has been defined.
A variable expression.
x <- variable("income") b <- biogeme_beta("b_income") b * x + 1x <- variable("income") b <- biogeme_beta("b_income") b * x + 1