# Script generated by the UniPV WinBUGS converter
# 'WinBUGSConverter' copyright (c) BMS - University of Pavia (2016)
# Converter Version: 1.0.0
# Source: PharmML 0.8.1
# Target: WINBUGS 1.4.3
# Run ID: run_id_0
# Model: Generated from MDL. MOG ID: Method_2_Nathan_mog
# File: Executable_Nathan_2008_diabetes
# Dated: Sat Jul 30 17:37:51 CEST 2016

model {
  for (ind_subj in 1:N_subj) {
    for (ind_t in 1:N_t[ind_subj]) {
      MPGinterp[ind_subj,ind_t] <- interp.function(grid[ind_subj,ind_t], grid_MPG[ind_subj,1:N_t_MPG[ind_subj]], MPG[ind_subj,1:N_t_MPG[ind_subj]])
      HBA1C[ind_subj,ind_t] <- (BETA0[ind_subj] + (BETA1[ind_subj] * MPGinterp[ind_subj,ind_t]))
      Y_mean[ind_subj,ind_t] <- (HBA1C[ind_subj,ind_t] + 0)
      Y[ind_subj,ind_t] ~ dnorm(Y_mean[ind_subj,ind_t], Y_prec)
      Y_res[ind_subj,ind_t] <- Y[ind_subj,ind_t]-Y_mean[ind_subj,ind_t]
    }
    BETA0[ind_subj] <- BETA0_POP
    BETA1[ind_subj] <- BETA1_POP
  }
  Y_prec <- 1 / ((pow((RES),2))*1)
  MU_BETA0_POP <- 1.5
  MU_BETA1_POP <- 0.05
  SIGMA_BETA0_POP <- 1.5
  SIGMA_BETA1_POP <- 0.05
  a_RES2 <- 1.2
  b_RES2 <- 0.0021
  RES <- (sqrt((1 / invRES2)))
  # PRIORS
  BETA1_POP ~ dnorm(MU_BETA1_POP, BETA1_POP_prec)
  BETA1_POP_prec <- 1/pow(SIGMA_BETA1_POP,2)
  invRES2 ~ dgamma(a_RES2, invRES2_rate)
  invRES2_rate <- 1/b_RES2
  BETA0_POP ~ dnorm(MU_BETA0_POP, BETA0_POP_prec)
  BETA0_POP_prec <- 1/pow(SIGMA_BETA0_POP,2)
}
