Skip to contents

Wraps a BUGS model string with `model = @bugs begin` and `end`, if it is not already wrapped. This is useful for preparing BUGS models for use with Julia packages that expect this specific block structure.

Usage

wrap_model_to_juliaBUGS(model_code)

Arguments

model_code

A character string containing the body of a BUGS model. If the model already starts with `model = @bugs begin` and ends with `end`, the function returns it unchanged.

Value

A character string with the BUGS model wrapped properly in Julia-compatible syntax.

Examples

model_body <- "
  for i in 1:N
    r[i] ~ dbin(p[i], n[i])
    b[i] ~ dnorm(0.0, tau)
    p[i] = logistic(alpha0 + alpha1 * x1[i] + alpha2 * x2[i] + alpha12 * x1[i] * x2[i] + b[i])
  end
  alpha0 ~ dnorm(0.0, 1.0E-6)
  tau ~ dgamma(0.001, 0.001)
  sigma = 1 / sqrt(tau)
"
wrap_model_to_juliaBUGS(model_body)
#> [1] "model = @bugs begin\nfor i in 1:N\n    r[i] ~ dbin(p[i], n[i])\n    b[i] ~ dnorm(0.0, tau)\n    p[i] = logistic(alpha0 + alpha1 * x1[i] + alpha2 * x2[i] + alpha12 * x1[i] * x2[i] + b[i])\n  end\n  alpha0 ~ dnorm(0.0, 1.0E-6)\n  tau ~ dgamma(0.001, 0.001)\n  sigma = 1 / sqrt(tau)\nend"