# Categorical and continuous variables in a DAG

**URL:** <https://discourse.mc-stan.org/t/categorical-and-continuous-variables-in-a-dag/30639>\
**Category:** General\
**Tags:** brms, specification, hierarchical-model\
**Created:** [March 6, 2023, 3:14pm UTC](https://discourse.mc-stan.org/t/categorical-and-continuous-variables-in-a-dag/30639 "2023-03-06T15:14:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michelle](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@Michelle](https://discourse.mc-stan.org/u/Michelle)\
**Post date:** [March 6, 2023, 3:14pm UTC](https://discourse.mc-stan.org/t/categorical-and-continuous-variables-in-a-dag/30639/1 "2023-03-06T15:14:50Z")

</div>

Hello,

May I ask a question about how to transfer DAG into logistic regression? I have a few categorical and continuous variables in a DAG. For one continuous variable’s causal effect on the outcome (binomial), it tells me I will need to control two categorical variables. I wonder if I should just put these two categorical variables as varying intercept like in mod1 below, or use them to build a multilevel model for both intercept and slope of the logistic regression? For instance, if I got A and B as two categorical variables, X as the continuous variable and DAG tells me to control A and B for X → outcome. Which model would make sense? Thank you very much.

```plaintext
mod1 <- brm(
  data = df, family = bernoulli(link = "logit"),
  bf(outcome ~ a + b + c, 
     a ~ 0 + A,
     b ~ 0 + B,
     c ~ 0 + X,
     nl = TRUE),
  prior = c(prior(normal(0, 1.5), nlpar = a),
            prior(normal(0, 1.5), nlpar = b),
            prior(normal(0, 1.5), nlpar = c)),
  iter = 2000, warmup = 1000, chains = 4, cores = 4)

```

```plaintext
mod2 <- brm(
  data = df, family = bernoulli(link = "logit"),
  bf(outcome ~ a + b + c + d,
     a ~ 0 + A,
     b ~ 0 + B,
     c ~ 0 + (X || A),
     d ~ 0 + (X || B),
     nl = TRUE),
  prior = c(prior(normal(0, 0.8), nlpar = a),
            prior(normal(0, 0.8), nlpar = b),
            prior(normal(0, 0.8), nlpar = c),
            prior(normal(0, 0.8), nlpar = d)),
  iter = 2000, warmup = 1000, chains = 4, cores = 4)

```

```plaintext
mod3 <- brm(
  data = df, family = bernoulli(link = "logit"),
  bf(outcome ~ 1 + A + B + X + (1 | A) + (1 | B) + (X || A) + (X || B)),
  prior = c(prior(normal(0, 1.5), class = Intercept),
            prior(normal(0, 0.5), class = b),
            prior(normal(0, 1), class = sd)),
  iter = 2000, warmup = 1000, chains = 4, cores = 4)

```
