mjskay / metabayes

R package for specifying Bayesian models (JAGS, Stan) as R code
1 stars 2 forks source link

Allow interleaving of blocks in metastan #6

Open mjskay opened 9 years ago

mjskay commented 9 years ago

So that transformations (for example) can be placed closer to their context of use to make code more readable. Something along the lines of this:

metastan(
  data = {
    J : int(lower=0)
    y[J] : real
    sigma[J] : real(lower=0)
  },
  parameters {
    mu : real
    tau : real(lower=0)
    eta[J] : real
  },
  transformed_parameters {
    theta[J] : real
    for (j in 1:J) {
      theta[j] <- mu + tau * eta[j]
    }
  },
  model {
    eta ~ normal(0, 1)
    y ~ normal(theta, sigma)
  }
)

becomes more like this:

metastan({
  J : int(lower=0)
  y[J] : real

  mu : real : parameters
  tau : real(lower=0) : parameters
  eta[J] : real : parameters
  eta ~ normal(0, 1)

  #or maybe
  eta[J] : real @parameters

  #or
  parameters::eta[J] : real

  {
    theta[J] : real
    for (j in 1:J) {
      theta[j] <- mu + tau * eta[j]
    }
  }@transformed_parameters

  #or maybe
  transformed_parameters: {
    ...
  }

  #or maybe
  transformed_parameters = {
    ...
  }

  data::sigma[J] : real(lower=0)
  y ~ normal(theta, sigma)
)