setwd("Bayesiani")
source("D:\\Utenti\\ddmoreTEL\\ddmore-TEL.R\\ddmore.TEL\\R\\WinBUGS.R")

setwd("Test")
test<-"InstallationTest_BUGS.mdl"
testCOMP<-"InstallationTest_COMPARTMENT_BUGS.mdl"
BUGSSO<-runWinBUGS(test, subfolder="WINBUGSUCtest") #OK - finale
BUGSSO<-estimate(test, subfolder="WINBUGSUCtest", target="winbugs",preprocessSteps=list(prepareWinbugsDs)) #OK - finale
BUGSSO<-runWinBUGS(testCOMP, subfolder="WINBUGSUCtestCOMP") #OK - finale
setwd("..")

UC1<-"UseCase1.mdl"
UC1_1<-"UseCase1_1.mdl"
UC1_2<-"UseCase1_2.mdl"
UC2<-"UseCase2.mdl"
UC2_1<-"UseCase2_1.mdl"
UC2_2<-"UseCase2_2.mdl"
UC3<-"UseCase3.mdl"
UC3_1<-"UseCase3_1.mdl"
UC4<-"UseCase4.mdl"
UC4_1<-"UseCase4_1.mdl"
UC4_2<-"UseCase4_2.mdl"
UC4_3<-"UseCase4_3.mdl"
UC5<-"UseCase5.mdl"
UC5P1<-"UseCase5Prova1.mdl"
UC5P2<-"UseCase5Prova2.mdl"
UC5P3<-"UseCase5Prova3.mdl"
UC5P4<-"UseCase5Prova4.mdl"
UC5_1<-"UseCase5_1.mdl"
UC5_2<-"UseCase5_2.mdl"
UC6<-"UseCase6.mdl"
UC6_1<-"UseCase6_1.mdl"
UC6_2<-"UseCase6_2.mdl"
UC6_3<-"UseCase6_3.mdl"
UC7<-"UseCase7.mdl"
UC8<-"UseCase8.mdl"
UC9<-"UseCase9.mdl"
UC10<-"UseCase10.mdl"
UC10_1<-"UseCase10_1.mdl"
UC17<-"UseCase17.mdl"
Hansson<-"Hansson.mdl"
BUGSSO<-runWinBUGS(UC1, subfolder="WINBUGSUC1") # OK - finale
BUGSSO<-runWinBUGS(UC2, subfolder="WINBUGSUC2") # ok - finale
BUGSSO<-runWinBUGS(UC3, subfolder="WINBUGSUC3") # OK - finale
#BUGSSO<-runWinBUGS(UC4, subfolder="WINBUGSUC4") #dt bo
BUGSSO<-runWinBUGS(UC5, subfolder="WINBUGSUC5") # OK - finale
BUGSSO<-runWinBUGS(UC6, subfolder="WINBUGSUC6") # OK - finale
BUGSSO<-runWinBUGS(UC7, subfolder="WINBUGSUC7") # OK - finale
BUGSSO<-runWinBUGS(UC9, subfolder="WINBUGSUC9")  # OK - finale
BUGSSO<-runWinBUGS(UC10, subfolder="WINBUGSUC10") # OK - finale
BUGSSO<-runWinBUGS(Hansson, subfolder="WINBUGSHan") # invalid range sepcified
#BUGSSO<-runWinBUGS(UC17, subfolder="WINBUGSUC17") # ERRORE, non so se deve andare. FORSE cE 16?



BUGSSO<-runWinBUGS(UC1_1, subfolder="WINBUGSUC1_1") # OK - finale
#BUGSSO<-runWinBUGS(UC1_2, subfolder="WINBUGSUC1_2") # NO - general error non supported
#BUGSSO<-runWinBUGS(UC2_1, subfolder="WINBUGSUC2_1") # DT  rifare
#BUGSSO<-runWinBUGS(UC2_2, subfolder="WINBUGSUC2_2") # errore data set  rifare
#BUGSSO<-runWinBUGS(UC3_1, subfolder="WINBUGSUC3_1") # errore data set  rifare
BUGSSO<-runWinBUGS(UC4_1, subfolder="WINBUGSUC4_1") # OK - finale
BUGSSO<-runWinBUGS(UC4_2, subfolder="WINBUGSUC4_2") # OK - finale
BUGSSO<-runWinBUGS(UC4_3, subfolder="WINBUGSUC4_3") # OK - finale
BUGSSO<-runWinBUGS(UC5P1, subfolder="WINBUGSUC5P1") # OK - finale - toglie categorica
BUGSSO<-runWinBUGS(UC5P2, subfolder="WINBUGSUC5P2") # OK - finale - toglie continue
BUGSSO<-runWinBUGS(UC5P3, subfolder="WINBUGSUC5P3") # OK - finale - toglie una continua
BUGSSO<-runWinBUGS(UC5P4, subfolder="WINBUGSUC5P4") # OK - finale - toglie tutto covariate 
BUGSSO<-runWinBUGS(UC5_1, subfolder="WINBUGSUC5_1") # OK - finale -  problema su precision Y maggiore zero, debuggare
BUGSSO<-runWinBUGS(UC5_2, subfolder="WINBUGSUC5_2") # OK - finale 
BUGSSO<-runWinBUGS(UC6_1, subfolder="WINBUGSUC6_1") # OK - finale - ma si inchioda?
BUGSSO<-runWinBUGS(UC6_2, subfolder="WINBUGSUC6_2") # OK - finale - ma si inchioda?
BUGSSO<-runWinBUGS(UC6_3, subfolder="WINBUGSUC6_3") # OK - finale - lento?
BUGSSO<-runWinBUGS(UC10_1, subfolder="WINBUGSUC10_1") # OK - finale

