# Glucose minimal model
#
# This model is used for estimation.
#
# Limitations:
# - The current implementation does not include prior distributions and Bayesian estimation
# - EVID encoded as a covariate in the data object
#
# Compatibility:
# NONMEM
# (at the time of submission, Monolix is not supported)
#
# Dataset:
# Simulated dataset 
#
# Evaluation method for this model:
# run NONMEM estimation via TEL;
# compare individual fits with figures generated by the Bayesian Minimal Model tool available at link http://lab-bioinfo.unipv.it/index.php/it/dload
#
# By Elisa Borella, Letizia Carrara, Silvia Lavezzi, Paolo Magni, Giulia Muzio, Lorenzo Pasotti, Elena Tosca
# BMS lab - Univ Pavia
# Copyright 2015
# 

magni2006_data = dataObj{
   DECLARED_VARIABLES{Y_G::observation}

   DATA_INPUT_VARIABLES{     
      ID : {use is id}
      TIME : {use is idv} #units= min
      DV : {use is dv, variable = Y_G} #mg/dl
      INS : {use is covariate}   #units = microU/ml    
      DOSE : {use is covariate}  # initial dose of glucose, units= mg/kg
#      EVID : {use is evid}
   }
   
   SOURCE{
   	srcfile: {file="Simulated_magni_2006_data.csv",   
   		      inputFormat is nonmemFormat
              }
          }
   }


magni2006_pri = priorObj{
	
	PRIOR_PARAMETERS{
	
	  # log scale
	  MU_SG_POP = -3.7
      MU_SI_POP = -7.5
      MU_P2_POP = -3.0
      MU_G0_POP = 5.6
      
      # standard deviations
      SIGMA_SG_POP = 0.45
      SIGMA_SI_POP = 0.71
      SIGMA_P2_POP = 0.63
      SIGMA_G0_POP = 0.12
	}
	
	PRIOR_VARIABLE_DEFINITION{
	  logSG_POP ~ Normal(mean=MU_SG_POP, sd=SIGMA_SG_POP)
	  logSI_POP ~ Normal(mean=MU_SI_POP, sd=SIGMA_SI_POP)
	  logP2_POP ~ Normal(mean=MU_P2_POP, sd=SIGMA_P2_POP)
	  logG0_POP ~ Normal(mean=MU_G0_POP, sd=SIGMA_G0_POP)
	  
	  pop_SG = exp(logSG_POP)
	  pop_SI = exp(logSI_POP)
	  pop_P2 = exp(logP2_POP)
	  pop_G0 = exp(logG0_POP)
	  
	  SIGMA_RES_G=1
	  CV=0.02
	  pop_GB=82
	  pop_IB=7
	}
}


magni2006_par = parObj{

   STRUCTURAL{
      #PARAMETER VALUES TO USE FOR ESTIMATION (initial values from Bayes Minimal Model tool)
      pop_SG :  {value=0.026, lo=0} # 1/min
      pop_SI : {value=0.000691, lo=0} # mL/min/uU 
      pop_P2 :{value=0.0418, lo=0} # 1/min	
      pop_G0 : {value=246, lo=0} #mg/dL	
      pop_GB : {value=82, fix=true} #mg/dl
      pop_IB : {value=7, fix=true} #	
      CV : {value=0.02, fix=true}   
   	}
   	
   	VARIABILITY{
   	SIGMA_RES_G : {value=1, fix=true, type is var}  
   	}     	
}

magni2006_mdl = mdlObj{

 	IDV { T }
 	
 	VARIABILITY_LEVELS{
 	 	DV : { level=1, type is observation }   	      
   }

	
	STRUCTURAL_PARAMETERS{
	  pop_SG 
      pop_SI 
      pop_P2
      pop_G0
      pop_GB
      pop_IB 
      CV
	}
	
	INDIVIDUAL_VARIABLES{
	  SG=pop_SG 
      SI=pop_SI 
      P2=pop_P2 	
      G0=pop_G0 	
      GB=pop_GB 
      IB=pop_IB
    }
	
	VARIABILITY_PARAMETERS{
   	 SIGMA_RES_G
	}
		
	 RANDOM_VARIABLE_DEFINITION (level=DV) {
	   EPS_RES_G ~ Normal(mean=0, var=SIGMA_RES_G)
	}
	 	
   	COVARIATES {
   	 INS 
	}
	
	MODEL_PREDICTION{
      	
		DEQ{		
			GLUC : {deriv=-(SG+X_REMOTE)*GLUC + SG*GB,   init=G0}
			X_REMOTE : {deriv=-P2*(X_REMOTE-SI*(INS-IB)) , init=0}	
    	}	
	}	
   
   OBSERVATION {
		Y_G : { type is proportionalError, proportional = CV, eps = EPS_RES_G, prediction = GLUC }
   }   
}

magni2006_task = taskObj{ 
  ESTIMATE { 
    	set algo is mcmc 
	        TARGET_SETTINGS(target="BUGS"){
            set 
            nchains = 1,
            burnin = 1,
            niter = 1,
        #    parameters = "LAMBDA0_POP,LAMBDA1_POP,K1_POP,K2_POP,W0_POP,LAMBDA0,K2,CV",
         #    thinupdater=1,
          #  thinsamples=5, # uno dei due
#           odesolver="LSODA", #oppure LSODA
        #    dic="true",
        	winbugsgui="true" # oppure no
        }
	}
}
	
magni2006 =mogObj{
	OBJECTS{
	    magni2006_data : { type is dataObj }
	    magni2006_pri : { type is priorObj }
	    magni2006_mdl : { type is mdlObj }
	    magni2006_task : { type is taskObj }
	}
}
