#load the prepared the input dataset. "param" includes at least one variable "ID" and covariates, pk parameters for each ID
load('param.RData')
param$DOSEINT <- map(param$REGIMEN, from=c(2,3), to=c(336, 504))

param[!duplicated(param[c('NDOSE','REGIMEN')]),] -> param2
param2$DOSEINT <- map(param2$REGIMEN, from=c(2,3), to=c(336, 504))
param2$INFTIME <- c(2,2,1,1,1,NA,0.5,0.5,0.5)
param2$DU <- c('mg', rep('mg/kg',2), rep('mg',4), rep('mg/kg',2))
param2$DOSECMT <- c(1,2,2,1,1,2,2,2,1)



st.2w <- c(0.5,1,2,4,6,8,24,48,72,168,336)
st.3w <- c(0.5,1,2,4,6,8,24,48,72,168,336,504)
st.4w <- c(0.5,1,2,4,6,8,24,48,72,168,336,672)
st.8w <- c(st.4w, 1344)

write.csv(param2, file='../../nm/0data/param2.csv', row.names=F, na='.', quote=F)

read.csv('../../nm/0data/param2.csv', header=T, na.strings='.', as.is = T) -> param2

#one dose regimen for all subjects
sim <- create.sim.dataset(read.dose.info=F, di = 336, num.dose = 3, dose = 3, dose.unit = c('mg/kg'), 
                           dose.cmt = 1, obs.cmt = 1, smp.time = list(st.2w), smp.time.as.is = F, inf.time = 0.5, 
                           auc.interval=T, auc.cmt = 3, cov.df = param, id.var = 'ID', bw.var='BBWT',  output.suffix = NULL, export=TRUE, export.path='../../nm/0data/',
                           ss = TRUE, ss.with.addl = TRUE, addl = 100, auc.ss.interval =FALSE, smp.time.ss = NULL, only.ss = FALSE, num.dose.ss = 4, skip.dir.check=TRUE)

#A loading dose is given at the same time
sim1 <- create.sim.dataset(read.dose.info=F, di = c(0,336), num.dose = c(1,2), dose = c(3, 200), dose.unit = c('mg/kg','mg'), 
                          dose.cmt = c(2,1), obs.cmt = 1, smp.time = list(NA, st.2w), smp.time.as.is = F, inf.time = c(-1,1), 
                          auc.interval=T, auc.cmt = 3, cov.df = param2, id.var = 'ID', bw.var='BBWT', output.suffix = 's1', export=TRUE, export.path='../../nm/0data/',
                          ss = TRUE, smp.time.ss = NULL, only.ss = FALSE, num.dose.ss = 1, skip.dir.check=TRUE)

#three sequential dosing regimens for each person (including different dose intervals, doses, dose units, dose compartment and multipe AUC compartments)
sim2 <- create.sim.dataset(read.dose.info=F, di = c(336, 504, 672), num.dose = 2, dose = c(3, 240, 10), dose.unit = c('mg/kg', 'mg', 'mg/kg'),
                           dose.cmt = c(1, 1, 2), obs.cmt = c(1), smp.time = list(st.2w, st.3w, st.4w), smp.time.as.is = F, inf.time = c(1, 0.5, 2),
                           auc.interval=T, auc.cmt = c(3,5), cov.df = param2, id.var = 'ID', bw.var='BBWT', output.suffix = 's2', export=TRUE,
                           ss = TRUE, smp.time.ss = NA, only.ss = FALSE, num.dose.ss = 2, skip.dir.check=TRUE)

#read dosing information from "cov.df"
sim3 <- create.sim.dataset(read.dose.info=T, di = 'DOSEINT', num.dose = 3, dose = 'NDOSE', dose.unit = 'DU', 
                          dose.cmt = 'DOSECMT', obs.cmt = 1, smp.time = list(st.2w, st.3w), smp.time.as.is = F, inf.time = 'INFTIME', 
                          auc.interval=T, auc.cmt = 3, cov.df = param2, id.var = 'ID', bw.var='BBWT', output.suffix = 's3', export=TRUE, export.path='../../nm/0data/',
                          ss = TRUE, smp.time.ss = NA, only.ss = FALSE, num.dose.ss = 2, skip.dir.check=TRUE)

