Write data contained in a list of dataframes in a single file (NONMEM/Monolix format) or in several files as tables.
model1 <- inlineModel("
[LONGITUDINAL]
input = {V, Cl, a1}
EQUATION:
Cc = pkmodel(V, Cl)
DEFINITION:
y1 ={distribution=lognormal, prediction=Cc, sd=a1}
")
adm <- list(amount=100, time=seq(0,50,by=24))
p <- c(V=10, Cl=1, a1=0.1)
y1 <- list(name='y1', time=seq(5,to=50,by=5))
res1a <- simulx( model = model1,
treatment = adm,
parameter = p,
output = y1,
group = list(size=5),
settings = list(seed = 32323))
## [INFO] The lixoftConnectors package has been successfully initialized:
## lixoftConnectors package version -> 2019.1
## Lixoft softwares suite version -> 2019R1
Use writeDatamlx
to write the results of the simulation in a csv
file using the standard format used by Monolix,
## id time y amount
## 1 1 0 . 100
## 2 1 5 5.75182 .
## 3 1 10 3.50217 .
## 4 1 15 2.05825 .
## 5 1 20 1.43786 .
## 6 1 24 . 100
in a txt
file,
writeDatamlx(res1a, result.file = "res1a.txt", sep="\t")
head(read.table("res1a.txt", header=TRUE, sep="\t"))
## id time y amount
## 1 1 0 . 100
## 2 1 5 5.75182 .
## 3 1 10 3.50217 .
## 4 1 15 2.05825 .
## 5 1 20 1.43786 .
## 6 1 24 . 100
or in several files in a folder
## [1] "treatment.csv" "y1.csv"
Data can be written both in a single file and in separated files in a folder
Remark: instead of using writeDatamlx
, it is possible to ask simulx
to write the results of the simulation in a file and/or in a folder.
res1b <- simulx( model = model1,
treatment = adm,
parameter = p,
output = y1,
group = list(size=5, level="individual"),
result.file ="res1b.csv",
result.folder ="res1b",
settings = list(seed = 32323))
head(read.csv("res1b.csv"))
## time y amount
## 1 0 . 100
## 2 5 5.7518 .
## 3 10 3.5022 .
## 4 15 2.0583 .
## 5 20 1.4379 .
## 6 24 . 100
## [1] "treatment.csv" "y1.csv"
A column group and a column rep are added to the data file when several groups and several replicates are defined
g1 = list(size=5, treatment=list(amount=100, time=seq(0,50,by=12)))
g2 = list(size=3, treatment=list(amount=50, time=seq(0,50,by=12)))
res1c <- simulx( model = model1,
parameter = p,
group = list(g1,g2),
nrep = 10,
output = y1)
writeDatamlx(res1c, result.file = "res1c.csv")
head(read.csv("res1c.csv"))
## rep id group time y amount
## 1 1 1 1 0 . 100
## 2 1 1 1 5 6.29267 .
## 3 1 1 1 10 4.09372 .
## 4 1 1 1 12 . 100
## 5 1 1 1 15 10.45882 .
## 6 1 1 1 20 6.08368 .
A column cens and a column limit are added when (left/right/interval) censored data are simulated
y1 <- list(name='y1', time=seq(5,to=50,by=5) , lloq=3, limit=0)
res1d <- simulx( model = model1,
treatment = adm,
parameter = p,
group = list(size=5),
output = y1)
writeDatamlx(res1d, result.file = "res1d.csv")
head(read.csv("res1d.csv"))
## id time y cens limit amount
## 1 1 0 . . . 100
## 2 1 5 6.54725 0 . .
## 3 1 10 3.67595 0 . .
## 4 1 15 3 1 0 .
## 5 1 20 3 1 0 .
## 6 1 24 . . . 100
model2 <- inlineModel("
[LONGITUDINAL]
input = {V, Cl, EC50, a1, a2}
EQUATION:
Cc = pkmodel(V, Cl)
E = 100*Cc/(Cc+EC50)
DEFINITION:
y1 ={distribution=lognormal, prediction=Cc, sd=a1}
y2 ={distribution=normal, prediction=E, sd=a2}
[INDIVIDUAL]
input={V_pop,o_V,Cl_pop,o_Cl,EC50_pop,o_EC50}
DEFINITION:
V ={distribution=lognormal, prediction=V_pop, sd=o_V}
Cl ={distribution=lognormal, prediction=Cl_pop, sd=o_Cl}
EC50={distribution=lognormal, prediction=EC50_pop,sd=o_EC50}
")
p <- c(V_pop=10, o_V=0.1, Cl_pop=1, o_Cl=0.2, EC50_pop=3, o_EC50=0.2, a1=0.1, a2=1)
y2 <- list(name='y2', time=seq(2,to=50,by=6))
res2a <- simulx( model = model2,
treatment = adm,
parameter = p,
group = list(size=5, level="individual"),
output = list(y1,y2))
A column ytype is created when several outputs are written in a single data file
## id time y cens limit ytype amount
## 1 1 0 . . . . 100
## 2 1 2 77.8691 0 . 2 .
## 3 1 5 6.64948 0 . 1 .
## 4 1 8 67.72575 0 . 2 .
## 5 1 10 3.77318 0 . 1 .
## 6 1 14 52.54578 0 . 2 .
One file per output is created when the data is written into a folder
## [1] "treatment.csv" "y1.csv" "y2.csv"
Let us simulate some data using a Monolix project,
project.file <- 'monolixRuns/theophylline_project.mlxtran'
sim.res1 <- simulx(project = project.file , setting=list(seed=123456))
We can then write the results in a data file. Using writeDatamlx(..., result.file=...)
, information about the project is not used,
## id time y amount
## 1 1 0.00 . 320
## 2 1 0.25 3.22263 .
## 3 1 0.57 5.76049 .
## 4 1 1.12 7.02616 .
## 5 1 2.02 8.06874 .
## 6 1 3.82 6.80563 .
Information about the project can be used by defining the Monolix project as an input argument of writeDatamlx
. In this case, a file with the simulated data is created in the result folder, with the prefix “sim_” added to the name of the original data file,
writeDatamlx(sim.res1, project=project.file)
head(read.table("monolixRuns/theophylline_project/sim_theophylline_data.txt",header=TRUE))
## ID AMT AMT.KG TIME CONC WEIGHT SEX
## 1 1 320 4.02 0.00 . 79.6 M
## 2 1 . . 0.25 3.22263 79.6 M
## 3 1 . . 0.57 5.76049 79.6 M
## 4 1 . . 1.12 7.02616 79.6 M
## 5 1 . . 2.02 8.06874 79.6 M
## 6 1 . . 3.82 6.80563 79.6 M
Another file name can be used
writeDatamlx(sim.res1, project=project.file, result.file="theosim.txt")
head(read.table("theosim.txt",header=TRUE))
## ID AMT AMT.KG TIME CONC WEIGHT SEX
## 1 1 320 4.02 0.00 . 79.6 M
## 2 1 . . 0.25 3.22263 79.6 M
## 3 1 . . 0.57 5.76049 79.6 M
## 4 1 . . 1.12 7.02616 79.6 M
## 5 1 . . 2.02 8.06874 79.6 M
## 6 1 . . 3.82 6.80563 79.6 M
The results can also be saved in separated files in a folder
## [1] "originalId.csv" "treatment.csv" "y.csv"
Note that the original format can be used by setting format.original=TRUE in the settings of simulx:
res2 <- simulx(project=project.file, result.file="theo_test.txt",settings=list(format.original=TRUE))
print(head(read.table("theo_test.txt", sep="\t", header=TRUE)))
## ID AMT AMT.KG TIME CONC WEIGHT SEX
## 1 1 320 4.02 0.00 . 79.6 M
## 2 1 . . 0.25 3.8611 79.6 M
## 3 1 . . 0.57 7.1748 79.6 M
## 4 1 . . 1.12 7.2208 79.6 M
## 5 1 . . 2.02 8.8076 79.6 M
## 6 1 . . 3.82 8.1912 79.6 M