Directed Acyclic Graph of Stan Model I have the following Stan model:
```{stan output.var=""}
data{
  int N;
  vector[N] x;
  vector[N] y;
  int N_rep;
}
parameters{
  real<lower = 0> mu_x; 
  real<lower = 0> mu_y; 
  real<lower=0> sigma;
}
transformed parameters{
  real prob_positive_diff;

  prob_positive_diff = mu_y >= mu_x;
}
model {
  x ~ normal(mu_x, sigma);
  y ~ normal(mu_y, sigma);

  sigma ~ normal(0, 10);
}
generated quantities{
  real p_x_new;
  real p_y_new;

  {
  vector[N_rep] x_new_ind;
  vector[N_rep] y_new_ind;
  for(n in 1:N_rep){
    x_new_ind[n] = normal_rng(mu_x, sigma) > 15 ? 1.0 : 0.0;
    y_new_ind[n] = normal_rng(mu_y, sigma) > 15 ? 1.0 : 0.0;
  }
  p_x_new = sum(x_new_ind)/N_rep;
  p_y_new = sum(y_new_ind)/N_rep;
  }

}
```

I want to construct the directed acyclic graph that represents this model.
My attempt at doing so is as follows:

Note that $y_{new}$ and $x_{new}$ in the graph correspond to y_new_ind and x_new_ind in the code, respectively. 
Based on my research, I have done the following:


*

*The nodes represents random variables.

*The directed edges represent dependencies.

*Has no loops/cycles. 



So we have that


*

*$y$ depends on $\mu_y$ and $\sigma$,

*$x$ depends on $\mu_x$ and $\sigma$,

*$y_{new}$ depends on $\mu_y$ and $\sigma$, and

*$x_{new}$ depends on $\mu_x$ and $\sigma$.


Assuming I did everything else correctly, there are 2 other question at the forefront of my mind as things that I am unsure of:
Why did I not include prob_positive_diff in the graph?
My reasoning for this is that prob_positive_diff is not, based on my understanding, a random variable per se; rather, it is a variable that is simply holding a single value: the probability that mu_y $\ge$ mu_x, where mu_y and mu_x are random variables.
Why did I not include p_x_new and p_y_new in the graph?
Honestly, I'm not sure about this one. I didn't include them because they were derived from x_new_ind and y_new_ind using simple operations, but I have a suspicion that, since they are random variables, they should be included below y_new_ind and x_new_ind with directed arrows going to them, respectively.
I would greatly appreciate it if people could please take the time to review my directed acyclic graph of this model.
 A: In this answer of mine you can find you can find an example of DAG of the Bayesian model described in JAGS language. The thing to remember is that DAG's describe the statistical model, while Stan is a programming language designed to describe and then estimate such models. What follows, there is no one-to-one translation between the code and the probabilistic model. Stan is a programming language that can be used to define many things that go beyond the definition of the model (many stuff happening in the generated quantities, or transformed parameters, also the parameters section is just about defining internal Stan objects).
Your DAG looks almost fine, but there are two things that are incorrect:


*

*You don't need the nodes for x_new and y_new, since they are just random draws from your model, they are neither parameters, nor data.

*Your definition of the priors for mu_x and mu_y is incorrect, since you define them only in the parameters section, what means for Stan that you assume uniform distribution for them (rather then normal, as in your DAG).

