Estimation resultsΒΆ

The estimation results are saved by Biogeme so that they can be re-used without the need for re-estimating the model Michel Bierlaire, EPFL Sun Jun 15 2025, 07:36:09

from IPython.core.display_functions import display

from biogeme.biogeme import BIOGEME
from biogeme.models import loglogit
from biogeme.results_processing import (
    EstimationResults,
    get_f12,
    get_html_estimated_parameters,
    get_latex_estimated_parameters,
    get_pandas_estimated_parameters,
)
from tutorial_data import biogeme_database, choice
from tutorial_model import utilities

log_choice_probability = loglogit(utilities, None, choice)
biogeme_object = BIOGEME(biogeme_database, log_choice_probability)
biogeme_object.calculate_null_loglikelihood(avail={0: 1, 1: 1})
-14.556090791758852

The name of the model as provided below determines the name of the files that are generated by Biogeme. Note that the estimation results are not stored, in a variable as we illustrate how they can be imported from a file.

biogeme_object.model_name = 'example'
_ = biogeme_object.estimate()

After estimation, three files have been created in the working directory:

  • __example.iter: during the course of the estimation algorithm, Biogeme saves in this file the best solution

    found so far. If the estimation is interrupted for any reason, it allows to restart it without losing the progress made so far. When the estimation starts, Biogeme looks for a file with that name. If it exists, it uses the values stored in the file as starting point of the estimation algorithm.

  • example.html: the estimation results are reported in a convenient HTML format in this file,

    that can be opened in any browser.

  • example.yaml: the raw estimation results are stored in this file, so that they can be imported instead

    of being re-calculated.

imported_results = EstimationResults.from_yaml_file(filename='example.yaml')

The object imported_results is identical to thw object results generated by the estimation procedure, and can be used in the exact same way.

Summary of the estimation results

print(imported_results.short_summary())
Results for model example
Nbr of parameters:              2
Sample size:                    21
Excluded data:                  0
Null log likelihood:            -14.55609
Final log likelihood:           -6.166042
Likelihood ratio test (null):           16.7801
Rho square (null):                      0.576
Rho bar square (null):                  0.439
Akaike Information Criterion:   16.33208
Bayesian Information Criterion: 18.42113

Various other functions are available in order to access the estimation results.

A dict containing the general statistics

print(imported_results.get_general_statistics())
{'Number of estimated parameters': '2', 'Sample size': '21', 'Excluded observations': '0', 'Null log likelihood': '-14.55609', 'Init log likelihood': '-6.166042', 'Final log likelihood': '-6.166042', 'Likelihood ratio test for the null model': '16.7801', 'Rho-square for the null model': '0.576', 'Rho-square-bar for the null model': '0.439', 'Likelihood ratio test for the init. model': '-0', 'Rho-square for the init. model': '0', 'Rho-square-bar for the init. model': '-0.324', 'Akaike Information Criterion': '16.33208', 'Bayesian Information Criterion': '18.42113', 'Final gradient norm': '4.6082E-06', 'Bootstrapping time': 'None'}

They can be accessed one by one as well

print(f'Number of parameter: {imported_results.number_of_parameters}')
print(f'Sample size: {imported_results.sample_size}')
print(f'Excluded observations: {imported_results.number_of_excluded_data}')
print(f'Init log likelihood: {imported_results.initial_log_likelihood}')
print(f'Final log likelihood: {imported_results.final_loglikelihood}')
print(
    f'Likelihood ratio test for the init. model: {imported_results.likelihood_ratio_init}'
)
print(
    f'Likelihood ratio test for the null model: {imported_results.likelihood_ratio_null}'
)
print(f'Akaike Information Criterion: {imported_results.akaike_information_criterion}')
print(
    f'Bayesian Information Criterion: {imported_results.bayesian_information_criterion}'
)
Number of parameter: 2
Sample size: 21
Excluded observations: 0
Init log likelihood: -6.1660422124237275
Final log likelihood: -6.1660422124237275
Likelihood ratio test for the init. model: -0.0
Likelihood ratio test for the null model: 16.780097158670248
Akaike Information Criterion: 16.332084424847455
Bayesian Information Criterion: 18.4211293002943

The estimated values of the parameters can be retrieved in a dict. This is particularly useful when using simulation.

print(imported_results.get_beta_values())
{'asc_car': -0.23757284960890077, 'b_time': -0.05310981573115624}

The value, the standard error and the t-test can also be extracted for each parameter

print(imported_results.get_parameter_value(parameter_name='b_time'))
print(imported_results.get_parameter_std_err(parameter_name='b_time'))
print(imported_results.get_parameter_t_test(parameter_name='b_time'))
-0.05310981573115624
0.021671520295531748
-2.4506732802731177

The results can also be exported in various formats

As a pandas data frame

pandas_frame = get_pandas_estimated_parameters(estimation_results=imported_results)
display(pandas_frame)
      Name     Value  Robust std err.  Robust t-stat.  Robust p-value
0  asc_car -0.237573         0.805174       -0.295058        0.767950
1   b_time -0.053110         0.021672       -2.450673        0.014259

In HTML format

html_code = get_html_estimated_parameters(estimation_results=imported_results)
print(html_code)
<table border="1">
<tr class=biostyle><th>Id</th><th>Name</th><th>Value</th><th>Robust std err.</th><th>Robust t-stat.</th><th>Robust p-value</th></tr>
<tr class=biostyle><td>0</td><td>asc_car</td><td>-0.238</td><td>0.805</td><td>-0.295</td><td>0.768</td></tr>
<tr class=biostyle><td>1</td><td>b_time</td><td>-0.0531</td><td>0.0217</td><td>-2.45</td><td>0.0143</td></tr>
</table>

In LaTeX format

latex_code = get_latex_estimated_parameters(estimation_results=imported_results)
print(latex_code)
\begin{tabular}{rlr@{.}lr@{.}lr@{.}lr@{.}l}
          &              &   \multicolumn{2}{l}{}         & \multicolumn{2}{l}{Robust}  &  \multicolumn{4}{l}{}  \\
Parameter &              &   \multicolumn{2}{l}{Coeff.}   & \multicolumn{2}{l}{Asympt.}       & \multicolumn{4}{l}{}   \\
number    &  Description &   \multicolumn{2}{l}{estimate} & \multicolumn{2}{l}{std. error}    & \multicolumn{2}{l}{$t$-stat}  &  \multicolumn{2}{l}{$p$-value} \\
\hline
0 & asc\_car & -0&238 & 0&805 & -0&295 & 0&768 \\
1 & b\_time & -0&0531 & 0&0217 & -2&45 & 0&0143 \\

\end{tabular}

In Alogit F12 format

f12_format = get_f12(estimation_results=imported_results)
print(f12_format)
                                                                        example
From biogeme 3.3.1                                      2025-09-03 05:23:42
END
   0    asc_car F  -2.375728496089e-01 +8.051736984869e-01
   0     b_time F  -5.310981573116e-02 +2.167152029553e-02
  -1
      21                  0 -1.455609079176e+01 -6.166042212424e+00
   0   0  2025-09-03 05:23:42
  61834

Total running time of the script: (0 minutes 0.587 seconds)

Gallery generated by Sphinx-Gallery