#real example: 6 doses of 360 mg Q3W, followed by 8 doses of 480 Q4W
sim4 <- create.sim.dataset(read.dose.info=F, di = c(504, 672), num.dose = c(6,9), dose = c(360, 480), dose.unit = c('mg', 'mg'),
                           dose.cmt = 1, obs.cmt = 1, smp.time = list(st.3w, st.4w), smp.time.as.is = F, inf.time = 0.5,
                           auc.interval=T, auc.cmt = 3, cov.df = param, id.var = 'ID', bw.var='BBWT', output.suffix = 's4', export=TRUE, export.path='../../nm/0data/',
                           ss = TRUE, smp.time.ss = NULL, only.ss = FALSE, num.dose.ss = 1, skip.dir.check=TRUE)

sim5 <- create.sim.dataset(read.dose.info=F, di = 336, num.dose = 26, dose = 3, dose.unit = c('mg/kg'), 
                          dose.cmt = 1, sec.dose.cmt = 2, obs.cmt = 1, smp.time = list(st.2w), smp.time.as.is = F, inf.time = NA, sec.inf.time = -2, 
                          auc.interval=T, auc.cmt = 3, cov.df = param, id.var = 'ID', bw.var='BBWT', output.suffix = 's5', export=TRUE, export.path='../../nm/0data/',
                          ss = TRUE, smp.time.ss = NULL, only.ss = FALSE, num.dose.ss = 4, skip.dir.check=TRUE)

sim6 <- create.sim.dataset(read.dose.info=F, di = 672, num.dose = 13, dose = 480, dose.unit = c('mg'), 
                           dose.cmt = 1, obs.cmt = 1, smp.time = list(st.4w), smp.time.as.is = F, inf.time = 1, 
                           auc.interval=T, auc.cmt = 3, cov.df = param, id.var = 'ID', bw.var='BBWT', output.suffix = 's6', export=TRUE, export.path='../../nm/0data/',
                           ss = TRUE, smp.time.ss = NULL, only.ss = FALSE, num.dose.ss = 2, skip.dir.check=TRUE)

sim7 <- create.sim.dataset(read.dose.info=F, di = 1344, num.dose = 7, dose = 960, dose.unit = c('mg'), 
                           dose.cmt = 1, obs.cmt = 1, smp.time = list(st.8w), smp.time.as.is = F, inf.time = 1, 
                           auc.interval=T, auc.cmt = 3, cov.df = param, id.var = 'ID', bw.var='BBWT', output.suffix = 's7', export=TRUE, export.path='../../nm/0data/',
                           ss = TRUE, smp.time.ss = NULL, only.ss = FALSE, num.dose.ss = 1, skip.dir.check=TRUE)

##steady state by ADDL
sim8 <- create.sim.dataset(read.dose.info=T, di = 'DOSEINT', num.dose = 'NUMDOSE', dose = 'NDOSE', dose.unit = 'DU', 
                   dose.cmt = 'DOSECMT', obs.cmt = 1, smp.time = list(st.2w, st.3w), smp.time.as.is = F, inf.time = 'INFTIME', 
                   auc.interval=T, auc.cmt = 3, cov.df = param2, id.var = 'ID', bw.var='BBWT', output.suffix = 's8', export=TRUE, export.path='../../nm/0data/',
                   ss = TRUE, ss.with.addl = TRUE, addl = 100, auc.ss.interval =TRUE, smp.time.ss = NULL, only.ss = FALSE, num.dose.ss = 3, skip.dir.check=TRUE)

sim9 <- create.sim.dataset(read.dose.info=F, di = 336, num.dose = 3, dose = 3, dose.unit = 'mg/kg', 
                           dose.cmt = 1, sec.dose.cmt = 2, obs.cmt = 1, smp.time = list(st.2w), smp.time.as.is = F, inf.time = NA, sec.inf.time = -2,
                           auc.interval=T, auc.cmt = c(3,5), cov.df = param2, id.var = 'ID', bw.var='BBWT', output.suffix = 's9', export=TRUE, export.path='../../nm/0data/',
                           ss = TRUE, ss.with.addl = T, addl = 100, auc.ss.interval =T, smp.time.ss = NULL, only.ss = FALSE, num.dose.ss = 2, skip.dir.check=TRUE)

