Skip to content

Commit

Permalink
Close #65
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Aug 21, 2020
1 parent a6a59db commit 9794d37
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 19 deletions.
44 changes: 32 additions & 12 deletions R/uptake.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,42 @@ uptake_pct_govtarget = function(
#' @inheritParams uptake_pct_govtarget
#' @export
#' @examples
#' # https://www.jtlu.org/index.php/jtlu/article/downloadSuppFile/862/360)
#' # Equation 1B:
#' distance = 15
#' gradient = 2
#' logit = -3.959 + 2.523 +
#' ((-0.5963 - 0.07626) * distance) +
#' (1.866 * sqrt(distance)) +
#' (0.008050 * distance^2) +
#' (-0.2710 * gradient) +
#' (0.009394 * distance*gradient) +
#' (-0.05135 * sqrt(distance) *gradient)
#' logit
#' # Result: -3.144098
#'
#' pcycle = exp(logit) / (1 + exp(logit))
#' # Result: 0.04132445
#' boot::inv.logit(logit)
#' uptake_pct_godutch(distance, gradient, alpha = -3.959 + 2.523, d1 = -0.5963 - 0.07626,
#' d2 = 1.866, d3 = 0.008050, h1 = -0.2710, i1 = 0.009394, i2 = -0.05135
#' )
#' # these are the default values
#' uptake_pct_godutch(distance, gradient)
#' l = routes_fast_leeds
#' pcycle_scenario = uptake_pct_godutch(l$length, l$av_incline)
#' plot(l$length, pcycle_scenario)
uptake_pct_godutch = function(
distance,
gradient,
alpha = -3.959,
d1 = -0.5963,
d2 = 1.832,
d3 = 0.007956,
h1 = -0.2872,
i1 = 0.01784,
i2 = -0.09770
) {
alpha = -3.959 + 2.523,
d1 = -0.5963 - 0.07626,
d2 = 1.866,
d3 = 0.008050,
h1 = -0.2710,
i1 = 0.009394,
i2 = -0.05135
) {
if(!exists(c("distance", "gradient")) |
!is.numeric(c(distance, gradient))) {
stop("distance and gradient need to be numbers.")
Expand All @@ -141,14 +163,12 @@ uptake_pct_godutch = function(
message("Distance assumed in m, switching to km")
distance = distance / 1000
}
pcycle_scenario = alpha + (d1 * distance) +
logit_pcycle = alpha + (d1 * distance) +
(d2 * sqrt(distance) ) + (d3 * distance^2) +
(h1 * gradient) +
(i1 * distance * gradient) +
(i2 * sqrt(distance) * gradient)
# looks like this
pcycle_scenario = pcycle_scenario + 2.499 -0.07384 * distance
boot::inv.logit(pcycle_scenario)
boot::inv.logit(logit_pcycle)
}


Expand Down
36 changes: 29 additions & 7 deletions man/uptake_pct_godutch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9794d37

Please sign in to comment.