MyNixOS website logo
Description

R6 Class for Structural Causal Models.

The implemented R6 class 'SCM' aims to simplify working with structural causal models. The missing data mechanism can be defined as a part of the structural model. The class contains methods for 1) defining a structural causal model via functions, text or conditional probability tables, 2) printing basic information on the model, 3) plotting the graph for the model using packages 'igraph' or 'qgraph', 4) simulating data from the model, 5) applying an intervention, 6) checking the identifiability of a query using the R packages 'causaleffect' and 'dosearch', 7) defining the missing data mechanism, 8) simulating incomplete data from the model according to the specified missing data mechanism and 9) checking the identifiability in a missing data problem using the R package 'dosearch'. In addition, there are functions for running experiments and doing counterfactual inference using simulation.

R6causal

The goal of R6causal is to make it easy to work with structural causal models. The R6 class ‘SCM’ contains methods for 1) defining a structural causal model via functions, text or conditional probability tables, 2) printing basic information on the model, 3) plotting the graph for the model using packages ‘igraph’ or ‘qgraph’, 4) simulating data from the model, 5) applying an intervention, 6) checking the identifiability of a query using the R packages ‘causaleffect’ and ‘dosearch’, 7) defining the missing data mechanism, 8) simulating incomplete data from the model according to the specified missing data mechanism and 9) checking the identifiability in a missing data problem using the R package ‘dosearch’. In addition, there are functions for running experiments and doing counterfactual inference using simulation.

Installation

You can install the released version of R6causal from CRAN with:

install.packages("R6causal")

Example

This is a basic example which shows you how define a structural causal model, plot the graph and simulate data from the model.

library(R6causal)
backdoor <- SCM$new("backdoor",
  uflist = list(
    uz = function(n) {return(stats::runif(n))},
    ux = function(n) {return(stats::runif(n))},
    uy = function(n) {return(stats::runif(n))}
  ),
  vflist = list(
    z = function(uz) {
      return(as.numeric(uz < 0.4))},
    x = function(ux, z) {
      return(as.numeric(ux < 0.2 + 0.5*z))},
    y = function(uy, z, x) {
      return(as.numeric(uy < 0.1 + 0.4*z + 0.4*x))}
  )
)
#backdoor$plot(vertex.size = 25)
backdoor$simulate(10)
backdoor$simdata
#>             uz         ux          uy z x y
#>  1: 0.95831862 0.39196794 0.321062576 0 0 0
#>  2: 0.43000353 0.02233175 0.617388078 0 1 0
#>  3: 0.48561035 0.91441259 0.001838702 0 0 1
#>  4: 0.06472618 0.82086014 0.390221544 1 0 1
#>  5: 0.36554423 0.51432070 0.203865336 1 1 1
#>  6: 0.75471971 0.57672430 0.391862174 0 0 0
#>  7: 0.75034180 0.85961544 0.652490875 0 0 0
#>  8: 0.46957831 0.20078767 0.608333027 0 0 0
#>  9: 0.09367406 0.29394365 0.488680623 1 1 1
#> 10: 0.92747329 0.84545162 0.230997331 0 0 0
Metadata

Version

0.8.3

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