-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprediction-functions.R
More file actions
610 lines (526 loc) · 30.8 KB
/
Copy pathprediction-functions.R
File metadata and controls
610 lines (526 loc) · 30.8 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
## This script is used for getting deSolve (numeric) predictions for the minimum release width or
## release diameter of underdominance, homing gene drive, TADE modification, or TADE suppression systems.
## It also finds the phat of TADE modification and TADE suppression systems numerically.
if (!requireNamespace("here", quietly = TRUE)) install.packages("here")
library(here)
source(here("deSolve-simulations/underdominance-functions.R"))
source(here("deSolve-simulations/homing-gd-functions.R"))
source(here("deSolve-simulations/tade-modification-functions.R"))
source(here("deSolve-simulations/tade-suppression-functions.R"))
###### Functions for quickly running simulations and returning whether the drive spread ##########
panmictic_tade_spreads_at_p0 = function(s, h, c, pd_overall, max_time, tol, suppression){
# Arguments:
# s: selection coefficient (dd fitness = 1 - s, dw fitness = 1 - hs)
# h: dominance coefficient
# c: rate at which drive cuts "a" nondisrupted target alleles in the germline
# pd_overall: the overall drive allele introduction frequency. Assuming a heterozygous release, pdw = 2*pd_overall.
# max_time: number of timesteps to simulate
# tol: tolerance to use for comparisons; drive spreads if (pfinal > (pd_overall + tol))
# suppression: if T, simulate TADE suppression. If F, simulate TADE modification
#
# Returns:
# Logical of whether the drive spread
if (!suppression){
spreads = simulate_panmictic_tade_modification(s = s, h = h, c = c, pd_overall = pd_overall, release_heterozygotes = T,
max_time = max_time, show_frequencies = F, tol = tol)
} else {
spreads = simulate_panmictic_tade_suppression(s = s, h = h, c = c, pd_overall = pd_overall, max_time = max_time,
show_frequencies = F, tol = tol)
}
return(spreads)
}
rde_drive_spreads_at_release_stat = function(system, dimension, drive_params, D,release_stat, p0, N, max_time, tol, verbose){
# For a 1D RDE, determines whether the system spreads at this release width
# Arguments:
# -system: this is one of "underdominance", "homing_gene_drive", "tade_modification", or "tade_suppression"
# -dimension: 1 or 2
# -drive_params:
# (1) if "underdominance", this is a list of "s", "phat", "cubic_approximation"
# (2) if "homing_gene_drive", this is a list of "s", "h", "c", "cubic_approximation"
# (3) if "tade_modification", this is a list of "s", "h", "c", "litter_size"
# (4) if "tade_suppression", this is a list of "s", "h", "c", "litter_size", "capacity"
# -D: diffusion constant
# -release_stat: if dimension=1, this is the release_width.
# if dimension=2, this is the release_diameter.
# -p0: the frequency of drive INDIVIDUALS within the release width
# note: for "underdominance" and "homing_gene_drive", homozygotes are released (pd = p0 within the release width)
# for "tade_modification" and "tade_suppression", heterozygotes are released (pd = 0.5*p0 within the release width)
# -N: if dimension=1, the number of slices (dx = 1/N).
# if dimension=2, the number of slices in the x-direction and y-direction (dx = dy = 1/N; N*N cells total)
# -max_time: number of time steps to simulate
# -tol: for modification systems, drive spreads if (pd.last > (p.d.full.0 + tol)).
# for suppression, drive spreads if (pd.last > (p.d.full.0 + tol)) or if (N.last < (capacity*(1 - release_area) - tol))
# -verbose: whether to print results
#
# Returns:
# whether the drive spreads in the RDE (T or F)
if (system == "underdominance"){
s = drive_params$s
phat = drive_params$phat
cubic_approximation = drive_params$cubic_approximation
if (dimension == 1){
spreads = simulate_underdominance_rde_1D(phat = phat, D = D, s = s,
release_width = release_stat,
bubble = F,
p0 = p0,
N = N, max_time = max_time,
cubic_approximation = cubic_approximation,
plot = F,
return_out = F,
tol = tol)
} else {
spreads = simulate_underdominance_rde_2D(phat = phat, D = D, s = s,
release_diameter = release_stat,
p0 = p0,
N = N,
max_time = max_time,
cubic_approximation = cubic_approximation,
plot = F, return_out = F,
tol = tol)
}
} else if (system == "homing_gene_drive"){
s = drive_params$s
h = drive_params$h
c = drive_params$c
cubic_approximation = drive_params$cubic_approximation
if (dimension == 1){
spreads = simulate_homing_gene_drive_rde_1D(s = s, h = h, c = c, D = D,
release_width = release_stat,
bubble = F, p0 = p0,
N = N, max_time = max_time,
cubic_approximation = cubic_approximation,
plot = F,
return_out = F,
tol = tol)
} else {
spreads = simulate_homing_gene_drive_rde_2D(s = s, h = h, c = c, D = D,
release_diameter = release_stat,
p0 = p0,
N = N, max_time = max_time,
cubic_approximation = cubic_approximation,
plot = F, return_out = F, tol = tol)
}
} else if (system == "tade_modification"){
s = drive_params$s
h = drive_params$h
c = drive_params$c
litter_size = drive_params$litter_size
if (dimension == 1){
spreads = simulate_tade_modification_rde_1D(s = s, h = h, c = c, D = D,
release_width = release_stat,
N = N,
max_time = max_time,
litter_size = litter_size,
p0 = p0,
release_heterozygotes = T,
plot = F, return_out = F,
tol = tol)
} else {
spreads = simulate_tade_modification_rde_2D(s = s, h = h, c = c, D = D,
release_diameter = release_stat,
N = N,
max_time = max_time, litter_size = litter_size,
p0 = p0, release_heterozygotes = T,
plot = F, return_out = F, tol = tol)
}
} else if (system == "tade_suppression"){
s = drive_params$s
h = drive_params$h
c = drive_params$c
litter_size = drive_params$litter_size
capacity = drive_params$capacity
if (dimension == 1){
spreads = simulate_tade_suppression_rde_1D(s = s, h = h, c = c, D = D,
release_width = release_stat,
N = N, max_time = max_time,
capacity = capacity, litter_size = litter_size,
p0 = p0, plot = F, return_out = F, tol = tol)
} else {
spreads = simulate_tade_suppression_rde_2D(s = s, h = h, c = c, D = D,
release_diameter = release_stat,
N = N, max_time = max_time,
capacity = capacity, litter_size = litter_size,
p0 = p0, plot = F, return_out = F, tol = tol)
}
} else {
stop(paste0(system, " is not one of: underdominance, homing_gene_drive, tade_modification, tade_suppression"))
}
if (verbose){
print(paste0(system, " system ", ifelse(spreads, "DOES spread", "DOESN'T spread"),
" at release ",ifelse(dimension == 1, "width", "diameter")," = ",release_stat," and p0 = ", p0))
}
return(spreads)
}
######################################################################################################
find_phat_tade = function(s, h, c, suppression = F,
low = 0.01, high = 0.5,
spreads_low = NULL, spreads_high=NULL,
phat.tol = 1e-5, condition.tol = 0,
max_time = 100, step = 0.01){
# Finds phat numerically through a binary search algorithm
# Note: "p0" in this context refers to the overall introduction frequency of the drive. 2*p0 is the starting frequency of heterozygotes.
#
# Arguments:
# s: selection coefficient (dd fitness = 1 - s, dw fitness = 1 - hs)
# h: dominance coefficient
# c: rate at which drive cuts "a" nondisrupted target alleles in the germline
# suppression: if T, this is for TADE suppression. If F, this is for TADE modification.
# low: the lower guess for phat
# high: the higher guess for phat
# spreads_low: whether the drive spreads at p0 = low, or NULL if not tested yet
# spreads_high: whether the drive spreads at p0 = high, or NULL if not tested yet
# phat.tol: if the difference in p0 values at which the drive doesn't spread and does spread is less than this, return the p0 at which it does spread
# condition.tol: for drive to have "spread", pfinal > (p0 + condition.tol)
# max_time: number of timesteps for the panmictic simulations to determine if drive spreads at a p0
# step: if drive doesn't spread at both low and high, next low = high and high = low - step
# and if drive does spread at both low and high, next high = low and low = high - step.
#
# Returns:
# numeric guess of phat, the minimum p0 at which the drive spreads
#
# Assumptions:
# -Random mating / no spatial structure
# -Drive is released in heterozygotes, so p0 cannot exceed 0.5
if (is.null(spreads_low)){
spreads_low = panmictic_tade_spreads_at_p0(s = s, h = h, c = c, pd_overall = low, max_time = max_time,
tol = condition.tol, suppression = suppression)
}
if (is.null(spreads_high)){
spreads_high = panmictic_tade_spreads_at_p0(s = s, h = h, c = c, pd_overall = high, max_time = max_time,
tol = condition.tol, suppression = suppression)
}
if (spreads_low & spreads_high){
high = low
low = high - step
if (low < 0){
low = 0 # never spreads at 0, so if spreads_low = F and spreads_high = T, should use midpoint
}
phat = find_phat_tade(low = low, high = high,
spreads_low = NULL, spreads_high=1,
step = step,
s = s, h = h, c = c, suppression = suppression,
phat.tol = phat.tol, condition.tol = condition.tol, max_time = max_time)
} else if (!spreads_low & !spreads_high){
if (near(high, 0.5)){
return(NA) # drive can't spread
}
low = high
high = low + step
if (high > 0.5){
high = 0.5 # max introduction; if drive can't spread here, it can never spread
}
phat = find_phat_tade(low = low, high = high,
spreads_low = 0, spreads_high = NULL,
step = step,
s = s, h = h, c = c, suppression = suppression,
phat.tol = phat.tol, condition.tol = condition.tol, max_time = max_time)
} else {
# doesn't spread low but does spread high
midpt = (low+high)/2
spreads_midpt = panmictic_tade_spreads_at_p0(s = s, h = h, c = c, pd_overall = midpt, max_time = max_time,
tol = condition.tol, suppression = suppression)
if (spreads_midpt){
if (high - midpt < phat.tol){
return(midpt)
}
phat = find_phat_tade(low = low, high = midpt,
spreads_low = 0, spreads_high = 1,
step = step,
s = s, h = h, c = c, suppression = suppression,
phat.tol = phat.tol, condition.tol = condition.tol, max_time = max_time)
} else {
if (high-midpt < phat.tol){
return(high)
}
phat = find_phat_tade(low = midpt, high = high,
spreads_low = 0, spreads_high = 1,
step = step,
s = s, h = h, c = c, suppression = suppression,
phat.tol = phat.tol, condition.tol = condition.tol, max_time = max_time)
}
}
}
reminders = function(system){
# Arguments:
# -system: this is one of "underdominance", "homing_gene_drive", "tade_modification", or "tade_suppression"
# Returns:
# No returns, just prints to the screen (1) the parameters that need to be in drive_params when calling find_critical_rde_release_stat
# and (2) the default N used in 1D D=1e-5 simulations
if (system == "underdominance"){
print("drive_params should be a list of s, phat, cubic_approximation")
print("dd are always released")
print("baseline N = 25000")
} else if (system == "homing_gene_drive"){
print("drive_params should be a list of s, h, c, cubic_approximation")
print("dd are always released")
print("baseline N = 25000")
} else if (system == "tade_modification"){
print("drive_params should be a list of s, h, c, litter_size")
print("dwAa are always released")
print("baseline N = 10000")
} else if (system == "tade_suppression") {
print("drive_params should be a list of s, h, c, litter_size, capacity")
print("dwAa are always released")
print("baseline N = 25000")
} else {
stop(paste0(system, " is not one of: underdominance, homing_gene_drive, tade_modification, tade_suppression"))
}
}
find_critical_rde_release_stat = function(system,
dimension, N,
drive_params, D,
low = 0.01, high = 0.5,
spreads_low = NULL, spreads_high=NULL,
step = 0.01,
p0 = 1, max_time = 100, condition.tol = 0,
stat.tol = 1e-5, verbose = T){
# Finds the critical RDE release width (if dimension = 1) or release diameter (if dimension = 2) numerically through a binary search algorithm
#
# Arguments:
# -system: this is one of "underdominance", "homing_gene_drive", "tade_modification", or "tade_suppression"
# -dimension: 1 or 2
# -N: if dimension=1, the number of slices (dx = 1/N).
# if dimension=2, the number of slices in the x-direction and y-direction (dx = dy = 1/N; N*N cells total)
# -drive_params:
# (1) if "underdominance", this is a list of "s", "phat", "cubic_approximation"
# (2) if "homing_gene_drive", this is a list of "s", "h", "c", "cubic_approximation"
# (3) if "tade_modification", this is a list of "s", "h", "c", "litter_size"
# (4) if "tade_suppression", this is a list of "s", "h", "c", "litter_size", "capacity"
# -D: diffusion constant
# -low: the lower guess for the critical release width (if dimension=1) or diameter (if dimension=2)
# -high: the higher guess for the critical release width (if dimension=1) or diameter (if dimension=2)
# -spreads_low: whether the drive spreads at low, or NULL if not tested yet
# -spreads_high: whether the drive spreads at high, or NULL if not tested yet
# -step: if drive doesn't spread at both low and high, next low = high and high = low - step
# and if drive does spread at both low and high, next high = low and low = high - step.
# -p0: the frequency of drive INDIVIDUALS within the release width
# note: for "underdominance" and "homing_gene_drive", homozygotes are released (pd = p0 within the release width)
# for "tade_modification" and "tade_suppression", heterozygotes are released (pd = 0.5*p0 within the release width)
# -max_time: number of time steps to simulate
# -tol: for modification systems, drive spreads if (pd.last > (p.d.full.0 + tol)).
# for suppression, drive spreads if (pd.last > (p.d.full.0 + tol)) or if (N.last < (capacity*(1 - release_area) - tol))
# -condition.tol: for drive to have "spread", pfinal > (p0 + condition.tol) or, for TADE suppression, Nfinal < (capacity*(1 - release_area) - tol)
# -stat.tol: if the difference in release_stat values at which the drive doesn't spread and does spread is less than this value,
# then return the minimum release_stat at which it does spread
# -verbose: whether to print results for each release_stat tested
#
# Returns:
# numeric guess of the critical release width (if dimension=1) or diameter (if dimension=2) for the system, based on its reaction-diffusion model
#
# Assumptions:
# -See the system Rscript for system-specific assumptions
if (is.null(spreads_low)){
spreads_low = rde_drive_spreads_at_release_stat(system = system, dimension = dimension, drive_params = drive_params,
D = D, release_stat = low, p0 = p0, N = N, max_time= max_time,
tol = condition.tol, verbose = verbose)
}
if (is.null(spreads_high)){
spreads_high = rde_drive_spreads_at_release_stat(system = system, dimension = dimension, drive_params = drive_params,
D = D, release_stat = high, p0 = p0, N = N, max_time= max_time,
tol = condition.tol, verbose = verbose)
}
if (spreads_low & spreads_high){
high = low
low = high - step
if (low < 0){
low = 0 # never spreads at 0, so if spreads_low = F and spreads_high = T, should use midpoint
}
critical_stat = find_critical_rde_release_stat(low = low, high = high,
spreads_low = NULL, spreads_high=1,
system = system,
dimension = dimension,
N = N,
drive_params = drive_params,
D = D,
step = step,
p0 = p0,
max_time = max_time,
condition.tol = condition.tol,
stat.tol = stat.tol,
verbose = verbose)
} else if (!spreads_low & !spreads_high){
if (near(high, 1)){
return(NA) # drive can't spread since width or diameter can't exceed arena length
}
low = high
high = low + step
if (high > 1){
high = 1 # max introduction; if drive can't spread here, it can never spread
}
critical_stat = find_critical_rde_release_stat(low = low, high = high,
spreads_low = 0, spreads_high=NULL,
system = system,
dimension = dimension,
N = N,
drive_params = drive_params,
D = D,
step = step,
p0 = p0,
max_time = max_time,
condition.tol = condition.tol,
stat.tol = stat.tol,
verbose = verbose)
} else {
# doesn't spread low but does spread high
midpt = (low+high)/2
spreads_midpt = rde_drive_spreads_at_release_stat(system = system, dimension = dimension, drive_params = drive_params,
D = D, release_stat = midpt, p0 = p0, N = N, max_time= max_time,
tol = condition.tol, verbose = verbose)
if (spreads_midpt){
if (high - midpt < stat.tol){
return(midpt)
}
critical_stat = find_critical_rde_release_stat(low = low, high = midpt,
spreads_low = 0, spreads_high=1,
system = system,
dimension = dimension,
N = N,
drive_params = drive_params,
D = D,
step = step,
p0 = p0,
max_time = max_time,
condition.tol = condition.tol,
stat.tol = stat.tol,
verbose = verbose)
} else {
if (high-midpt < stat.tol){
return(high)
}
critical_stat = find_critical_rde_release_stat(low = midpt, high = high,
spreads_low = 0, spreads_high=1,
system = system,
dimension = dimension,
N = N,
drive_params = drive_params,
D = D,
step = step,
p0 = p0,
max_time = max_time,
condition.tol = condition.tol,
stat.tol = stat.tol,
verbose = verbose)
}
}
}
# for finding the critical p0 given a width or diameter
find_critical_rde_p0 = function(system, dimension,
release_stat,
N,
drive_params, D,
low = 0.01, high = 1,
spreads_low = NULL, spreads_high=NULL,
step = 0.01, max_time = 100, condition.tol = 0,
stat.tol = 1e-5, verbose = T){
# Finds the critical RDE release p0 for a given release width (if dimension = 1) or
# release diameter (if dimension = 2) numerically through a binary search algorithm
#
# Note: For the underdominance system and homing_gene_drive system, p0 corresponds to pd.0 since d/d are released.
# But for tade_modification and tade_suppression, heterozygotes are released. p0 = frequency of heterozygotes within
# the release width. This means that p0 = 1 corresponds to pd.0 = 0.5 within the release shape.
#
# Arguments:
# -system: this is one of "underdominance", "homing_gene_drive", "tade_modification", or "tade_suppression"
# -dimension: 1 or 2
# -release_stat: the fixed release width if 1D or release diameter if 2D
# -N: if dimension=1, the number of slices (dx = 1/N).
# if dimension=2, the number of slices in the x-direction and y-direction (dx = dy = 1/N; N*N cells total)
# -drive_params:
# (1) if "underdominance", this is a list of "s", "phat", "cubic_approximation"
# (2) if "homing_gene_drive", this is a list of "s", "h", "c", "cubic_approximation"
# (3) if "tade_modification", this is a list of "s", "h", "c", "litter_size"
# (4) if "tade_suppression", this is a list of "s", "h", "c", "litter_size", "capacity"
# -D: diffusion constant
# -low: the lower guess for the critical p0
# -high: the higher guess for the critical p0
# -spreads_low: whether the drive spreads at low, or NULL if not tested yet
# -spreads_high: whether the drive spreads at high, or NULL if not tested yet
# -step: if drive doesn't spread at both low and high, next low = high and high = low - step
# and if drive does spread at both low and high, next high = low and low = high - step.
# -max_time: number of time steps to simulate
# -tol: for modification systems, drive spreads if (pd.last > (p.d.full.0 + tol)).
# for suppression, drive spreads if (pd.last > (p.d.full.0 + tol)) or if (N.last < (capacity*(1 - release_area) - tol))
# -condition.tol: for drive to have "spread", pfinal > (p0 + condition.tol) or, for TADE suppression, Nfinal < (capacity*(1 - release_area) - tol)
# -stat.tol: if the difference in release_stat values at which the drive doesn't spread and does spread is less than this value,
# then return the minimum release_stat at which it does spread
# -verbose: whether to print results for each release_stat tested
#
# Returns:
# numeric guess of the critical release p0 for the system, based on its reaction-diffusion model. If no p0 can allow spread, returns NA.
#
# Assumptions:
# -See the system Rscript for system-specific assumptions
if (is.null(spreads_low)){
spreads_low = rde_drive_spreads_at_release_stat(system = system, dimension = dimension, drive_params = drive_params,
D = D, release_stat = release_stat, p0 = low, N = N, max_time= max_time,
tol = condition.tol, verbose = verbose)
}
if (is.null(spreads_high)){
spreads_high = rde_drive_spreads_at_release_stat(system = system, dimension = dimension, drive_params = drive_params,
D = D, release_stat = release_stat, p0 = high, N = N, max_time= max_time,
tol = condition.tol, verbose = verbose)
}
if (spreads_low & spreads_high){
high = low
low = high - step
if (low < 0){
low = 0 # never spreads at 0, so if spreads_low = F and spreads_high = T, should use midpoint
}
critical_stat = find_critical_rde_p0(low = low, high = high,
spreads_low = NULL, spreads_high=1,
system = system, dimension = dimension,
release_stat = release_stat,
N = N,
drive_params = drive_params, D = D,
step = step, max_time = max_time, condition.tol = condition.tol,
stat.tol = stat.tol, verbose = verbose)
} else if (!spreads_low & !spreads_high){
if (near(high, 1)){
return(NA) # drive can't spread at all
}
low = high
high = low + step
if (high > 1){
high = 1 # max introduction; if drive can't spread here, it can never spread
}
critical_stat = find_critical_rde_p0(low = low, high = high,
spreads_low = 0, spreads_high=NULL,
system = system, dimension = dimension,
release_stat = release_stat,
N = N,
drive_params = drive_params, D = D,
step = step, max_time = max_time, condition.tol = condition.tol,
stat.tol = stat.tol, verbose = verbose)
} else {
# doesn't spread low but does spread high
midpt = (low+high)/2
spreads_midpt = rde_drive_spreads_at_release_stat(system = system, dimension = dimension, drive_params = drive_params,
D = D, release_stat = release_stat, p0 = midpt, N = N, max_time= max_time,
tol = condition.tol, verbose = verbose)
if (spreads_midpt){
if (high - midpt < stat.tol){
return(midpt)
}
critical_stat = find_critical_rde_p0(low = low, high = midpt,
spreads_low = 0, spreads_high=1,
system = system, dimension = dimension,
release_stat = release_stat,
N = N,
drive_params = drive_params, D = D,
step = step, max_time = max_time, condition.tol = condition.tol,
stat.tol = stat.tol, verbose = verbose)
} else {
if (high-midpt < stat.tol){
return(high)
}
critical_stat = find_critical_rde_p0(low = midpt, high = high,
spreads_low = 0, spreads_high=NULL,
system = system, dimension = dimension,
release_stat = release_stat,
N = N,
drive_params = drive_params, D = D,
step = step, max_time = max_time, condition.tol = condition.tol,
stat.tol = stat.tol, verbose = verbose)
}
}
}