# run NONMEM '../../0sim/tvCL-nivo-sim-ss-s8-addl.ctl'
# run NONMEM '../../0sim/tvCL-nivo-sim-ss-s9-addl.ctl'

#Using smp.time.ss argument when only steady state dataset is generated, smp.time can be NULL
#smp.time.ss is not required if smp.time argument is given appropriate values
sim8b <- create.sim.dataset(read.dose.info=T, di = 'DOSEINT', num.dose = 'NUMDOSE', dose = 'NDOSE', dose.unit = 'DU', 
                           dose.cmt = 'DOSECMT', sec.dose.cmt = 'SDOSECMT', obs.cmt = 1, smp.time = list(st.2w, st.3w), smp.time.as.is = F, inf.time = 'INFTIME', sec.inf.time = 'SINFTIME',
                           auc.interval=T, auc.cmt = 3, cov.df = param3, id.var = 'ID', bw.var='BBWT', output.suffix = 's8b', export=T, export.path='../../nm/0data/',
                           ss = T, ss.with.addl = T, addl = 100, auc.ss.interval =T, smp.time.ss = list(c(1,2,3,504), c(2,4,6,336)), only.ss = F, num.dose.ss = 'NUMDOSE', skip.dir.check=TRUE)

sim9b <- create.sim.dataset(read.dose.info=F, di = c(504), num.dose = 2, dose = c(3), dose.unit = c('mg/kg'), 
                           dose.cmt = 2, obs.cmt = 1, smp.time = NULL, smp.time.as.is = F, inf.time = 0.5, 
                           auc.interval=T, auc.cmt = 3, cov.df = param2, id.var = 'ID', bw.var='BBWT', output.suffix = 's9b', export=T, export.path='../../nm/0data/',
                           ss = T, ss.with.addl = T, addl = 100, auc.ss.interval =T, smp.time.ss = list(c(1,2,3,504)), only.ss = T, num.dose.ss = 3, skip.dir.check=TRUE)


#QD dosing with a no-dose period in between; also use multiple AUC compartments
sim.qd <- create.sim.dataset(read.dose.info=F, di = rep(c(24,96,48),3), num.dose = rep(c(5,1,3),3), dose = rep(c(3,0,3),3), dose.unit = c('mg/kg'), 
                             dose.cmt = 1, obs.cmt = 2, smp.time = rep(list(st.qd, st.q4d, st.q2d),3), inf.time = 1, 
                             auc.interval=rep(c(T,F,T),3), auc.cmt = c(3,5,7), cov.df = param2, id.var = 'ID', bw.var='BBWT', output.suffix = 'qd', export=TRUE, export.path='../../nm/0data/',
                             ss = TRUE, smp.time.ss = NULL, only.ss = FALSE, num.dose.ss = 4, skip.dir.check=TRUE)

#With a bigger AUC interval than the dosing interval
sim.bigAUCINT <- create.sim.dataset(read.dose.info=F, di = 24, num.dose = c(5,2,3), dose = 3, dose.unit = c('mg/kg'), 
                                    dose.cmt = 1, obs.cmt = 1, smp.time = list(st.qd), inf.time = 1, 
                                    auc.interval=c(T,F,T), auc.cmt = 3, cov.df = param2, id.var = 'ID', bw.var='BBWT', output.suffix = 'bigAUCINT', export=TRUE, export.path='../../nm/0data/',
                                    ss = TRUE, smp.time.ss = NULL, only.ss = FALSE, num.dose.ss = 4, skip.dir.check=TRUE)

# Ipi + Nivo combination regimen
#   W1	W3	W5	W7	W9	W11	W13	W15	W17	W19	W21	W23
#   I3			    I3			    I3			    I3		
#   --	N1	N1	--	N1	N1	--	N1	N1	--	N1	N1

