-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriver_singlemeals.r
More file actions
146 lines (122 loc) · 4.29 KB
/
Copy pathdriver_singlemeals.r
File metadata and controls
146 lines (122 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Run each of the single meal experiments
# Load relevant packages
library(deSolve)
library(rootSolve)
# Get relevant functions
source("set_params.r")
source("init_conds.r")
source("varnames.r")
source("mealmod_KClOnly.r")
source("mealmod_MealOnly.r")
source("mealmod_MealKCl.r")
# Set parameter values
params <- set_params()
varnames <- get_varnames()
t0 = 0
tf = (6 + 8 + 2) * 60
tvals = seq(t0,tf,1)
#--------------
# Meal + KCl
#--------------
# Solve SS for initial conditions
IC <- init_conds() # baseline ICs
init_guess <- c(amt_gut = IC$amt_gut,
conc_plas = IC$conc_plas,
conc_inter = IC$conc_inter,
conc_muscle = IC$conc_muscle)
ST <- stode(init_guess, time = 0, func = mealmod_MealKCl,
parms = params)
# Update initial conditions with SS solution
IC <- as.list(ST$y)
# Run the model simulation
out_MealKCl <- as.data.frame(lsoda(unlist(IC[varnames]),
times = tvals,
func= mealmod_MealKCl,
parms = params,
rtol = 1e-8,
atol = 1e-10
)
)
#--------------
# Meal Only
#--------------
# Solve SS for initial conditions
IC <- init_conds() # baseline ICs
init_guess <- c(amt_gut = IC$amt_gut,
conc_plas = IC$conc_plas,
conc_inter = IC$conc_inter,
conc_muscle = IC$conc_muscle)
ST <- stode(init_guess, time = 0, func = mealmod_MealOnly,
parms = params)
# Update initial conditions with SS solution
IC <- as.list(ST$y)
# Run the model simulation
out_MealOnly <- as.data.frame(lsoda(unlist(IC[varnames]),
times = tvals,
func= mealmod_MealOnly,
parms = params,
rtol = 1e-8,
atol = 1e-10
)
)
#--------------
# KCl Only
#--------------
# Solve SS for initial conditions
IC <- init_conds() # baseline ICs
init_guess <- c(amt_gut = IC$amt_gut,
conc_plas = IC$conc_plas,
conc_inter = IC$conc_inter,
conc_muscle = IC$conc_muscle)
ST <- stode(init_guess, time = 0, func = mealmod_KClOnly,
parms = params)
# Update initial conditions with SS solution
IC <- as.list(ST$y)
# Run the model simulation
out_KClOnly <- as.data.frame(lsoda(unlist(IC[varnames]),
times = tvals,
func= mealmod_KClOnly,
parms = params,
rtol = 1e-8,
atol = 1e-10
)
)
#----------------
# Save results
#----------------
save_info = as.integer(readline(prompt = 'do you want to save? (0/1) '))
if (save_info) {
notes = readline(prompt = "notes for filename: ")
today <- Sys.Date()
# fname = paste(today, "_MealSim_",
# "_notes-", notes,
# sep = "")
fMealKCl <- paste("./Results/", today,
"_MealSim_",
"_type-", "MealKCl",
"_notes-", notes,
".csv",
sep = "")
write.csv(out_MealKCl, file = fMealKCl)
fMealOnly <- paste("./Results/", today,
"_MealSim_",
"_type-", "MealOnly",
"_notes-", notes,
".csv",
sep = "")
write.csv(out_MealOnly, file = fMealOnly)
fKClOnly <- paste("./Results/", today,
"_MealSim_",
"_type-", "KClOnly",
"_notes-", notes,
".csv",
sep = "")
write.csv(out_KClOnly, file = fKClOnly)
# Save all the RData
fname <- paste("./Results/", today,
"_MealSims_all",
"_notes-", notes,
".RData",
sep = "")
save.image(file = fname) # save details of workspace
}