# Creating a Control of Eating Questionnaire ADaM

# License

Note that University of Leeds are the copyright holders of the Control of Eating Questionnaire (CoEQ) and the test data included within `{admiralmetabolic}` as well as the ADCOEQ code are for not-for-profit use only within `{admiralmetabolic}` and pharmaverse-related examples/documentation. Any persons or companies wanting to use the CoEQ should request a license to do so from the following link.

# Introduction

This article describes creating a Control of Eating Questionnaire ADaM for clinical trials.

We advise you first consult the `{admiral}` Creating Questionnaire ADaMs vignette. The programming workflow around creating the general set-up of an `ADQS` using `{admiral}` functions is the same. In this vignette, we focus on the Control of Eating Questionnaire and avoid repeating information and maintaining the same content in two places. As such, the code in this vignette is not completely executable; we recommend consulting the ADQS template script to view the full workflow.

Note: All examples assume CDISC SDTM and/or ADaM format as input unless otherwise specified.

## Required Packages

The examples of this vignette require the following packages.

    library(admiral)
    library(admiralmetabolic)
    library(pharmaversesdtm)
    library(dplyr)
    library(stringr)

# Programming Workflow

- Read in Data
- Original items
- Derive the four Subscales
- Remaining ADCOEQ Set-up

## Read in Data

To start, all data frames needed for the creation of the ADaM dataset should be loaded into the global environment. Reading data will usually be a company specific process, however, for the purpose of this vignette, we will use example data from `{pharmaversesdtm}` and `{admiral}`. We will utilize `DM`, `QS` and `ADSL`.

In this vignette we use example data for the CoEQ. The example `QS` data (`qs_metabolic`) is included in the `{admiralmetabolic}` package.

    dm_metabolic <- admiralmetabolic::dm_metabolic
    qs_metabolic <- admiralmetabolic::qs_metabolic
    admiral_adsl <- admiral::admiral_adsl

    dm <- convert_blanks_to_na(dm_metabolic)
    qs <- convert_blanks_to_na(qs_metabolic)
    admiral_adsl <- convert_blanks_to_na(admiral_adsl)

Within this vignette, `DM` is used as the basis for `ADSL`:

    # Retrieve required variables from admiral ADSL for this vignette that are not present in DM dataset
    adsl <- dm %>%
      select(-DOMAIN) %>%
      mutate(TRT01P = ARM, TRT01A = ACTARM) %>%
      derive_vars_merged(
        dataset_add = admiral_adsl,
        by_vars = exprs(USUBJID),
        new_vars = exprs(TRTSDT, TRTEDT)
      )

## Original Items

The original items, i.e. the answers to the questionnaire questions, can be handled in the same way as in an {admiral} BDS finding ADaM.

    adcoeq1 <- qs %>%
      # Add ADSL variables
      derive_vars_merged(
        dataset_add = adsl,
        by_vars = exprs(STUDYID, USUBJID),
        new_vars = exprs(TRTSDT, TRTEDT, TRT01P, TRT01A)
      ) %>%
      # Add analysis parameter variables
      mutate(
        PARAMCD = QSTESTCD,
        PARAM = QSTEST,
        PARCAT1 = QSCAT
      ) %>%
      # Add timing variables
      derive_vars_dt(new_vars_prefix = "A", dtc = QSDTC) %>%
      derive_vars_dy(reference_date = TRTSDT, source_vars = exprs(ADT)) %>%
      mutate(
        AVISIT = case_when(
          is.na(VISIT) ~ NA_character_,
          str_detect(VISIT, "UNSCHED|RETRIEVAL|AMBUL") ~ NA_character_,
          TRUE ~ str_to_title(VISIT)
        ),
        AVISITN = case_when(
          AVISIT == "Baseline" ~ 0,
          str_detect(AVISIT, "Screen") ~ -1,
          str_detect(VISIT, "WEEK") ~ as.integer(str_extract(VISIT, "\\d+")),
          TRUE ~ NA_integer_
        )
      )

USUBJID | PARAMCD | PARAM | PARCAT1 | QSSTRESN | ADY | AVISIT
--- | --- | --- | --- | --- | --- | ---
01-701-1015 | COEQ01 | How hungry have you felt? | COEQ | 17 | -7 | Screening 1
01-701-1015 | COEQ02 | How full have you felt? | COEQ | 81 | -7 | Screening 1
01-701-1015 | COEQ03 | How strong was your desire to eat sweet foods? | COEQ | 38 | -7 | Screening 1
01-701-1015 | COEQ04 | How strong was your desire to eat savoury foods? | COEQ | 33 | -7 | Screening 1
01-701-1015 | COEQ05 | How happy have you felt? | COEQ | 60 | -7 | Screening 1
01-701-1015 | COEQ06 | How anxious have you felt? | COEQ | 60 | -7 | Screening 1
01-701-1015 | COEQ07 | How alert have you felt? | COEQ | 12 | -7 | Screening 1
01-701-1015 | COEQ08 | How contented have you felt? | COEQ | 29 | -7 | Screening 1
01-701-1015 | COEQ09 | During the last 7 days how often have you had food cravings? | COEQ | 58 | -7 | Screening 1
01-701-1015 | COEQ10 | How strong have any food cravings been? | COEQ | 63 | -7 | Screening 1

The analysis values (`AVAL` and `AVALC`) for most original items are set directly from `QSSTRESN` and `QSORRES`, respectively. However, CoEQ item 6 (`COEQ06`) requires a manual transformation, where we invert the original scores. This transformation is performed because CoEQ item 6 is used in calculating the subscale for “Positive Mood,” where its original scores indicate anxiety.