# SIMEONI e SIMENONI POP
setwd("Test/Prova")
Simeoni<-"Simeoni_PAGE_Estimation_BUGS.mdl"
SimeoniPOP<-"Simeoni_PAGE_Estimation_POP_BUGS.mdl"
BUGSSO<-runWinBUGS(Simeoni, subfolder="WINBUGSSSIMEONI") # OK - finale
BUGSSO<-runWinBUGS(SimeoniPOP, subfolder="WINBUGSSSIMEONIPOP") # OK - finale
setwd("../..")


setwd("Priors")
UC1PrUni<-"UseCase1_PRIOR_univariate.mdl"
UC1Pr<-"UseCase1_PRIOR.mdl"
UC1Cauchy<-"UseCase1_PRIOR_Cauchy.mdl"
UCex331<-"example331.mdl"
UCex3311<-"example3311.mdl"
#UCex3312<-"example3312.mdl"
UCex332<-"example332.mdl"
UCex332_1<-"example332_1.mdl"
UCex3321<-"example3321.mdl"
UCex334<-"example334.mdl"
UCex335<-"example335.mdl"
UCex335P1<-"example335Prova.mdl"
UCex335P2<-"example335Prova2.mdl"
BUGSSO<-runWinBUGS(UC1PrUni, subfolder="WINBUGSUC1PrUni") # OK
BUGSSO<-runWinBUGS(UC1Pr, subfolder="WINBUGSUC1Pr") # OK. Ma problemi con wishart
BUGSSO<-runWinBUGS(UC1Cauchy, subfolder="WINBUGSUC1Chauchy") # OK. Ma problemi con wishart
BUGSSO<-runWinBUGS(UCex331, subfolder="WINBUGSUCex331") # OK
BUGSSO<-runWinBUGS(UCex3311, subfolder="WINBUGSUCex3311") # OK 
#BUGSSO<-runWinBUGS(UCex3312, subfolder="WINBUGSUCex3312") # NO
BUGSSO<-runWinBUGS(UCex332, subfolder="WINBUGSUCex332") # OK, but not allowed in WinBugs
BUGSSO<-runWinBUGS(UCex332_1, subfolder="WINBUGSUCex332_1") # OK
BUGSSO<-runWinBUGS(UCex3321, subfolder="WINBUGSUCex3321") # OK problema campionamento wishart
BUGSSO<-runWinBUGS(UCex334, subfolder="WINBUGSUCex334")  # OK
BUGSSO<-runWinBUGS(UCex335, subfolder="WINBUGSUCex335") # OK
BUGSSO<-runWinBUGS(UCex335P1, subfolder="WINBUGSUCex335Prova") # OK
BUGSSO<-runWinBUGS(UCex335P2, subfolder="WINBUGSUCex335Prova2") # OK errore matrici
setwd("..")	

setwd("Veri")
Magni2004<-"Executable_Magni_2004_diabetes_IVGTT.mdl" # 
Magni2006<-"Executable_Magni_2006_diabetes_MinimalModel.mdl" # 
Magni2004<-"Executable_Magni_2004_diabetes_IVGTT.mdl"
Magni2000P1<-"Magni_2000_diabetes_C-peptide1.mdl"
Magni2000P2<-"Magni_2000_diabetes_C-peptide2.mdl"
Magni2000P3<-"Magni_2000_diabetes_C-peptide3.mdl"
Magni2000P1catcov<-"Magni_2000_diabetes_C-peptide1_catcov.mdl"
Russu2009Emax<-"Executable_Russu_2009_dose_escalation_Emax.mdl"
Russu2009loglog<-"Executable_Russu_2009_dose_escalation_loglog.mdl"
Russu2009power<-"Executable_Russu_2009_dose_escalation_power.mdl"
Nathan2008<-"Executable_Nathan_2008_diabetes.mdl"
Rocchetti2013<-"Executable_Rocchetti_2013_oncology_TGI_antiangiogenic_combo.mdl"
#BUGSSO<-runWinBUGS(Magni2004, subfolder="Magni2004") # prior numerica non va
BUGSSO<-runWinBUGS(Magni2006, subfolder="Magni2006") # OK finale
BUGSSO<-runWinBUGS(Magni2000P1, subfolder="Magni2000P1") # OK else if Da riimplementare x wishart , matrice Rinv
BUGSSO<-runWinBUGS(Magni2000P2, subfolder="Magni2000P2") # OK vedi sopra 
BUGSSO<-runWinBUGS(Magni2000P3, subfolder="Magni2000P3") # OK vedi sopra
BUGSSO<-runWinBUGS(Magni2000P1catcov, subfolder="Magni2000P1catcov") # else if vedi sopra 
BUGSSO<-runWinBUGS(Russu2009Emax, subfolder="Russu2009Emax") # OK
BUGSSO<-runWinBUGS(Russu2009loglog, subfolder="Russu2009loglog") # OK 
BUGSSO<-runWinBUGS(Russu2009power, subfolder="Russu2009power") # OK
BUGSSO<-runWinBUGS(Nathan2008, subfolder="Nathan2008") # OK
BUGSSO<-runWinBUGS(Rocchetti2013, subfolder="Rocchetti2013") # OK
setwd("..")


getPopulationParameters(BUGSSO)$Bayesian
getPopulationParameters(BUGSSO, what="estimates")$Bayesian # o other options,  what= precisions, intervals, all
# it is possible also to omitt $Bayesian
getIndividualParameters(BUGSSO)
