11
2+
3+ # Parameter Estimation in an ODE Model of Bile Acid Transport
4+
5+ # # Preliminaries
6+
27library(dMod )
38library(dplyr )
49library(ggplot2 )
10+ library(pander )
511theme_set(theme_dMod())
6- rm(list = ls())
712
8- # # Read the data ---------------------------------------------
13+ setwd(" /tmp" )
14+
15+
16+ # # The model scheme
17+
18+ # # Read the data
19+
920
1021data(BAdata )
1122data <- BAdata %> %
1223 filter(experiment == " exp1" ) %> %
1324 as.datalist()
1425covtable <- covariates(data )
15- print(covtable )
16-
1726plot(data )
1827
28+ # # Setting up the base model
29+
30+ # ## Setting up the prediction function
1931
20- # # Set up a base model ----------------------------------------
2132
22- # Set up base reactions
2333reactions <- eqnlist() %> %
34+ # addReaction(from, to, rate, description) %>%
2435 addReaction(" Tca_buffer" , " Tca_cyto" , " import_Tca*Tca_buffer" , " Basolateral uptake" ) %> %
2536 addReaction(" Tca_cyto" , " Tca_buffer" , " export_Tca_baso*Tca_cyto" , " Basolateral efflux" ) %> %
2637 addReaction(" Tca_cyto" , " Tca_canalicular" , " export_Tca_cana*Tca_cyto" , " Canalicular efflux" ) %> %
2738 addReaction(" Tca_canalicular" , " Tca_buffer" , " transport_Tca*Tca_canalicular" , " Transport bile" ) %> %
28- addReaction(" 0" , " cations" , " 0" , " Cation concentration in buffer" )
39+ # addReaction("0", "cations", "0", "Cation concentration in buffer") %>%
40+ {. }
2941
30- # Translate to ODEs and let cation concentration change transport rate
3142odes <- reactions %> %
3243 as.eqnvec() %> %
33- reparameterize(" x ~ (x*crit/(crit + cations))" , x = " transport_Tca" )
34-
35- # Set up events to control the experiment
36- events <- data.frame (
37- var = c(" Tca_buffer" , " cations" ),
38- time = c(" change_buffer" , " change_cations" ),
39- value = c(" value_buffer" , " value_cations" ),
40- method = c(" replace" , " replace" )
41- )
42-
43- # Make ODE model available as prediction function
44- noSens <- c(" change_buffer" , " change_cations" , " value_cations" , " cations" )
44+ insert(" transport_Tca ~ (transport_Tca*crit/(crit + cations))" )
45+
46+ events <- eventlist() %> %
47+ # addEvent(var, time, value, method = "replace") %>%
48+ addEvent(" Tca_buffer" , " t_addTca" , " amount_Tca" ) %> %
49+ addEvent(" Tca_buffer" , " t_removeTca" , " 0" ) %> %
50+ addEvent(" cations" , " t_removeCa" , " 0" )
51+
52+ noSens <- c(" t_removeCa" , " t_addTca" , " t_removeTca" , " cations" )
4553x <- odemodel(odes , events = events , fixed = noSens , modelname = " BA_basemodel" ) %> %
4654 Xs()
4755
48- # Make observation function available
49- g <- eqnvec(
50- buffer = " s*Tca_buffer" ,
51- cellular = " s*(Tca_cyto + Tca_canalicular)" ) %> %
56+ # # Demonstration of the usage of x()
57+ n <- getParameters(x )
58+ pars <- runif(length(n ), min = 0 , max = 100 )
59+ names(pars ) <- n
60+
61+ times <- 0 : 200
62+ pred <- x(times , pars )
63+ plot(pred ) + theme(legend.position = " none" )
64+
65+ # ## Setting up the observation function
66+
67+ g <- eqnvec(buffer = " s*Tca_buffer" ,
68+ cellular = " s*(Tca_cyto + Tca_canalicular)" ) %> %
5269 Y(f = x , modelname = " obsfn" , compile = TRUE )
5370
54- # Parameterize the model
71+ # Demonstration of the usage of g
72+ pars [" s" ] <- 1
73+ pred <- (g * x )(times , pars )
74+ plot(pred ) + theme(legend.position = " none" )
75+
76+
77+ # ## Parameterization
78+
79+
80+
5581parameters <- getParameters(g , x )
56- transformation <- eqnvec() %> %
57- reparameterize(" x~x" , x = parameters ) %> %
58- reparameterize(" x~0" , x = c(" Tca_cyto" , " Tca_canalicular" , " value_buffer" , " value_cations" )) %> %
59- reparameterize(" x~1" , x = " cations" )
60-
82+ p <- eqnvec() %> %
83+ define(" x ~ x" , x = parameters ) %> %
84+ define(" x ~ 0" , x = c(" Tca_cyto" , " Tca_canalicular" , " Tca_buffer" )) %> %
85+ define(" cations ~ 1" ) %> %
86+ define(" t_addTca ~ 0" ) %> %
87+ define(" t_removeTca ~ 30" ) %> %
88+ branch(covtable ) %> %
89+ define(" t_removeCa ~ time" , time = ifelse(changeCa == " yes" , 30 , 1e3 )) %> %
90+ insert(" x ~ exp(X)" , x = parameters , X = toupper(parameters )) %> %
91+ P()
92+
6193
62- p <- P()
63- for (c in rownames(covtable )) {
64- p <- p + transformation %> %
65- reparameterize(" x~cations" , x = " change_cations" , cations = covtable [c , " cations" ]) %> %
66- reparameterize(" x~buffer" , x = " change_buffer" , buffer = covtable [c , " drug_time" ]) %> %
67- reparameterize(" x~exp(x)" , x = parameters ) %> %
68- P(condition = c )
69- }
94+ # # Parameter estimation
7095
96+ set.seed(12837 )
7197estimate <- getParameters(p )
72- pars <- structure(rep( - 1 , length(estimate )), names = estimate )
98+ pars <- structure(runif( length(estimate ), min = - 2 , max = 0 ), names = estimate )
7399times <- seq(0 , 200 , 1 )
74100(g * x * p )(times , pars ) %> % plot(data = data , time < = 180 )
75101
76- obj <- normL2(data , g * x * p ) + constraintL2(pars , sigma = 10 )
77- myfit <- trust(obj , pars , rinit = 1 , rmax = 10 , iterlim = 500 )
78102
79- (g * x * p )(times , myfit $ argument ) %> % plot(data = data )
103+ obj <- normL2(data , g * x * p ) + constraintL2(0 * pars , sigma = 10 )
104+ myfit <- trust(obj , pars , rinit = 1 , rmax = 10 , iterlim = 500 )
80105
106+ (g * x * p )(times , myfit $ argument ) %> % plot(data = data , time < = 180 )
107+ # ## Identifiability
81108profiles <- profile(obj , myfit $ argument , names(myfit $ argument ), cores = 4 )
82109profiles %> % plotProfile(mode == " data" )
83110
84111
85112# Add additional data
86- data $ exp1_30_no_0_0_30 <- rbind(data $ exp1_30_no_0_0_30 , data.frame (
87- name = " Tca_buffer" , time = 0 , value = 21.5 , sigma = 2
88- ))
113+ data $ exp1_yes_no_0 <- data $ exp1_yes_no_0 %> %
114+ rbind(data.frame (name = " Tca_buffer" , time = 1 , value = 21.5 , sigma = 2 ))
89115
90- obj <- normL2(data , g * x * p ) + constraintL2(pars , sigma = 10 )
116+ obj <- normL2(data , g * x * p ) + constraintL2(0 * pars , sigma = 10 )
91117myfit <- trust(obj , pars , rinit = 1 , rmax = 10 , iterlim = 500 )
92118
93- (g * x * p )(times , myfit $ argument ) %> % plot(data = data )
119+ pred <- (g * x * p )(times , myfit $ argument )
120+ pred %> % plot(data = data , name %in% c(" buffer" , " cellular" , " Tca_buffer" ))
94121
95- profiles <- profile(obj , myfit $ argument , c(" s" , " Tca_buffer" ), cores = 2 )
122+
123+ profiles <- profile(obj , myfit $ argument , c(" S" , " AMOUNT_TCA" ), cores = 2 )
96124profiles %> % plotProfile(mode == " data" )
97125
126+
98127# Explore parameter space
99128fits <- mstrust(obj , pars , fits = 30 , rinit = 1 , rmax = 10 , samplefun = " runif" , min = - 5 , max = 5 , cores = 4 )
100129parframe <- as.parframe(fits )
101- plotValues(parframe [1 : 29 ,])
102- plotPars(parframe [1 : 29 ,])
103- subframe <- unique(parframe [1 : 29 ,])
130+ plotValues(parframe [1 : 28 ,])
131+ plotPars(parframe [1 : 28 ,])
132+ subframe <- unique(parframe [1 : 28 ,])
104133
105134prediction <- predict(g * x * p , times = times , pars = subframe , data = data )
106135
107- ggplot(prediction , aes(x = time , y = value , color = as.factor(.value ))) + facet_wrap(~ name * cations , scales = " free" ) +
136+ ggplot(prediction , aes(x = time , y = value , color = as.factor(round( .value )))) + facet_wrap( ~ name * changeCa , scales = " free" ) +
108137 geom_line() +
109- geom_point(data = as.data.frame(data ), color = " black" )
138+ geom_point(data = as.data.frame(data ), color = " black" ) +
139+ scale_color_discrete(name = " obj. value" )
140+
110141
111142profiles <- lapply(1 : nrow(subframe ), function (i ) {
112- profile(obj , as.parvec(subframe , i ), names(myfit $ argument ), cores = 4 , algoControl = list ( gamma = 10 ) )
143+ profile(obj , as.parvec(subframe , i ), names(myfit $ argument ), limits = c( - 4 , 4 ), cores = 4 )
113144})
114145names(profiles ) <- c(" obj = 23" , " obj = 24" , " obj = 27" )
115146profiles %> % plotProfile(mode == " data" )
116147
148+
117149partable <- confint(profiles [[1 ]], level = 0.9 , val.column = " value" )
118150
151+
119152# Save objects from this session
120153save.image(file = " part1.RData" )
121154
122-
155+
156+
0 commit comments