/
find-optimal-distance.R
51 lines (49 loc) · 1.23 KB
/
find-optimal-distance.R
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
#' Function that finds the distance at which the sprint, probe, or
#' FV profile is optimal (i.e., equal to 100 perc)
#' @param ... Forwarded to selected \code{optimal_func}
#' @param optimal_func Selected profile optimization function. Default is \code{\link{optimal_FV}}
#' @param min,max Distance over which to find optimal profile distance
#' @return Distance
#' @export
#' @examples
#' MSS <- 10
#' MAC <- 8
#' bodymass <- 75
#'
#' fv <- create_FVP(MSS, MAC, bodymass)
#'
#' find_optimal_distance(
#' F0 = fv$F0,
#' V0 = fv$V0,
#' bodymass = fv$bodymass,
#' optimal_func = optimal_FV,
#' method = "max"
#' )
#'
#' find_optimal_distance(
#' MSS = MSS,
#' MAC = MAC,
#' optimal_func = optimal_MSS_MAC
#' )
#'
#' find_optimal_distance(
#' MSS = MSS,
#' MAC = MAC,
#' optimal_func = probe_MSS_MAC
#' )
find_optimal_distance <- function(...,
optimal_func = optimal_FV,
min = 1,
max = 60) {
opt_func <- function(par) {
(100 - optimal_func(distance = par, ...)[["profile_imb"]])^2
}
results <- stats::optim(
par = min,
fn = opt_func,
method = "Brent",
lower = min,
upper = max
)
results$par
}