Replies: 2 comments 2 replies
-
Hi @huyo1444 - It's hard to tell where the NA might be coming from (the input, the model or the output processing). I've reproduced your original problem showing inputs and outputs. Could you do the same? I've also included a re-work of the problem that would be more efficient solution and reduce chances of processing problems. library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(mrgsolve)
#>
#> Attaching package: 'mrgsolve'
#> The following object is masked from 'package:stats':
#>
#> filter Reproduce original problemnothing <- c(0,0)
parameters <- data.frame(
a = nothing,
b = nothing,
c = nothing,
d = nothing,
e = c(100, 200), # amt
f = c(1,0.5), # Fa
g = c(1, 1.1) # ka
)
parameters
#> a b c d e f g
#> 1 0 0 0 0 100 1.0 1.0
#> 2 0 0 0 0 200 0.5 1.1
code <- '
[ param ] CL = 1, V = 20, ka = 1, Fa = 1
[ main ]
F_cent = Fa;
double KA = ka;
[ pkmodel ] cmt = "Xgut cent", depot = TRUE
[ error ] capture CP = cent / V;
'
mod <- mcode("na", code)
#> Building na ... done.
output <- data.frame()
for (i in 1:2) {
dat <- expand.ev(amt = parameters[i,5], ka = parameters[i,7], Fa = parameters[i, 6],
ii = 24, addl = 9)
out <- mod %>%
data_set(dat) %>%
Req(CP, Xgut) %>%
mrgsim(end = 240, delta = 1, out = "df")
out$ID<-i
output<-bind_rows(output,out)
}
head(output)
#> ID time Xgut CP
#> 1 1 0 0.000000 0.000000
#> 2 1 0 100.000000 0.000000
#> 3 1 1 36.787944 3.070263
#> 4 1 2 13.533528 4.050011
#> 5 1 3 4.978707 4.268005
#> 6 1 4 1.831564 4.212711
summary(output)
#> ID time Xgut CP
#> Min. :1.0 Min. : 0.0 Min. : 0.00000 Min. : 0.000
#> 1st Qu.:1.0 1st Qu.: 59.0 1st Qu.: 0.00000 1st Qu.: 3.725
#> Median :1.5 Median :119.5 Median : 0.00061 Median : 5.265
#> Mean :1.5 Mean :119.5 Mean : 9.46260 Mean : 5.898
#> 3rd Qu.:2.0 3rd Qu.:180.0 3rd Qu.: 0.27207 3rd Qu.: 7.454
#> Max. :2.0 Max. :240.0 Max. :200.00000 Max. :12.517 You could make this more efficient withdata <- mutate(parameters, amt = e, ka = g, Fa = f, time = 0, evid = 1, ID = c(1,2),
ii = 24, addl = 9, cmt = 1)
output <- mod %>%
data_set(data) %>%
Req(CP,Xgut) %>%
mrgsim(end = 240, output = "df")
head(output)
#> ID time Xgut CP
#> 1 1 0 0.000000 0.000000
#> 2 1 0 100.000000 0.000000
#> 3 1 1 36.787944 3.070263
#> 4 1 2 13.533528 4.050011
#> 5 1 3 4.978707 4.268005
#> 6 1 4 1.831564 4.212711 Created on 2021-12-12 by the reprex package (v2.0.1) |
Beta Was this translation helpful? Give feedback.
-
Provide the reproducible example that I asked for in the first reply.
You'll have to provide a reproducible example for this too; write some code that I can run and share it here that shows this behavior. Thanks, |
Beta Was this translation helpful? Give feedback.
-
Hi.
I wanted to conduct simulation with some sets of PK parameter value.
so I created parameter set in csv file and conducted simulation with following described code,
there are no problem, and run code, but there are some NA values in output.
for (i in 1:2) {
dat <- expand.ev(amt = parameters[i,5], ka = parameters[i,7], Fa = parameters[i, 6],
ii = 24, addl = 9)
out <- mod %>%
data_set(dat) %>%
Req(CP, Xgut) %>%
mrgsim(end = 240, delta = 1, out = "df")
out$ID<-i
output<-bind_rows(output,out)
}
Beta Was this translation helpful? Give feedback.
All reactions