larch.ModelGroup#
- class ModelGroup(models, title=None)[source]#
Bases:
ConstrainedModel,MutableSequenceA group of models that can be treated as a single model for estimation.
This structure collects a group of models for simultaneous estimation. Each component model is a separate Model object, but they can share parameters. This sharing is controlled by parameter names, in that if two models in the group have a parameter with the same name, they will be treated as a common parameter. There is no requirement that the linked parameters be used in the same way in each model, but since they are treated as a single parameter, they will be estimated together, and must have the same bounds and constraints.
The model group object acts like a list of Model objects (i.e., a MutableSequence), and can be indexed, sliced, and iterated over.
- Parameters:
models (list of Model or ModelGroup) – A list of models to include in the group. Each model can be a Model object or another ModelGroup object. If a ModelGroup is included, its submodels are each included in the group, and the ModelGroup itself is not included.
title (str, optional) – A title for the model group. This is used for display purposes and does not affect the estimation.
Methods
__init__(models[, title])add_parameter_array(name, values)append(value)S.append(value) -- append value to the end of the sequence
availability_def([new_def])Get or set the definition of the availability variable.
bhhh([x, return_dataframe])calculate_parameter_covariance([pvals, robust])Calculate the parameter covariance matrix.
choice_def([new_def])Get or set the definition of the choice variable.
clear()clear_cache()Remove all cached log likelihood values and estimation results.
constraint_violation([on_violation, ...])Check if constraints are currently violated.
count(value)d2_loglike([x, start_case, stop_case, step_case])Compute the Hessian matrix of the log likelihood.
d_loglike([x, return_series])Compute the gradient of the log likelihood of the group of models.
d_logloss([x, start_case, stop_case, step_case])distribution_on_idca_variable(x[, xlabel, ...])Generate a figure of observed and modeled choices over a range of variable values.
distribution_on_idco_variable(x[, xlabel, ...])Generate a figure of variables over a range of variable values.
doctor(**kwargs)Run diagnostics, checking for common problems and inconsistencies.
estimate(*args, **kwargs)Maximize loglike, and then calculate parameter covariance.
estimation_statistics([compute_loglike_null])Create an XHTML summary of estimation statistics.
estimation_statistics_raw([compute_loglike_null])Compile estimation statistics as a pandas Series.
extend(values)S.extend(iterable) -- extend sequence by appending elements from the iterable
fit_bhhh(*args, **kwargs)get_param_loc(name)Get the position of a named parameter.
get_value(name, *[, default, kind])index(value, [start, [stop]])Raises ValueError if the value is not present.
initialize_graph([alternative_codes, ...])Write a nesting tree graph for a MNL model.
insert(i, value)S.insert(index, value) -- insert value before index
load_data(*args, **kwargs)No-op.
lock_value([name, value])Set a fixed value for a model parameter.
loglike([x, check_if_best])Compute the log likelihood of the group of models.
loglike2_bhhh([x, return_series])loglike_casewise([x])Compute the log likelihood case-by-case for the group of models.
loglike_null([use_cache])Compute the log likelihood at null values.
logloss([x, start_case, stop_case, ...])mangle([data, structure])maximize_loglike(*args, **kwargs)Maximize the log likelihood.
Create a tabular summary of parameter values.
plock([values])Lock the values of one or more parameters.
pop([index])Raise IndexError if list is empty or index is out of range.
pretty_table()reflow_data_arrays()Reload the internal data_arrays so they are consistent with the datatree.
remove(value)S.remove(value) -- remove first occurrence of value.
required_data()Report what data is required in DataFrames for this model to be used.
reverse()S.reverse() -- reverse IN PLACE
set_cap([cap])Set limiting values for one or more parameters.
set_value(name[, value, initvalue, ...])Set the value one or more attributes of a single parameter.
set_values([values])Set the parameter values for one or more parameters.
swap_datatree(tree[, should_mangle])Swap the current datatree with a new datatree.
to_xlsx(filename[, save_now, ...])Write the estimation results to an Excel file.
Compute the total weight across all models in the group.
unmangle([force, structure_only])update_parameters(x)utility_functions([subset, resolve_parameters])Generate an XHTML output of the utility function(s).
Attributes
autoscale_weightsWhether to automatically scale case weights.
availability_anyA flag indicating whether availability should be inferred from the data.
availability_ca_varAn idca variable or expression indicating if alternatives are available.
availability_co_varsA mapping giving idco expressions that evaluate to availability indicators.
availability_varchoice_anychoice_ca_varAn idca variable giving the choices as indicator values.
choice_co_codeAn idco variable giving the choices as alternative id's.
choice_co_varsA mapping giving idco expressions that evaluate to indicator values.
compute_engineconstraint_intensityA simple attribute descriptor.
constraint_sharpnessA simple attribute descriptor.
constraintsdatadatasetData arrays as loaded for model computation.
datatreeA source for data for the model.
graphidentGetter method for the ident property.
is_mangledlogsum_parameterA copy of the result dict from most recent likelihood maximization.
n_casesTotal number of cases in all submodels.
n_paramsorderingA simple attribute descriptor.
parametersA copy of the current min-max bounds of the parameters.
A DataFrame of the model parameters.
An array indicating which parameters are marked as holdfast.
pinitvalsAn array of the initial parameter values.
An array of the current parameter maximum values.
An array of the current parameter minimum values.
An array of the current parameter names.
An array of the current parameter null values.
Possible overspecification of the model.
An array of the current parameter standard errors.
An array of the current parameter values.
quantity_caThe portion of the quantity function computed from idca data.
quantity_scalerename_parametersA simple attribute descriptor.
titleA simple attribute descriptor.
use_streamingutility_caThe portion of the utility function computed from idca data.
utility_coThe portion of the utility function computed from idco data.
weight_co_var