From 180d1b9575f45149ce1c4a2805d21e73a9442f12 Mon Sep 17 00:00:00 2001 From: Duncan Gillespie Date: Fri, 1 Sep 2023 14:21:00 +0100 Subject: [PATCH] add warnings if height in cm not m is detected --- R/AlcBinge.R | 9 ++++++++- R/AlcBinge_stapm.R | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/R/AlcBinge.R b/R/AlcBinge.R index 6697094..98ca5ab 100644 --- a/R/AlcBinge.R +++ b/R/AlcBinge.R @@ -241,10 +241,17 @@ AlcBinge <- function( #data[sex == "Male", rwatson := 0.55] #data[sex == "Female", rwatson := 0.68] + # Note that the numbers in the formulae below come from "The Estimation of Blood Alcohol Concentration - Widmark Revisited" - Posey and Mozayani + # height must be in meters and weight in kg + + if(max(data$height, na.rm = T) > 100) { + warning("AlcBinge: height in cm not m - correct the input data") + } + data[sex == "Male", rwatson := 0.39834 + ((12.725 * height - 0.11275 * age + 2.8993) / weight)] data[sex == "Female", rwatson := 0.29218 + ((12.666 * height - 2.4846) / weight)] - + data[ , age_temp := NULL] return(data) diff --git a/R/AlcBinge_stapm.R b/R/AlcBinge_stapm.R index 558ccf1..f784657 100644 --- a/R/AlcBinge_stapm.R +++ b/R/AlcBinge_stapm.R @@ -130,6 +130,13 @@ AlcBinge_stapm <- function( by = c("age_cat", "sex", "imd_quintile"), all.x = T, all.y = F, sort = F) + # Note that the numbers in the formulae below come from "The Estimation of Blood Alcohol Concentration - Widmark Revisited" - Posey and Mozayani + # height must be in meters and weight in kg + + if(max(data$height, na.rm = T) > 100) { + warning("AlcBinge: height in cm not m - correct the input data") + } + data[sex == "Male", rwatson := 0.39834 + ((12.725 * height - 0.11275 * age + 2.8993) / weight)] data[sex == "Female", rwatson := 0.29218 + ((12.666 * height - 2.4846) / weight)]