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:
run_simulation() executes without errors or warnings.
- Output dimensions and column names match expected formats.
- Calculated welfare changes are numeric and non-NA.
Definition of Done
Task: Extend
run_simulation()to support Poisson Equivalence ModelsObjective
Update the
run_simulation()function inrun_simulation.rto support welfare analysis simulations for Poisson equivalence models. The design, data formatting, and fitting workflows for Poisson models have already been implemented informat_model_data.r,fishset_design.r, andfishset_fit.r.Relevant Files
run_simulation.r(target function:run_simulation())format_model_data.r,fishset_design.r,fishset_fit.rtests/testthat/test-run_simulation.rImplementation Requirements
1. Model Detection
run_simulation().design$settingsor the equivalent model configuration field established infishset_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:$\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:
Because the individual fixed effects / scale terms
$$\Delta E(W_i) = \frac{1}{\alpha} \left( \ln \sum_{j} \hat{\lambda}{ij}^1 - \ln \sum{j} \hat{\lambda}_{ij}^0 \right)$$
Where:
Map this logic cleanly alongside the existing conditional logit and expected profit control flows inside
run_simulation.r.3. Output Consistency
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
tests/testthat/test-run_simulation.r.test_that()block that fits a dummy Poisson equivalence model using the pipeline infishset_design.randfishset_fit.r, then runsrun_simulation().run_simulation()executes without errors or warnings.Definition of Done
run_simulation()handles Poisson models seamlessly via design settings.tests/testthat/test-run_simulation.rpass viadevtools::test().