R/tdee.R

Defines functions calculate_mean_tdee calculate_tdee

Documented in calculate_mean_tdee calculate_tdee

#' @title Calculate TDEE
#'
#' @description
#' \lifecycle{stable}
#'
#' With this function you can calculate your total daily energy expenditure
#'
#' @param rmr basal metabolic rate
#' @param objective integer between 0.8 - 1.3, Default: 1.0
#' @param effort integer between 1.2 - 1.8, Default: NULL
#'
#' @return total daily energy expenditure
#'
#' @details
#' Details on setting your objective:
#' \itemize{
#' \item 1.1 to 1.3 for mass gain
#' \item 1.0 for maintaining
#' \item 0.8 to 1.0 for mass loss
#' }
#'
#' Details on setting your effort (PAL = physical activity level):
#' \itemize{
#' \item Completely Paralyzed, Comatose, Unable to Move Without the Aid of Others (1.0)
#' \item Immobile, Stationary with Some Arm Movement, Bedridden or Partially Paralyzed (1.05)
#' \item Constricted Lifestyle, Movement is Limited to a Confined Space, Almost Always Sitting or Laying (1.1)
#' \item Working From Home with Little to No Travel, No Exercise, Some Walking, Mostly Sitting or Laying (1.16)
#' \item Sedentary Lifestyle, Little or No Exercise, Moderate Walking, Desk Job (Away from Home) (1.2)
#' \item Slightly Active, Exercise or Light Sports 1 to 3 Days a Week, Light Jogging or Walking 3 to 4 Days a Week (1.375)
#' \item Lightly Active, Exercise or Moderate Sports 2 to 3 Days a Week, Light Jogging or Walking 5 to 7 Days a Week (1.425)
#' \item Moderately Active, Physical Work, Exercise, or Sports 4 to 5 Days a Week, Construction Laborer (1.55)
#' \item Very Active, Heavy Physical Work, Exercise, or Sports 6 to 7 Days a Week, Hard Laborer (1.75)
#' \item Extremely Active, Very Heavy Physical Work or Exercise Every Day, Professional/Olympic Athlete (1.9)
#' }
#' For more details go to \url{https://www.sailrabbit.com/bmr/}
#'
#' TDEE is calculated as follows:
#' \deqn{TDEE = RMR \times objective \times effort}
#'
#' @examples
#' calculate_tdee(
#'   rmr = 2100,
#'   objective = 1,
#'   effort = 1.5
#' )
#' @rdname calculate_tdee
#' @importFrom checkmate check_number
#' @export
calculate_tdee <- function(rmr,
                           objective = 1.0,
                           effort = NULL) {
  # TODO(MJABOER): cut out objective and create function WeightGoalCalc.
  # Objective should not be in tdee. TDEE is just RMR + extra energy needed.
  # It should not contain an objective to loose or gain weight.
  # TODO(MJABOER): add ectomorph, endomorph and mesomorph body types as variable
  if (!checkmate::check_number(objective, lower = 0.8, upper = 1.3)) {
    stop("Your `objective` should be between 0.8 and 1.3")
  }
  if (!checkmate::check_number(effort, lower = 1.0, upper = 1.9)) {
    stop("Your `effort` should be between 1.0 and 1.9")
  }
  tdee <- rmr * objective
  if (effort) {
    tdee <- rmr * objective * effort
  }
  return(tdee)
}