sim10 <- create.sim.dataset(read.dose.info=F, di = 336, num.dose = rep(c(1,1,1), 4),  dose = rep(c(0, 1, 5),4), dose.unit = c('mg/kg'), 
                   dose.cmt = 1, obs.cmt = 1, smp.time = list(st.2w), inf.time = rep(c(0,1,0.5), 4), 
                   auc.interval=c(T), auc.cmt = 3, cov.df = param2, id.var = 'ID', bw.var='BBWT', output.suffix = 's10', export=TRUE, export.path='../../nm/0data/',
                   ss = TRUE, smp.time.ss = NULL, only.ss = FALSE, num.dose.ss = 3, skip.dir.check=TRUE)


#process the output from s8, s9 (steady state only)
exp8 <- process.simout(nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s8-addl/', nm.output.ss = 's8',
                       type = 'summary.exposure', keep.col = c('BBWT','DI','NDOSESIM'), dose.no='all', scenario = '')

ct8 <- process.simout(nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s8-addl/', 
                          type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSESIM'), dose.no='all', scenario = 'Various', cmt = 1, addl = 100)

exp9 <- process.simout(nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s9-addl/', 
                        type = 'summary.exposure', keep.col = c('BBWT','DI','NDOSESIM'), dose.no='all', scenario = '3 mg/kg Q2W', cmt=2)

ct9 <- process.simout(nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s9-addl/', 
                           type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSESIM'), dose.no='all', scenario = '3 mg/kg Q2W', cmt=1, addl = 100)


noquote(paste0(names(sim5[[1]]), collapse=' '))
noquote(paste0(names(sim5[[2]]), collapse=' '))

noquote(paste0(names(sim8), collapse=' '))

#run NONMEM simulation under '../../nm/0sim/'
#===================================================
#process the simulation output

#Get the summary exposure (Cmin, Cmax and Cavg) after the 1,2,8 and 12 doses and steady state
system.time(exp4 <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s4/simout.s4', nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s4/simout.ss.s4', 
                                   type = 'summary.exposure', keep.col = c('BBWT'), dose.no=c(1,2,8,12), scenario = '360 mg Q3W, 480 mg Q4W'))

#Get summary exposure after every dose simulated (including steady state)
system.time(exp4all <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s4/', nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s4/', 
                                   type = 'summary.exposure', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '360 mg Q3W, 480 mg Q4W'))

#Get summary exposure after every dose simulated (including steady state)
system.time(exp4dh <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s4/', 
                                      type = 'summary.exposure', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '360 mg Q3W, 480 mg Q4W'))

#Get summary exposure steady state only
system.time(exp4ss <- process.simout(nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s4/', 
                                      type = 'summary.exposure', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '360 mg Q3W, 480 mg Q4W'))

#Derive a new exposure metric CAVGD28 based on the CAVG1 and CAVG2, and CMIND28 = CMIN2
exp5cavgd28 <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s5/', nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s5/', 
                       type = 'summary.exposure', keep.col = c('BBWT'), dose.no=c(1,2), derive.new.var=list('CAVGD28 = (CAVG1+CAVG2)/2', 'CMIND28 = CMIN2') ,scenario = '3 mg/kg Q2W')
#Note: the drive.new var argument should be used with cautions for different dosing regimens

head(exp5cavgd28)

##Concentration vs time profiles
#Get concentration vs time profile for all doses (including steady state)
ct4 <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s4/', nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s4/', 
                                  type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '360 mg Q3W, 480 mg Q4W')

#CT profile for dosing history only
ct4dh <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s4/', 
                                  type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '360 mg Q3W, 480 mg Q4W')

#CT profile for steady state only
ct4ss <- process.simout(nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s4/', 
                                  type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '360 mg Q3W, 480 mg Q4W')

#Get concentration vs time profile for the first ten doses (including steady state)
ct4m <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s4/', nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s4/', 
                                  type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSE'), dose.no=c(1:10), scenario = '360 mg Q3W, 480 mg Q4W')

ct4mdh <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s4/',  
                                   type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSE'), dose.no=c(1:7), scenario = '360 mg Q3W, 480 mg Q4W')

ct4mss <- process.simout(nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s4/', 
                                   type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSE'), dose.no=c(1:7), scenario = '360 mg Q3W, 480 mg Q4W')


##More scenarios
ct5 <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s5/', nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s5/',
                        type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '3 mg/kg Q2W')

ct5dh <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s5/', 
                      type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '3 mg/kg Q2W')

