R/riskFunctions.R

#' Indicator Function
#'
#' Calculates risk associated with a given amount of activity (MET hrs/week) based on the LTPA recommended minimum of 7.5 MET hrs/week. Returns 0 if this guideline is met, otherwise 1.
#'
#' @param x Activity (MET hrs/week)
#'
#' @return Risk (Value between 0 and 1)
#' @export
R.ind <- function(x) { return(ifelse(x < 7.5, 1, 0)) } # less than LTPA recommended minimum of 7.5 MET hrs/week

#' Exponential Function, per Woodcock et al
#'
#' Calculates risk associated with a given amount of activity (MET hrs/week), modeling this relationship exponentially. This risk calculation method was used by Woodcock et al.
#'
#' @param x Activity (MET hrs/week)
#'
#' @return Risk (Value between 0 and 1)
#' @export
R.exp <- function(x) { exp(-0.03*sqrt(x)) }

#' Step Function, per Arem et al
#'
#' Calculates risk associated with a given amount of activity (MET hrs/week) based on the LTPA recommended minimum of 7.5 MET hrs/week. The associated risk corresponds to multiples of this recommended minimum. This risk calculation method was used by Arem et al.
#'
#' @param x Activity (MET hrs/week)
#'
#' @return Risk (Value between 0 and 1)
#' @export
R.arem.step <- function(x) {
  x <- ifelse(x == 0, 1, # no physical activity
              ifelse(x > 0,
                     ifelse(x < 7.5, 0.8, # less than LTPA recommended minimum of 7.5 MET hours/week
                            ifelse(x < 15, 0.69, # 1-2x minimum OR > 10x minimum
                                   ifelse(x < 22.5, 0.63, # 2-3x minimum
                                   ifelse(x < 75, 0.61, 0.69 # 3-10x, > 10x minimum
                            )))),NA))
  return(x)}

#' Piecewise-Linear Function, per Arem et al
#'
#' Calculates risk associated with a given amount of activity (MET hrs/week) based on the LTPA recommended minimum of 7.5 MET hrs/week. The associated risk corresponds to multiples of this recommended minimum. This risk calculation method was used by Arem et al.
#'
#' @param x Activity (MET hrs/week)
#'
#' @return Risk (Value between 0 and 1)
#' @export
R.arem.fun <- function(x) {
  x <- ifelse(x >= 0, # no physical activity
              ifelse(x < 7.5, approxfun(c(0,7.5),c(1,0.8))(x), # less than LTPA recommended minimum of 7.5 MET hours/week
                     ifelse(x < 15, approxfun(c(7.5,15),c(0.8,0.69))(x), # 1-2x minimum OR > 10x minimum
                            ifelse(x < 22.5, approxfun(c(15,22.5),c(0.69,0.63))(x), # 2-3x minimum
                                   ifelse(x < 40, approxfun(c(22.5,40),c(0.63,0.61))(x), # 3-5.33x minimum
                                          ifelse(x < 75, approxfun(c(40,75),c(0.61,0.69))(x), 0.69 # 5.33-10x, > 10x minimum
                                                 ))))),NA)
  return(x)}

#' Step function, per Lear et al
#'
#' Calculates risk associated with a given amount of activity (MET hrs/week), placing particular emphasis on the thresholds of 10 and 50 MET hrs/week. This risk calculation method was used by Lear et al.
#'
#' @param x Activity (MET hrs/week)
#'
#' @return Risk (Value between 0 and 1)
#' @export
R.lear.step <- function(x) {
  x <- ifelse(x == 0, 1, # "Low" physical activity (< 10 MET hrs/week)
              ifelse(x > 0,
                     ifelse(x < 10, 0.8, 0.65 # "Moderate" physical activity (10-50 MET hrs/week), "High" physical activity (> 50 MET hrs/week)
                            ),NA))
  return(x)}

#' Piecewise-Linear Function, per Lear et al
#'
#' Calculates risk associated with a given amount of activity (MET hrs/week), placing particular emphasis on the thresholds of 10 and 50 MET hrs/week. This risk calculation method was used by Lear et al.
#'
#' @param x Activity (MET hrs/week)
#'
#' @return Risk (Value between 0 and 1)
#' @export
R.lear.fun <- function(x) {
  x <- ifelse(x >= 0,
              ifelse(x < 10, approxfun(c(0,10),c(1,0.8))(x), # "Low" physical activity, defined as less than 10 MET hrs/week
                     ifelse(x < 50, approxfun(c(10,50),c(0.8,0.65))(x), 0.65 # "Moderate" physical activity (10-50 MET hrs/week), "High" physical activity (> 50 MET hrs/week)
                            )),NA)
  return(x)}

#' Step Function, per Wen et al
#'
#' Calculates risk associated with a given amount of activity (MET hrs/week), based on five categories of physical activity volume. This risk calculation method was used by Wen et al.
#'
#' @param x Activity (MET hrs/week)
#'
#' @return Risk (Value between 0 and 1)
#' @export
R.wen.step <- function(x) {
  x <- ifelse(x >= 0,  
              ifelse(x < 3.75, 1, # "Inactive" physical activity volume, defined as less than 3.75 MET hrs/week
                     ifelse(x < 7.5, 0.86, # "Low" volume (3.75-7.49 MET hrs/week)
                            ifelse(x < 16.5, 0.8, # "Medium" volume (7.5-16.49 MET hrs/week)
                                   ifelse(x < 25.5, 0.71, 0.65 # "High" volume (16.5-25.49 MET hrs/week), "Very high" volume (> 25.5 MET hrs/week)
                                          )))),NA)
  return(x)}

#' Piecewise-Linear Function, per Wen et al
#'
#' Calculates risk associated with a given amount of activity (MET hrs/week), based on five categories of physical activity volume. This risk calculation method was used by Wen et al.
#'
#' @param x Activity (MET hrs/week)
#'
#' @return Risk (Value between 0 and 1)
#' @export
R.wen.fun <- function(x) {
  x <- ifelse(x >= 0, 
              ifelse(x < 3.75, approxfun(c(0,3.75),c(1,0.86))(x), # "Inactive" physical activity volume, defined as less than 3.75 MET hrs/week
                     ifelse(x < 7.5, approxfun(c(3.75,7.5),c(0.86,0.8))(x), # "Low" volume (3.75-7.49 MET hrs/week)
                            ifelse(x < 16.5, approxfun(c(7.5,16.5),c(0.8,0.71))(x), # "Medium" volume (7.5-16.49 MET hrs/week)
                                   ifelse(x < 25.5, approxfun(c(16.5,25.5),c(0.71,0.65))(x), 0.65 # "High" volume (16.5-25.49 MET hrs/week), "Very high" volume (> 25.5 MET hrs/week)
                                   )))),NA)
  return(x)}
GHI-UW/HOT documentation built on June 14, 2019, 1:21 a.m.