#' @title Calculate mean TDEE from all methods
#'
#' @description
#' \lifecycle{soft-deprecated}
#'
#' `calculate_mean_tdee` calculates the mean TDEE from all
#'   available methods in calculate_rmr
#'
#' @param weight weight in kg.
#' @param height height in centimeters, Default: NULL.
#' @param age age in years, Default: NULL.
#' @param sex `male` or `female`, Default: NULL.
#' @param bfp body fat percentage. Optional variable, used when equation is
#'   'katch-mcardle', Default: NULL.
#' @inheritParams calculate_tdee
#'
#' @return tdee
#'
#' @examples
#' calculate_mean_tdee(
#'   weight = 80,
#'   height = 180,
#'   age = 30,
#'   sex = "male",
#'   bfp = 15,
#'   objective = 1,
#'   effort = 1.4
#' )
#' @rdname calculate_tdee
#' @seealso \code{\link{calculate_rmr}}
#' @export
#' @importFrom dplyr bind_rows summarise_all mutate
calculate_mean_tdee <- function(weight,
                                height,
                                age,
                                sex,
                                bfp,
                                objective,
                                effort) {
  equations <- c(
    "mifflin",
    "harris-benedict",
    "revised-harris-benedict",
    "katch-mcardle",
    "katch-mcardle-hybrid",
    "cunningham"
  )
  mean.tdee <-
    tibble::enframe(
      mapply(
        calculate_tdee,
        mapply(calculate_rmr,
               weight,
               height,
               age,
               sex,
               bfp,
               equations),
        objective,
        effort
      ),
      name = "equation",
      value = "TDEE"
    ) %>%
    dplyr::mutate(Equation = equations) %>%
    dplyr::select(Equation, TDEE) %>%
    dplyr::bind_rows(dplyr::summarise_all(.,
                                          list( ~ if (is.numeric(.)) {
                                            mean(.)
                                          } else {
                                            "mean"
                                          }))) %>%
    dplyr::mutate(TDEE = round(TDEE, 2))
  return(mean.tdee)
}

# TDEE = RMR + NREE
# NREE = TEF + PAEE
# PAEE = NEAT + EEE

#' @title Thermic effect of food
#'
#' @description
#' \lifecycle{experimental}
#'
#' TEF relates to energy needed for digestion, absorption and storage of food.
#'
#' @param tdee Total daily energy expenditure
#'
#' @return Thermic effect of food (tdee)
#'
#' @details
#' Ref: The effect of exercise on non-exercise physical activity and sedentary
#' behaviour in adults- E. L. Melanson (2017).
#'
#' @examples
#' calculate_tef(tdee = 2600)
#' @rdname calculate_tef
#' @export
calculate_tef <- function(tdee) {
  # assumed to be static at 10% of tdee
  # 6-12% ?
  tef <- tdee * 0.10
  return(tef)
}

#' @title Physical activity Energy Expenditure
#'
#' @description
#' \lifecycle{experimental}
#'
#' FUNCTION_DESCRIPTION
#'
#' @param tdee Total daily energy expenditure
#' @param rmr Resting metabolic rate
#'
#' @return OUTPUT_DESCRIPTION
#'
#' @details Same as Physical Energy Expenditure (PEE). Same as activity energy
#' expenditure (AEE)
#'
#' @examples
#' calculate_paee(tdee = 2666, rmr = 1904)
#' @rdname calculate_paee
#' @export
calculate_paee <- function(tdee, rmr) {
  # 15-30% of tdee
  # PAEE = EEE + NEAT
  paee <- 0.9 * tdee - rmr
  return(paee)
}

#' @title Exercise Energy Expenditure
#'
#' @description
#' \lifecycle{experimental}
#'
#' FUNCTION_DESCRIPTION
#'
#' @param tdee Total daily energy expenditure
#'
#' @return OUTPUT_DESCRIPTION
#'
#' @details same as exercise-related activity thermogenesis (EAT)
#'
#' @examples
#' ## calculate_eee(tdee = 2666)
#' @rdname calculate_eee
#' @export
calculate_eee <- function(tdee) {
  .NotYetImplemented()
}

#' @title Non exercise-related activity thermogenesis
#'
#' @description
#' \lifecycle{experimental}
#'
#' FUNCTION_DESCRIPTION
#'
#' @param tdee Total daily energy expenditure
#'
#' @return OUTPUT_DESCRIPTION
#'
#' @details DETAILS
#'
#' @examples
#' ## calculate_neat(tdee = 2666)
#' @rdname calculate_neat
#' @export
calculate_neat <- function(tdee) {
  .NotYetImplemented()
}

#' @title Physical activity level
#'
#' @description
#' \lifecycle{experimental}
#'
#' FUNCTION_DESCRIPTION
#'
#' @param tdee Total daily energy expenditure
#' @param rmr Resting metabolic rate
#'
#' @return OUTPUT_DESCRIPTION
#'
#' @details DETAILS
#'
#' @examples
#' calculate_pal(tdee = 2666, rmr = 1904)
#' @rdname calculate_pal
#' @export
calculate_pal <- function(tdee, rmr) {
  pal <- tdee / rmr
  return(pal)
}
MarijnJABoer/befitteR documentation built on April 24, 2020, 5:43 a.m.