Skip to contents

Make BUGS model from fitted DAG

Usage

makebugs(dag, data.dists, coefs, stderrors)

Arguments

dag

named adjacency matrix representing the DAG. Names correspond to node names.

data.dists

list of node distributions.

coefs

a list named by the node names containing for each element a matrix with the nodes' coefficients.

stderrors

a list named by the node names containing for each element a matrix with the nodes' standard errors

Value

Bugs model returned as stdout.

Examples

## Prepare data and arguments
mydists <- list(a="gaussian",
                b="multinomial",
                c="binomial",
                d="poisson")
mydag <- matrix(0, 4, 4, byrow = TRUE,
                dimnames = list(c("a", "b", "c", "d"),
                                c("a", "b", "c", "d")))
mydag[2,1] <- mydag[3,2] <- mydag[4,3] <- 1
# plotAbn(mydag, data.dists = mydists)
mycoefs <- list("a"=matrix(-6.883383e-17, byrow = TRUE,
                           dimnames = list(NULL,
                                           "a|intercept")),
                "b"=matrix(c(2.18865, 3.133928, 3.138531, 1.686432, 3.134161, 5.052104),
                           nrow= 1, byrow = TRUE,
                           dimnames = list(c(NULL),
                                      c("b|intercept.2", "b|intercept.3", "b|intercept.4",
                                      "a.2", "a.3", "a.4"))),
                "c"=matrix(c(1.11, 2.22, 3.33, 4.44, 5.55),
                           nrow= 1, byrow = TRUE,
                           dimnames = list(c(NULL),
                                      c("c|intercept", "b1", "b2", "b3", "b4"))),
                "d"=matrix(c(3.33, 4.44),
                           nrow= 1, byrow = TRUE,
                           dimnames = list(c(NULL),
                                      c("d|intercept", "c"))))
mymse <- c("a"=0,"b"=1,"c"=2,"d"=3)
## Make BUGS model
makebugs(dag = mydag, data.dists = mydists, coefs = mycoefs, stderrors = mymse)
#> model{
#> a ~ dnorm(mu.a, precision.a) # Gaussian response
#> mu.a <- -6.883383e-17 # Linear regression
#> precision.a <- inverse(0) # precision tau = 1/standard_dev
#> b ~ dcat(p.b) # Categorical response
#> p.b[1] <- phi.b[1]/sum(phi.b) # soft-max
#> log(phi.b[1]) <- 0 # Reference category
#> p.b[2] <- phi.b[2]/sum(phi.b) # soft-max
#> log(phi.b[2]) <- 2.18865 + 1.686432*a
#> p.b[3] <- phi.b[3]/sum(phi.b) # soft-max
#> log(phi.b[3]) <- 3.133928 + 3.134161*a
#> p.b[4] <- phi.b[4]/sum(phi.b) # soft-max
#> log(phi.b[4]) <- 3.138531 + 5.052104*a
#> c ~ dbern(p.c) # Bernoulli response
#> logit(p.c) <- 1.11 + 
#> 0.0242836145724376*b + 0.0736851897251164*b + 0.223587273987992*b + 0.678443921714454*b
#>  # logistic regression
#> d ~ dpois(lambda.d) # Poisson response
#> log(lambda.d) <- 3.33 + 4.44*c # logistic regression
#> }