MyNixOS website logo
Description

Simulate Data from a DAG and Associated Node Information.

Simulate complex data from a given directed acyclic graph and information about each individual node. Root nodes are simply sampled from the specified distribution. Child Nodes are simulated according to one of many implemented regressions, such as logistic regression, linear regression, poisson regression and more. Also includes a comprehensive framework for discrete-time simulation, which can generate even more complex longitudinal data.

Project Status: Active - The project has reached a stable, usable state and is being actively developed. R-CMD-check Codecov test coverage

simDAG

Author: Robin Denz

Description

simDAG is an R-Package which can be used to generate data from a known directed acyclic graph (DAG) with associated information on distributions and causal coefficients. The root nodes are sampled first and each subsequent child node is generated according to a regression model (linear, logistic, multinomial, cox, ...) or other function. The result is a dataset that has the same causal structure as the specified DAG and by expectation the same distributions and coefficients as initially specified. It also implements a comprehensive framework for conducting discrete-time simulations in a similar fashion.

Installation

A stable version of this package can be installed from CRAN:

install.packages("simDAG")

and the developmental version may be installed from github using the remotes R-Package:

library(remotes)

remotes::install_github("RobinDenz1/simDAG")

Bug Reports and Feature Requests

If you encounter any bugs or have any specific feature requests, please file an Issue.

Examples

Suppose we want to generate data with the following causal structure:

where age is normally distributed with a mean of 50 and a standard deviation of 4 and sex is bernoulli distributed with p = 0.5 (equal number of men and women). Both of these "root nodes" (meaning they have no parents - no arrows pointing into them) have a direct causal effect on the bmi. The causal coefficients are 1.1 and 0.4 respectively, with an intercept of 12 and a sigma standard deviation of 2. death is modeled as a bernoulli variable, which is caused by both age and bmi with causal coefficients of 0.1 and 0.3 respectively. As intercept we use -15.

The following code can be used to generate 10000 samples from these specifications:

dag <- empty_dag() +
  node("age", type="rnorm", mean=50, sd=4) +
  node("sex", type="rbernoulli", p=0.5) +
  node("bmi", type="gaussian", parents=c("age", "sex"), betas=c(1.1, 0.4),
    intercept=12, error=2) +
  node("death", type="binomial", parents=c("age", "bmi"), betas=c(0.1, 0.3),
    intercept=-15)

sim_dat <- sim_from_dag(dag, n_sim=10000)

By fitting appropriate regression models, we can check if the data really does approximately conform to our specifications. First, lets look at the bmi:

mod_bmi <- glm(bmi ~ age + sex, data=sim_dat, family="gaussian")
summary(mod_bmi)

This seems about right. Now we look at death:

mod_death <- glm(death ~ age + bmi, data=sim_dat, family="binomial")
summary(mod_death)

The estimated coefficients are also very close to the ones we specified. More examples can be found in the documentation and the vignette.

Citation

Use citation("simDAG") to get the relevant citation information.

License

© 2023 Robin Denz

The contents of this repository are distributed under the GNU General Public License. You can find the full text of this License in this github repository. Alternatively, see http://www.gnu.org/licenses/.

Metadata

Version

0.1.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows