The package tktdjl2r
is a companion package to use from R
the package TKTDsimulations.jl
written in julia
.
TKTDsimulations.jl
is dedicated to the simulation of a large set of TKTD models using efficient differential equations solvers implemented in julia
.
You need to have julia
installed in your computer:see here for information about julia installation
If Julia
is on your machine, then install and load tktdjl2r
library:
library(tktdjl2r)
In order to make the link from julia
to R
, you have to run the setup command:
# Julia can be quite long to install the first time.
::tktdjl2r_setup() tktdjl2r
This command is going to call the JuliaCall
R package and check or install required dependencies.
In the console, you should have (for instance on windows):
Julia version 1.5.0 at location C:\Users\...\AppData\Local\Programs\JULIA1~1.0\bin will be used.
Loading setup script for JuliaCall...
Finish loading setup script for JuliaCall.
The first time this code is run can be long. But after the first run, the run should be highly faster.
runTK(c(0,1,2,3), c(0,1,2,2), 0.5) single_runTK =
rbeta(4,10,10)
kdVector =
runTK_MCMC(c(0,1,2,3), c(0,1,2,2), kdVector) mcmc_runTK =
runSD(c(0,1,2,3), c(0,1,2,2), 0.5, 0.2, 1, 0.4) single_runSD =
data.frame(
paramDF =kd = rbeta(4,10,10),
hb = rbeta(4,10,10),
z = rbeta(4,10,10),
kk = rbeta(4,10,10))
runSD_MCMC(c(0,1,2,3), c(0,1,2,2), paramDF$kd, paramDF$hb, paramDF$z, paramDF$kk) mcmc_runSD =
runIT(c(0,1,2,3), c(0,1,2,2),0.5, 0.2, 1, 0.4) single_runIT =
data.frame(
paramDF =kd = rbeta(4,10,10),
hb = rbeta(4,10,10),
alpha = rbeta(4,10,10),
beta = rbeta(4,10,10))
runIT_MCMC(c(0,1,2,3), c(0,1,2,2), paramDF$kd, paramDF$hb, paramDF$alpha, paramDF$beta) mcmc_runIT =
library(deSolve)
function(t, State, parms, input) {
model_TK <-with(as.list(c(parms, State)), {
list(kd*(input(t) - State)) # internal damage
})
}
function(time, conc, listParameters){
deSolve_TK <- data.frame(times = time,
signal <-import = conc)
stats::approxfun(signal$times,
sigimp <-$import,
signalmethod = "linear",
rule = 2)
## values for steady state
c(D = 0)
xstart <-## model
ode(y = xstart,
out <-times = time,
func = model_TK,
parms = listParameters,
input = sigimp)
data.frame(
time = time,
exposure = conc,
TK = out[,2]
)
}
list(kd = 0.5)
listParameters = deSolve_TK(c(0,1,2,3), c(0,1,2,2), list(kd=0.5))
testR_runTK =plot(c(0,1,2,3), single_runTK$TK, type = "l", lwd = 3)
lines(c(0,1,2,3), testR_runTK$TK, col = "red", lwd = 2)
library(microbenchmark)
::microbenchmark(
microbenchmarktestJulia_runTK = runTK(c(0,1,2,3), c(0,1,2,2), 0.5),
testR_runTK = deSolve_TK(c(0,1,2,3), c(0,1,2,2), list(kd=0.5)),
times = 10
)