Skip to content

Update run_simulation() for Poisson model #409

Description

@Paul-Carvalho

Task: Extend run_simulation() to support Poisson Equivalence Models

Objective

Update the run_simulation() function in run_simulation.r to support welfare analysis simulations for Poisson equivalence models. The design, data formatting, and fitting workflows for Poisson models have already been implemented in format_model_data.r, fishset_design.r, and fishset_fit.r.


Relevant Files

  • Simulation Core: run_simulation.r (target function: run_simulation())
  • Reference Data & Design Files: format_model_data.r, fishset_design.r, fishset_fit.r
  • Unit Tests: tests/testthat/test-run_simulation.r

Implementation Requirements

1. Model Detection

  • Do not add new input arguments to run_simulation().
  • Automatically detect if the model is a Poisson equivalence model by checking the design object settings passed into the function (e.g., inspect design$settings or the equivalent model configuration field established in fishset_design.r).

2. Poisson Welfare Calculation Logic

Currently, run_simulation() supports Conditional Logit and Expected Profit models. Implement the Poisson welfare calculation following the equivalence properties:

  • Utility / Log-Intensity ($V_{ij}$ / $\ln \lambda_{ij}$):
    In the Poisson equivalence specification, the linear predictor $\eta_{ij} = \mathbf{X}{ij}\boldsymbol{\beta} + \gamma_i$ corresponds to log-intensity $\ln(\lambda{ij})$.

  • Logsum / Consumer Surplus Calculation:
    Because the individual fixed effects / scale terms $\gamma_i$ cancel out when taking differences across scenarios, the change in expected welfare ($\Delta E(W_i)$) for individual $i$ between baseline ($0$) and policy/counterfactual ($1$) scenarios is:

    $$\Delta E(W_i) = \frac{1}{\alpha} \left( \ln \sum_{j} \hat{\lambda}{ij}^1 - \ln \sum{j} \hat{\lambda}_{ij}^0 \right)$$

    Where:

    • $\hat{\lambda}{ij} = \exp(\mathbf{X}{ij}\boldsymbol{\beta})$ is the predicted intensity (or predicted count) for choice $j$.
    • $\alpha$ is the price parameter (marginal utility of income) extracted from the fitted Poisson model object.
  • Map this logic cleanly alongside the existing conditional logit and expected profit control flows inside run_simulation.r.

3. Output Consistency

  • Ensure the output data structure returned by run_simulation() (e.g., summary data frames, list elements, column names) remains identical to the existing structure generated for standard conditional logit models.

Unit Test Requirements

  • Update tests/testthat/test-run_simulation.r.
  • Add a new test_that() block that fits a dummy Poisson equivalence model using the pipeline in fishset_design.r and fishset_fit.r, then runs run_simulation().
  • Assert that:
    1. run_simulation() executes without errors or warnings.
    2. Output dimensions and column names match expected formats.
    3. Calculated welfare changes are numeric and non-NA.

Definition of Done

  • run_simulation() handles Poisson models seamlessly via design settings.
  • Welfare changes are correctly computed using the Poisson logsum formula.
  • Return objects match existing output specifications.
  • All tests in tests/testthat/test-run_simulation.r pass via devtools::test().

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions