"""
File: 01-testing.py

Michel Bierlaire
Sat Aug 02 2025, 17:39:56
"""

from IPython.core.display_functions import display
from biogeme.results_processing import (
    get_pandas_correlation_results,
    get_pandas_estimated_parameters,
)

from logit_airline_base import results as res_base

# The objective of this laboratory is to investigate various specification tests.

# We consider the models developed in an earlier laboratory for the airline itinerary choice. We read the estimation
# results directly from the specification files available in the same directory.

# Base model:
# \begin{align*}
# V_class_1 &= \beta_\text{fare}  \text{fare}_1 + \beta_\text{legroom}  \text{legroom}_1
#       + \beta_\text{sd\_early} \text{sched\_delay\_early}_1  + \beta_\text{sd\_late} \text{sched\_delay\_late}_1
#       + \beta_\text{time} \text{elapsed\_time}_1 \\
# V_class_2 &= \text{cte}_2 + \beta_\text{fare}  \text{fare}_2 + \beta_\text{legroom}  \text{legroom}_2
#       + \beta_\text{sd\_early} \text{sched\_delay\_early}_2  + \beta_\text{sd\_late} \text{sched\_delay\_late}_2
#       + \beta_\text{time} \text{elapsed\_time}_2 \\
# V_3 &= \text{cte}_3 + \beta_\text{fare}  \text{fare}_3 + \beta_\text{legroom}  \text{legroom}_3
#       + \beta_\text{sd\_early} \text{sched\_delay\_early}_3  + \beta_\text{sd\_late} \text{sched\_delay\_late}_3
#       + \beta_\text{time} \text{elapsed\_time}_3 \\
# \end{align*}


# Alternative specific time coefficient:
# \begin{align*}
# V_class_1 &= \beta_\text{fare}  \text{fare}_1 + \beta_\text{legroom}  \text{legroom}_1
#         + \beta_\text{sd\_early} \text{sched\_delay\_early}_1  + \beta_\text{sd\_late} \text{sched\_delay\_late}_1
#         + \beta_\text{time, 1} \text{elapsed\_time}_1 \\
# V_class_2 &= \text{cte}_2 + \beta_\text{fare}  \text{fare}_2 + \beta_\text{legroom}  \text{legroom}_2
#         + \beta_\text{sd\_early} \text{sched\_delay\_early}_2  + \beta_\text{sd\_late} \text{sched\_delay\_late}_2
#         + \beta_\text{time, 2} \text{elapsed\_time}_2 \\
# V_3 &= \text{cte}_3 + \beta_\text{fare}  \text{fare}_3 + \beta_\text{legroom}  \text{legroom}_3
#         + \beta_\text{sd\_early} \text{sched\_delay\_early}_3  + \beta_\text{sd\_late} \text{sched\_delay\_late}_3
#         + \beta_\text{time, 2} \text{elapsed\_time}_3 \\
# \end{align*}

# Question 1: test the null hypothesis that `beta_elapsed\_time_2` is equal to `beta_elapsed\_time_3`.

# Question 2: test the null hypothesis that, between the two models, the base model is the true model.

# Consider the model where the fare coefficient varies with income.

# Question 3: Test the null hypothesis that the fare coefficient does not vary with income.

# Consider the model with Box-Cox transform of the time variable.

# Question 4: test the linear specification with alternative specific time parameters, against the nonlinear
# specification with Box-Cox transform of the time variable.

# Consider the piecewise linear specification.

# Question 4: test the piecewise linear specification against the base model.

# Question 5: test the piecewise linear specification against the specification with the alternative specific time
# coefficient.

# The objects of class `results` contains all the necessary information to perform the tests.

# General statistics can be obtained from a dictionary.
display(res_base.get_general_statistics())

# The estimates of the parameters and relevant statistics are available from a Pandas data frame.
display(get_pandas_estimated_parameters(estimation_results=res_base))


# Information about the covariance/correlation between pairs of parameters are also available from a Pandas data frame.
display(get_pandas_correlation_results(estimation_results=res_base))