exp5dh <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s5/', 
                        type = 'summary.exposure', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '3 mg/kg Q2W')

ct6 <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s6/', nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s6/',
                        type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '480 mg Q4W')

ct6dh <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s6/', 
                        type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '480 mg Q4W')

exp6dh <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s6/', 
                         type = 'summary.exposure', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '480 mg Q4W')

ct7 <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s7/', nm.path.ss = '../../nm/0sim/tvCL-nivo-sim-ss-s7/',
                      type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '960 mg Q8W')

ct7dh <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s7/', 
                                    type = 'conc.vs.time', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '960 mg Q8W')

exp7dh <- process.simout(nm.path = '../../nm/0sim/tvCL-nivo-sim-s7/', 
                         type = 'summary.exposure', keep.col = c('BBWT','DI','NDOSE'), dose.no='all', scenario = '960 mg Q8W')

#============Plots

plot1 <- ct.plot.overlaid(ct.df = list(ct5, ct6), time.window = c(0, 672), export = F, scale=list(y=list(relation='free')))

#without SS
ct.plot.overlaid(ct.df = list(ct5dh, ct6dh), time.window = c(0, 672), export = F, layout=c(1,1))

#another example
  ct.plot.overlaid(ct.df = list(ct5, ct6), time.window = c(672, 672*2), xlab='Time [Week]', export = F)

plot2 <- ct.plot.overlaid(ct.df = list(ct5, ct6), export = F)

plot3 <- ct.plot.with.pi(ct.df = list(ct5, ct6, ct7), safety.margin = c(387, 603), export = F)
#another example
  ct.plot.with.pi(ct.df = list(ct5dh, ct6dh), safety.margin = c(387, 603), xlab='Time [Month]', export = F)

plot4 <- smr.exp.vs.time(exp.df = list( exp5dh, exp4dh, exp6dh), exp = 'CMAX', export = F)
#another example
  smr.exp.vs.time(exp.df = list( exp5dh, exp4dh, exp6dh), exp = 'CMAX', xlab='Time [Day]', export = F)

#count the data and calculate a percentage
param$WTCUT <- cut2(param$BBWT,cuts=c(65, 90))

count.pct(data=param, count.var = 'ID', count.by.var1 = c('WTCUT','SEX'))
count.pct(data=exp5d1, count.var = 'ID', cov.df=param, count.by.var1 = 'WTCUT', count.by.var2='TTYPEF2')
count.pct(data=exp5d1, subset='SEX==1', count.var = 'ID', cov.df=param, count.by.var1 = 'WTCUT', count.by.var2='TTYPEF2', overall=T, cat.results=T)
count.pct(data=exp5d1, count.var = 'ID', cov.df=param, count.by.var1 = c('WTCUT','SEX'), count.by.var2=c('TTYPEF2'), overall=T,  cat.results=T, report.all=F)
count.pct(data=exp5d1, count.var = 'ID', cov.df=param, count.by.var1 = c('WTCUT'), count.by.var2=c('SEX','TTYPEF2'), overall=F)
count.pct(data=exp5d1, count.var = 'ID', cov.df=param, count.by.var1 = c('WTCUT','SEX'), count.by.var2=c('RACE','TTYPEF2'), overall=F)
#count unique values
count.pct(data=exp5d1, count.var = 'CMAX1', count.unique = FALSE, cov.df=param, count.by.var1 = 'WTCUT', count.by.var2='TTYPEF2', overall=T, cat.results=T, report.all=F)
count.pct(data=exp5d1, count.var = 'CMAX1', count.unique = TRUE, cov.df=param, count.by.var1 = c('WTCUT','SEX'), count.by.var2=c('TTYPEF2'), overall=T)

# png(file='../plots/ct-plot-overlaid-1.png', width=1000, height=600); print(plot1); dev.off()
# png(file='../plots/ct-plot-overlaid-2.png', width=1000, height=600); print(plot2); dev.off()
# png(file='../plots/ct-plot-with-pi.png', width=1000, height=600); print(plot3); dev.off()
# png(file='../plots/Cmax-vs-time.png', width=1000, height=600); print(plot4); dev.off()

