# 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: russu_log_log_mog
# File: Executable_Russu_2009_dose_escalation_loglog
# Dated: Sat Jul 30 17:40:28 CEST 2016

model {
  for (ind_subj in 1:N_subj) {
    for (ind_t in 1:N_t[ind_subj]) {
      DMINinterp[ind_subj,ind_t] <- interp.function(grid[ind_subj,ind_t], grid_DMIN[ind_subj,1:N_t_DMIN[ind_subj]], DMIN[ind_subj,1:N_t_DMIN[ind_subj]])
      C[ind_subj,ind_t] <- (exp((ALPHA[ind_subj] + (BETA[ind_subj] * (log((grid[ind_subj,ind_t] / DMINinterp[ind_subj,ind_t])))))))
      Y_mean[ind_subj,ind_t] <- (C[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]
    }
    ETA_1[ind_subj] ~ dnorm(0, ETA_1_prec)
    ETA_2[ind_subj] ~ dnorm(0, ETA_2_prec)
    ALPHA[ind_subj] <- THETA1 + ETA_1[ind_subj]
    BETA[ind_subj] <- THETA2 + ETA_2[ind_subj]
  }
  Y_prec <- 1 / ((pow((SIGMA_1),2))*1)
  ETA_1_prec <- (1/(OMEGA_1))
  ETA_2_prec <- (1/(OMEGA_2))
  MU_THETA1 <- 1
  MU_THETA2 <- 1
  VAR_THETA1 <- 1
  VAR_THETA2 <- 1
  a_1 <- 1
  b_1 <- 1
  a_2 <- 1
  b_2 <- 1
  a_sigma <- 1
  b_sigma <- 1
  OMEGA_1 <- (1 / invOMEGA_1)
  OMEGA_2 <- (1 / invOMEGA_2)
  SIGMA_1 <- (sqrt((1 / invSIGMA2)))
  # PRIORS
  invOMEGA_2 ~ dgamma(a_2, invOMEGA_2_rate)
  invOMEGA_2_rate <- 1/b_2
  THETA1 ~ dnorm(MU_THETA1, THETA1_prec)
  THETA1_prec <- (1/(VAR_THETA1))
  invOMEGA_1 ~ dgamma(a_1, invOMEGA_1_rate)
  invOMEGA_1_rate <- 1/b_1
  invSIGMA2 ~ dgamma(a_sigma, invSIGMA2_rate)
  invSIGMA2_rate <- 1/b_sigma
  THETA2 ~ dnorm(MU_THETA2, THETA2_prec)
  THETA2_prec <- (1/(VAR_THETA2))
}
