#' Visceral Adiposity Index(VAI)
#'
#' @param data data
#' @param years years
#' @details
#' the equations of Visceral Adiposity Index
#' - male: VAI = (WC/39.68 + (1.88*BMI)) * (TG/1.03) * (1.31/HDL)
#' - female: VAI = (WC/36.58 + (1.89*BMI)) * (TG/0.81) * (1.52/HDL)
#'
#' - WC, waist circumference(cm)
#' - BMI, body mass index
#' - TG, triglycerides(mmol/l)
#' - HDL, high density lipoprotein(mmol/l)
#' @export
attach_VAI <- function(data,years){
if (!missing(data)){
years <- unique(data$Year)
seqn <- unique(data$seqn)
}
years <- prepare_years(years)
(demo <- nhs_tsv('demo',years=years,cat=FALSE))
(bmx <- nhs_tsv('bmx',years=years,cat=FALSE))
(biopro <- nhs_tsv('lab18\\.|l40_b|l40_c|biopro',years=years,cat=FALSE))
(hdl <- nhs_tsv('lab13\\.|l13_b|l13_c|hdl',years=years,cat=FALSE))
nr <- nhs_read(demo,"riagendr:sex",
bmx,'bmxwaist:waist','bmxbmi:bmi',
biopro,'lbdstrsi:TG',
hdl,'lbdhdlsi,lbdhddsi:HDL',
lower_cd = TRUE,cat=FALSE)
if (!missing(data)) nr <- nr[nr$seqn %in% seqn,]
ck <- nr$sex == 'male' & !is.na(nr$sex)
nr$VAI[ck] <- (nr$waist[ck]/(39.68 + (1.88*nr$bmi[ck]))) * (nr$TG[ck]/1.03) * (1.31/nr$HDL[ck])
ck <- nr$sex == 'female' & !is.na(nr$sex)
nr$VAI[ck] <- (nr$waist[ck]/(36.58 + (1.89*nr$bmi[ck]))) * (nr$TG[ck]/0.81) * (1.52/nr$HDL[ck])
data0 <- nr[,c('seqn','Year','VAI')]
if (missing(data)){
data <- data0
}else{
data0 <- data0[,!colnames(data0) %in% 'Year']
data <- as.data.frame(dplyr::left_join(data,data0,'seqn'))
}
return(data)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.