Skip to contents

Standardize/normalize numeric value by baseline summary

Usage

normalize_var_by_baseline_score(x, baseline_summary, varName = NULL)

Arguments

x

Numeric value

baseline_summary

A data.frame of baseline score summary that contains the following variables:

  • MEAN: Mean value

  • SD: Standard deviation value

  • VAR: Contains variable name. Only applicable for non-missing varName value.

The baseline_summary can be generated using compute_baseline_score_summary() function.

varName

Variable name

Value

A numeric vector

See also

Other utility functions: calculate_zscore()

Examples

if (FALSE) { # \dontrun{
# Suppose we wanted to standardize/normalize ADASTT13 scores in
# ADNIMERGE2:ADQS by baseline summary score of Cognitive Normal (CN)
# enrolled subjects.

library(tidyverse)
library(assertr)
library(ADNIMERGE2)

bl.summary <- ADNIMERGE2::ADSL %>%
  compute_baseline_score_summary(
    .data = ADNIMERGE2::ADSL,
    filterBy = "ENRLFL",
    filterValue = "Y",
    wideFormat = TRUE,
    scoreVar = "ADASTT13",
    groupVar = "DX",
    filterGroup = "CN"
  )

# Using numeric vector
example_data1 <- ADNIMERGE2::ADQS %>%
  filter(PARAMCD %in% "ADASTT13")
rsample_adas13 <- example_data1$AVAL
rsample_adas13 <- sample(rsample_adas13, size = 100)
normalize_var_by_baseline_score(
  x = rsample_adas13,
  baseline_summary = bl.summary,
  varName = NULL
)

# Using data.frame format

example_data2 <- ADNIMERGE2::ADQS %>%
  mutate(across(AVAL,
    ~ normalize_var_by_baseline_score(
      x = .x,
      baseline_summary = bl.summary,
      varName = "ADASTT13"
    ),
    .names = "{col}.zscore"
  ))

example_data2 %>%
  group_by(PARAMCD, !is.na(AVAL), !is.na(AVAL.zscore)) %>%
  count() %>%
  ungroup()

library(ggplot2)

example_data2 %>%
  filter(PARAMCD %in% "ADASTT13") %>%
  pivot_longer(
    cols = c("AVAL", "AVAL.zscore"),
    names_to = "SOURCE",
    values_to = "VALUE"
  ) %>%
  ggplot(aes(x = VALUE)) +
  geom_histogram() +
  facet_wrap(~SOURCE)
} # }