In cases where `QSSTRESN` values require transformation, it is recommended to keep the original `QSSTRESN` values in the ADaM dataset for traceability.

    adcoeq2 <- adcoeq1 %>%
      # Add analysis value variables
      mutate(
        AVAL = if_else(PARAMCD == "COEQ06", 100 - QSSTRESN, QSSTRESN),
        AVALC = if_else(PARAMCD == "COEQ20", QSORRES, NA_character_)
      )

USUBJID | PARAMCD | PARAM | PARCAT1 | QSSTRESN | ADY | AVISIT | AVALC | AVAL
--- | --- | --- | --- | --- | --- | --- | --- | ---
01-701-1015 | COEQ01 | How hungry have you felt? | COEQ | 17 | -7 | Screening 1 | NA | 17
01-701-1015 | COEQ02 | How full have you felt? | COEQ | 81 | -7 | Screening 1 | NA | 81
01-701-1015 | COEQ03 | How strong was your desire to eat sweet foods? | COEQ | 38 | -7 | Screening 1 | NA | 38
01-701-1015 | COEQ04 | How strong was your desire to eat savoury foods? | COEQ | 33 | -7 | Screening 1 | NA | 33
01-701-1015 | COEQ05 | How happy have you felt? | COEQ | 60 | -7 | Screening 1 | NA | 60
01-701-1015 | COEQ06 | How anxious have you felt? | COEQ | 60 | -7 | Screening 1 | NA | 40
01-701-1015 | COEQ07 | How alert have you felt? | COEQ | 12 | -7 | Screening 1 | NA | 12
01-701-1015 | COEQ08 | How contented have you felt? | COEQ | 29 | -7 | Screening 1 | NA | 29
01-701-1015 | COEQ09 | During the last 7 days how often have you had food cravings? | COEQ | 58 | -7 | Screening 1 | NA | 58
01-701-1015 | COEQ20 | Which one food makes it most difficult for you to control eating? | COEQ | NA | -7 | Screening 1 | Ice Cream | NA

For deriving visits based on time-windows, see `{admiral}` Visit and Period Variables.

## Derive the four Subscales

For the Control of Eating Questionnaire, four subscales are derived. These subscales are derived as the mean across a subset of the various items/questions.

The subscales are defined as follows:

- Craving Control: Calculate mean of items 9, 10, 11, 12 and 19.

- Craving for Sweet: Calculate mean of items 3, 13, 14 and 15.

- Craving for Savoury: Calculate mean of items 4, 16, 17 and 18.

- Positive Mood: Calculate mean of items 5, 7, 8 and 6 (reversed).

These parameters can be derived by `derive_summary_records()`:

    adcoeq3 <- adcoeq2 %>%
      call_derivation(
        derivation = derive_summary_records,
        variable_params = list(
          params(
            filter_add = PARAMCD %in% c("COEQ09", "COEQ10", "COEQ11", "COEQ12", "COEQ19"),
            set_values_to = exprs(
              AVAL = mean(AVAL, na.rm = TRUE),
              PARAMCD = "COEQCRCO",
              PARAM = "COEQ - Craving Control"
            )
          ),
          params(
            filter_add = PARAMCD %in% c("COEQ03", "COEQ13", "COEQ14", "COEQ15"),
            set_values_to = exprs(
              AVAL = mean(AVAL, na.rm = TRUE),
              PARAMCD = "COEQCRSW",
              PARAM = "COEQ - Craving for Sweet"
            )
          ),
          params(
            filter_add = PARAMCD %in% c("COEQ04", "COEQ16", "COEQ17", "COEQ18"),
            set_values_to = exprs(
              AVAL = mean(AVAL, na.rm = TRUE),
              PARAMCD = "COEQCRSA",
              PARAM = "COEQ - Craving for Savoury"
            )
          ),
          params(
            filter_add = PARAMCD %in% c("COEQ05", "COEQ07", "COEQ08", "COEQ06"),
            set_values_to = exprs(
              AVAL = mean(AVAL, na.rm = TRUE),
              PARAMCD = "COEQPOMO",
              PARAM = "COEQ - Positive Mood"
            )
          )
        ),
        dataset_add = adcoeq2,
        by_vars = exprs(STUDYID, USUBJID, AVISIT, AVISITN, ADT, ADY, PARCAT1, TRTSDT, TRTEDT, TRT01P, TRT01A)
      )

USUBJID | PARAMCD | PARAM | AVAL | ADY | AVISIT
--- | --- | --- | --- | --- | ---
01-701-1015 | COEQCRCO | COEQ - Craving Control | 62.60 | -7 | Screening 1
01-701-1015 | COEQCRSA | COEQ - Craving for Savoury | 49.25 | -7 | Screening 1
01-701-1015 | COEQCRSW | COEQ - Craving for Sweet | 58.50 | -7 | Screening 1
01-701-1015 | COEQPOMO | COEQ - Positive Mood | 35.25 | -7 | Screening 1
01-701-1015 | COEQCRCO | COEQ - Craving Control | 54.80 | -2 | Screening 2
01-701-1015 | COEQCRSA | COEQ - Craving for Savoury | 65.75 | -2 | Screening 2
01-701-1015 | COEQCRSW | COEQ - Craving for Sweet | 43.50 | -2 | Screening 2
01-701-1015 | COEQPOMO | COEQ - Positive Mood | 53.00 | -2 | Screening 2
01-701-1015 | COEQCRCO | COEQ - Craving Control | 37.80 | 1 | Baseline
01-701-1015 | COEQCRSA | COEQ - Craving for Savoury | 47.75 | 1 | Baseline

## Remaining ADCOEQ Set-up

The `{admiral}` Creating Questionnaire ADaMs vignette describes further steps, including, how to calculate the change from baseline variables, and how to add parameters for questionnaire completion.

# Example Scripts

ADaM | Sample Code
--- | ---
ADCOEQ | ad_adcoeq.R