Skip to contents

Sample a distribution from a causal model

Usage

dhvm_sample_distribution(
  dhvm,
  parmsamp = function(k) rnorm(k),
  nsamp_latent = 1000
)

Arguments

parmsamp

A function that takes a integer as the single argument, and returns the parameters used in the linear predictors

nsamp_latent

The number of random draws to take from each unobserved variable

dag

A causal model possibly with latent variables, currently only supports binary observed variables

Value

A data frame where each row represents a distinct observation vector plus the joint probability

Examples

# example code
ivdag <- caugi(Z %-->% X %-->% Y, U %-->% X + Y) |> dhvm()
dhvm_sample_distribution(ivdag)
#>   Z X Y   prob.Y_X  prob.X_Z    prob.Z  prob.joint
#> 1 0 0 0 0.41306346 0.5639860 0.8170736 0.191353609
#> 2 1 0 0 0.41306346 0.7520119 0.1829264 0.057750529
#> 3 0 1 0 0.05847711 0.4360140 0.8170736 0.021093415
#> 4 1 1 0 0.05847711 0.2479881 0.1829264 0.002896137
#> 5 0 0 1 0.58693654 0.5639860 0.8170736 0.269464484
#> 6 1 0 1 0.58693654 0.7520119 0.1829264 0.079812261
#> 7 0 1 1 0.94152289 0.4360140 0.8170736 0.335162135
#> 8 1 1 1 0.94152289 0.2479881 0.1829264 0.042467429