← Latest papers
📊 statistics

Simulating Complex Crossectional and Longitudinal Data using the simDAG R Package

This paper introduces the **simDAG** R package, a standardized tool that simplifies the generation of complex cross-sectional and longitudinal data by utilizing structural equations in directed acyclic graphs to support diverse data types, non-linear relationships, and arbitrary dependencies for Monte-Carlo simulation studies.

Original authors: Robin Denz, Nina Timmesfeld

Published 2026-06-02
📖 4 min read☕ Coffee break read

Original authors: Robin Denz, Nina Timmesfeld

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are a chef trying to test a new recipe. Before you serve the dish to real customers, you need to know if your ingredients will work together. In the world of statistics, researchers do the same thing: they run "simulations" to test if their mathematical recipes (statistical methods) work correctly. To do this, they need to create fake data that looks and behaves exactly like the real world.

The problem? Creating this fake data is like trying to build a complex Lego castle where every brick depends on the one before it, and some bricks change shape over time. It's tedious, error-prone, and requires a lot of programming skill.

Enter simDAG, a new tool (an R package) that acts like a "smart blueprint builder" for this fake data. Here is how it works, explained simply:

1. The Blueprint: The DAG

Instead of writing thousands of lines of code to generate numbers, you draw a map called a Directed Acyclic Graph (DAG).

  • Think of it like a family tree: You have a "root" (like a parent) and "children" (variables that depend on the parent).
  • The Rule: The arrows only go one way (from parent to child), and there are no loops (you can't be your own ancestor).
  • What it does: This map tells the computer exactly how variables are connected. For example, "Smoking causes Lung Cancer," or "Age affects both Smoking and Lung Cancer."

2. The Recipe: Structural Equations

Once you have the map, you need to tell the computer how to build the data. In simDAG, you attach a "recipe" to each node (variable) on your map.

  • Root Nodes (The Start): These are variables with no parents (like a coin flip or a random number). You just say, "Make this a random number between 0 and 1."
  • Child Nodes (The Dependents): These variables depend on others. You can say, "Take the value of 'Smoking' and add 20% to it to get 'Lung Cancer risk'."
  • The Magic: You don't need to be a coding wizard. You can use simple formulas (like y = 2x + 5) or even complex functions. The package handles the heavy lifting of calculating the numbers based on your map.

3. The Time Machine: Longitudinal Data

Most fake data is just a snapshot (like a photo). But sometimes, researchers need a movie (longitudinal data) to see how things change over time.

  • The Old Way: You had to draw a new map for every single day, week, or year. If you wanted to simulate 100 days, you had to draw 100 separate maps. This was like drawing a comic strip by hand, one frame at a time.
  • The simDAG Way: It uses a Discrete-Time Simulation. Imagine a conveyor belt moving through time. Instead of drawing every frame, you give the machine one rule: "Every time the belt moves, check if an event happens."
    • Example: If you are simulating a vaccine, the machine checks every day: "Did this person get vaccinated? If yes, does their risk of side effects go up for the next 20 days?"
    • This allows researchers to simulate years of data (thousands of time points) for thousands of people without redrawing the map every time.

4. Why This Matters

The paper demonstrates that simDAG can handle:

  • Mixed Ingredients: It can generate continuous numbers (like height), categories (like "yes/no"), counts (like "number of hospital visits"), and time-to-event data (like "how long until a heart attack") all in the same simulation.
  • Complex Relationships: It handles non-linear relationships (where doubling the input doesn't just double the output) and interactions (where two variables work together to create a third effect).
  • Real-World Replication: The authors showed they could recreate the complex data generation processes from real, published scientific studies, proving the tool is powerful enough for serious research.

The Catch (Computational Cost)

The paper admits that simulating time step-by-step is like watching a movie frame-by-frame; it takes more computing power than just looking at a still photo. However, the authors built the tool to be very fast (using a special engine called data.table) so it can run on a standard office computer without needing a supercomputer.

In Summary

simDAG is a tool that lets researchers draw a simple map of how variables are connected and then automatically generates complex, realistic fake data based on that map. It turns the difficult, manual process of building simulation data into a streamlined, standardized workflow, making it easier for scientists to test their theories and ensure their statistical methods are working correctly.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →