|
| 1 | +#' |
| 2 | +#' @title Calculates Blood pressure z-scores |
| 3 | +#' @description The function calculates blood pressure z-scores in two steps: |
| 4 | +#' Step 1. Calculates z-score of height according to CDC growth chart (Not the |
| 5 | +#' WHO growth chart!). Step 2. Calculates z-score of BP according to the fourth |
| 6 | +#' report on BP management, USA |
| 7 | +#' @param sex the name of the sex variable. The variable should be coded as 1 for males |
| 8 | +#' and 2 for females. If it is coded differently (e.g. 0/1), then you can use the |
| 9 | +#' ds.recodeValues function to recode the categories to 1/2 before the use of |
| 10 | +#' ds.bp_standards |
| 11 | +#' @param age the name of the age variable in years. |
| 12 | +#' @param height the name of the height variable in cm |
| 13 | +#' @param bp the name of the blood pressure variable. |
| 14 | +#' @param systolic logical. If TRUE (default) the function assumes conversion of |
| 15 | +#' systolic blood pressure. If FALSE the function assumes conversion of diastolic |
| 16 | +#' blood pressure. |
| 17 | +#' @return assigns a new object on the server-side. The assigned object is a list |
| 18 | +#' with two elements: the 'Zbp' which is the zscores of the blood pressure and 'perc' |
| 19 | +#' which is the percentiles of the BP zscores. |
| 20 | +#' @note The z-scores of height based on CDC growth charts are calculated |
| 21 | +#' by the sds function from the childsds R package. |
| 22 | +#' @author Demetris Avraam for DataSHIELD Development Team |
| 23 | +#' @import childsds |
| 24 | +#' @export |
| 25 | +#' |
| 26 | +bp_standardsDS <- function(sex=sex, age=age, height=height, bp=bp, systolic=systolic){ |
| 27 | + |
| 28 | + if(is.character(sex)){ |
| 29 | + sex <- eval(parse(text = sex), envir = parent.frame()) |
| 30 | + } |
| 31 | + if(is.character(age)){ |
| 32 | + age <- eval(parse(text = age), envir = parent.frame()) |
| 33 | + } |
| 34 | + if(is.character(height)){ |
| 35 | + height <- eval(parse(text = height), envir = parent.frame()) |
| 36 | + } |
| 37 | + if(is.character(bp)){ |
| 38 | + bp <- eval(parse(text = bp), envir = parent.frame()) |
| 39 | + } |
| 40 | + |
| 41 | + # convert height to a Z-score relative to age and sex based on CDC growth charts |
| 42 | + Zht <- sds(value=height, age=age, sex=sex, male="1", female="2", |
| 43 | + ref = childsds::cdc.ref, item = "height2_20", type = "SDS") |
| 44 | + |
| 45 | + # Compute the expected BP (systolic or diastolic) for males/females of age y years and height |
| 46 | + # h inches using the regression coefficients given in table B-1 in |
| 47 | + # https://www.nhlbi.nih.gov/sites/default/files/media/docs/hbp_ped.pdf |
| 48 | + males_idx <- which(sex==1) |
| 49 | + females_idx <- which(sex==2) |
| 50 | + mu <- rep(NA, times=length(sex)) |
| 51 | + if(systolic==TRUE){ |
| 52 | + mu[males_idx] <- 102.19768 + 1.82416 * (age[males_idx]-10) + 0.12776 * (age[males_idx]-10)^2 + |
| 53 | + 0.00249 * (age[males_idx]-10)^3 - 0.00135 * (age[males_idx]-10)^4 + 2.73157 * Zht[males_idx] - |
| 54 | + 0.19618 * Zht[males_idx]^2 - 0.04659 * Zht[males_idx]^3 + 0.00947 * Zht[males_idx]^4 |
| 55 | + mu[females_idx] <- 102.01027 + 1.94397 * (age[females_idx]-10) + 0.00598 * (age[females_idx]-10)^2 - |
| 56 | + 0.00789 * (age[females_idx]-10)^3 - 0.00059 * (age[females_idx]-10)^4 + 2.03526 * Zht[females_idx] + |
| 57 | + 0.02534 * Zht[females_idx]^2 - 0.01884 * Zht[females_idx]^3 + 0.00121 * Zht[females_idx]^4 |
| 58 | + } |
| 59 | + if(systolic==FALSE){ |
| 60 | + mu[males_idx] <- 61.01217 + 0.68314 * (age[males_idx]-10) - 0.09835 * (age[males_idx]-10)^2 + |
| 61 | + 0.01711 * (age[males_idx]-10)^3 + 0.00045 * (age[males_idx]-10)^4 + 1.46993 * Zht[males_idx] - |
| 62 | + 0.07849 * Zht[males_idx]^2 - 0.03144 * Zht[males_idx]^3 + 0.00967 * Zht[males_idx]^4 |
| 63 | + mu[females_idx] <- 60.50510 + 1.01301 * (age[females_idx]-10) + 0.01157 * (age[females_idx]-10)^2 + |
| 64 | + 0.00424 * (age[females_idx]-10)^3 - 0.00137 * (age[females_idx]-10)^4 + 1.16641 * Zht[females_idx] + |
| 65 | + 0.12795 * Zht[females_idx]^2 - 0.03869 * Zht[females_idx]^3 - 0.00079 * Zht[females_idx]^4 |
| 66 | + } |
| 67 | + |
| 68 | + # convert the observed BP to a Z-score (Zbp) using sigmas given in table B-1 |
| 69 | + Zbp <- rep(NA, times=length(mu)) |
| 70 | + if(systolic==TRUE){ |
| 71 | + Zbp[males_idx] <- (bp[males_idx]-mu[males_idx])/10.7128 |
| 72 | + Zbp[females_idx] <- (bp[females_idx]-mu[females_idx])/10.4855 |
| 73 | + } |
| 74 | + if(systolic==FALSE){ |
| 75 | + Zbp[males_idx] <- (bp[males_idx]-mu[males_idx])/11.6032 |
| 76 | + Zbp[females_idx] <- (bp[females_idx]-mu[females_idx])/10.9573 |
| 77 | + } |
| 78 | + |
| 79 | + # convert the bp Z-score to a percentile |
| 80 | + perc <- round(stats::pnorm(Zbp)*100, digits=2) |
| 81 | + |
| 82 | + return(list(Zbp=Zbp, perc=perc)) |
| 83 | + |
| 84 | +} |
0 commit comments