How policyanalysisinc/heromod2 works
JSON Input Reception and Parsing
• Node Label: “Receive JSON Input”
• Description: The workflow starts when the user inputs a Markov model in JSON format. This JSON is parsed into an R object. (Assumed to use a JSON library call such as jsonlite::fromJSON, though this step might be wrapped in a helper function within heRomod2.)
Input Validation and Pre-processing
• Node Label: “Validate & Pre-process Input”
• Functions Involved: A utility (possibly in R/error.r) ensures that the JSON adheres to the expected schema. This error-checking step validates structure and content.
Initialization of Model Components
• Node Label: “Initialize Model Components”
• Functions Involved:
• R/constants.r: Loads any constant values used across the simulation.
• R/variables.r: Sets up the model’s variables (e.g., starting state probabilities, costs, utilities).
• Description: With valid input, initialization functions prepare the required settings and constant parameters.
Main Evaluation Function
• Node Label: “Evaluate Markov Model” (main routine)
• Functions Involved: R/heromod2.r likely contains the main orchestrator function (e.g., evaluate_markov_model or similar) that accepts the pre-processed input and commands the simulation.
• Description: The orchestrator method is responsible for driving the simulation cycles and coordinating other component functions.
Execution of the Simulation Loop
• Node Label: “Simulation Loop (Cycle Over Time)”
• Loop Details:
o For each cycle, the following sub-steps occur:
1. State Transition Calculation:
– Function: R/formula.r (function such as compute_transition might be defined here)
– Description: Calculate the probabilities of transitioning between states using the input formulas.
2. Variable Update:
– Function: R/variables.r (could be updating state counters, accumulators for costs/effects)
– Description: Updates the model’s state based on computed transitions.
3. Error Handling within Cycle:
– Function: R/error.r (if any unexpected computation or data is encountered, this function is called)
– Description: Validates the integrity of calculations; if errors arise, the error handling routine is activated.
4. Optional: Additional computations using R/misc.r may be performed to manage any auxiliary calculations.
Final Computation and Output Generation
• Node Label: “Summarize & Generate Output”
• Description: Once all cycles are processed, final metrics (e.g., total costs, QALYs) are aggregated.
• Functions Involved: This step may aggregate outputs using functions from R/heromod2.r or other utility functions. Final validations or formatting may be executed here.
Optional Logging and Reporting
• Node Label: “Logging / Reporting”
• Description: Although not explicitly shown, the package may include hooks for logging progress or reporting intermediate results.
• This could be drawn as a side-process branching from the main simulation loop.
• Input/Output nodes (e.g., JSON input, final output) could use a rounded rectangle.
• Core processing routines (e.g., Evaluate Markov Model, Simulation Loop) could use rectangles.
• That each step is as granular as possible: specify “Parse JSON”, “Validate Input via error.r”, “Setup Constants via constants.r”, “Compute Transitions via formula.r”, “Update Variables via variables.r”, etc.