# system('rm ../plots/*-b.png')
# plot3b <- ct.plot.with.pi(ct.df = list(ct5dh, ct6dh, ct7dh), safety.margin = c(387, 603))
# png(file='../plots/ct-plot-with-pi-b.png', width=1000, height=600); print(plot3b); dev.off()
# 
# plot4b <- smr.exp.vs.time(exp.df = list( exp5dh, exp6dh, exp7dh), exp = 'CMAX')
# png(file='../plots/Cmax-vs-time-b.png', width=1000, height=600); print(plot4b); dev.off()


read.csv('../../nm/0data/param3.csv', header=T, na.strings='.', as.is = T) -> param3

#oral dose are introduced into two compartments (e.g. to model zero order and first order simultaneously)
#read dose info from cov.df
sim11 <- create.sim.dataset(read.dose.info=T, di = 'DOSEINT', num.dose = 'NUMDOSE', dose = 'NDOSE', dose.unit ='DU', 
                   dose.cmt = 'DOSECMT', sec.dose.cmt = 'SDOSECMT' , obs.cmt = 1, smp.time = list(st.2w, st.3w), smp.time.as.is = F, inf.time = 'INFTIME', sec.inf.time = 'SINFTIME', 
                   auc.interval=T, auc.cmt = 3, cov.df = param3, id.var = 'ID', bw.var='BBWT', output.suffix = 's11', export=TRUE, export.path='../../nm/0data/',
                   ss = TRUE, smp.time.ss = NULL, ss.with.addl = F, addl = NULL, only.ss = T, num.dose.ss = 3, skip.dir.check=TRUE)

sim11b <- create.sim.dataset(read.dose.info=T, di = 'DOSEINT', num.dose = 'NUMDOSE', dose = 'NDOSE', dose.unit ='DU', 
                            dose.cmt = 'DOSECMT', sec.dose.cmt = 'SDOSECMT' , obs.cmt = 1, smp.time = list(st.2w, st.3w), smp.time.as.is = F, inf.time = 'INFTIME', sec.inf.time = 'SINFTIME', 
                            auc.interval=T, auc.cmt = 3, cov.df = param3, id.var = 'ID', bw.var='BBWT', output.suffix = 's11b', export=TRUE, export.path='../../nm/0data/',
                            ss = TRUE, smp.time.ss = NULL, ss.with.addl = T, addl = 100, only.ss = T, num.dose.ss = 3, skip.dir.check=TRUE)

#dosing info provided through arugments directly
sim12 <- create.sim.dataset(read.dose.info=F, di = c(336,504,336), num.dose = c(2,2,3), dose = c(240, 3, 10), dose.unit =c('mg','mg/kg','mg/kg'), 
                   dose.cmt = 1,  sec.dose.cmt = c(NA, 2, 2), obs.cmt = 2, smp.time = list(st.2w, st.3w, st.2w), smp.time.as.is = F, inf.time = c(-1, NA, NA),  sec.inf.time = c(NA,-2, -2),
                   auc.interval=T, auc.cmt = 3, cov.df = param2, id.var = 'ID', bw.var='BBWT', output.suffix = 's12', export=TRUE, export.path='../../nm/0data/',
                   ss = TRUE, smp.time.ss = NULL, ss.with.addl = F, addl = NULL, only.ss = F, num.dose.ss = 3, skip.dir.check=TRUE)

sim12b <- create.sim.dataset(read.dose.info=F, di = c(336,504,336), num.dose = c(2,2,3), dose = c(240, 3, 10), dose.unit =c('mg','mg/kg','mg/kg'), 
                            dose.cmt = 1,  sec.dose.cmt = c(NA, 2, 2), obs.cmt = 2, smp.time = list(st.2w, st.3w, st.2w), smp.time.as.is = F, inf.time = c(-1, NA, NA),  sec.inf.time = c(NA,-2, -2),
                            auc.interval=T, auc.cmt = 3, cov.df = param2, id.var = 'ID', bw.var='BBWT', output.suffix = 's12b', export=TRUE, export.path='../../nm/0data/',
                            ss = TRUE, smp.time.ss = NULL, ss.with.addl = T, addl = 100, only.ss = TRUE, num.dose.ss = 3, skip.dir.check=TRUE)
