# Hy’s Law Implementation

# Introduction

During the drug development process, clinical trials are often required to assess for the potential that the experimental drug can cause severe liver injury, known as a drug induced liver injury (DILI) Drug-Induced Liver Injury: Premarketing Clinical Evaluation. There are multiple criteria that need to be evaluated to determine and classify a DILI “Event”. Hy’s Law, a common rule of thumb for a DILI Event , is usually comprised of three parts:

- Elevated alanine aminotransferase (ALT) or aspartate aminotransferase (AST) by 3-times or greater of the upper limit of normal.
- Elevated serum total bilirubin (BILI) by 2-times or greater within a window of time, ~14 days after the elevated ALT/AST event.
- No other reason to explain these increased lab values like preexisting liver disease.

## Required Packages

The examples of this vignette require the following packages.

    library(admiral)
    library(dplyr, warn.conflicts = FALSE)

# Programming Workflow

- Read in Data
- Flagging Elevated Values (`CRITy`, `CRITyFL`)
- Subsetting by `LBTESTCD` and Joining by Potential Events
- How to Create New Parameters and Rows
- Conclusion

## Read in Data

We assume that an `ADLB` dataset is available 1.

First we read in the `ADLB` parameters required for the Hy’s Law parameters:

    adlb <- admiral::admiral_adlb %>%
      filter(PARAMCD %in% c("AST", "ALT", "BILI") & is.na(DTYPE))

STUDYID

DOMAIN

USUBJID

LBSEQ

LBTESTCD

LBTEST

LBCAT

LBORRES

LBORRESU

LBORNRLO

LBORNRHI

LBSTRESC

LBSTRESN

LBSTRESU

LBSTNRLO

LBSTNRHI

LBNRIND

LBBLFL

VISITNUM

VISIT

VISITDY

LBDTC

LBDY

TRTSDT

TRTEDT

TRT01A

TRT01P

ADT

ADY

PARAMCD

PARAM

PARAMN

PARCAT1

AVAL

AVALC

ANRLO

ANRHI

DTYPE

AVISIT

AVISITN

ONTRTFL

ANRIND

BASETYPE

ABLFL

BASE

BASEC

BNRIND

CHG

PCHG

ATOXDSCL

ATOXDSCH

ATOXGRL

ATOXGRH

ATOXGR

BTOXGRL

BTOXGRH

BTOXGR

R2BASE

R2ANRLO

R2ANRHI

SHIFT1

SHIFT2

ANL01FL

LVOTFL

TRTP

TRTA

ASEQ

SUBJID

RFSTDTC

RFENDTC

RFXSTDTC

RFXENDTC

RFICDTC

RFPENDTC

DTHDTC

DTHFL

SITEID

AGE

AGEU

SEX

RACE

ETHNIC

ARMCD

ARM

ACTARMCD

ACTARM

COUNTRY

DMDTC

DMDY

TRTSDTM

TRTSTMF

TRTEDTM

TRTETMF

TRTDURD

SCRFDT

EOSDT

EOSSTT

FRVDT

RANDDT

DTHDT

DTHDTF

DTHADY

LDDTHELD

DTHCAUS

DTHDOM

DTHCGR1

LSTALVDT

SAFFL

RACEGR1

AGEGR1

REGION1

LDDTHGR1

DTH30FL

DTHA30FL

DTHB30FL

CDISCPILOT01

LB

01-701-1015

3

ALT

Alanine Aminotransferase

CHEMISTRY

27

U/L

6

34

27

27

U/L

6

34

NORMAL

Y

1

SCREENING 1

-7

2013-12-26T14:45

-7

2014-01-02

2014-07-02

Placebo

Placebo

2013-12-26

-7

ALT

Alanine Aminotransferase (U/L)

3

CHEMISTRY

27

NA

6

34

NA

Baseline

0

NA

NORMAL

LAST

Y

27

NA

NORMAL

NA

NA

NA

Alanine aminotransferase increased

NA

0

0

NA

0

0

1.0000000

4.500000

0.7941176

NORMAL to NORMAL

0 to 0

NA

NA

Placebo

Placebo

27

1015

2014-01-02

2014-07-02

2014-01-02

2014-07-02

NA

2014-07-02T11:45

NA

NA

701

63

YEARS

F

WHITE

HISPANIC OR LATINO

Pbo

Placebo

Pbo

Placebo

USA

2013-12-26

-7

2014-01-02

H

2014-07-02 23:59:59

H

182

NA

2014-07-02

COMPLETED

NA

2014-01-02

NA

NA

NA

NA

NA

NA

NA

2014-07-02

Y

White

18-64

NA

NA

NA

NA

NA

CDISCPILOT01

LB

01-701-1015

41

ALT

Alanine Aminotransferase

CHEMISTRY

41

U/L

6

34

41

41

U/L

6

34

HIGH

NA

4

WEEK 2

14

2014-01-16T13:17

15

2014-01-02

2014-07-02

Placebo

Placebo

2014-01-16

15

ALT

Alanine Aminotransferase (U/L)

3

CHEMISTRY

41

NA

6

34

NA

Week 2

4

Y

HIGH

LAST

NA

27

NA

NORMAL

14

51.851852

NA

Alanine aminotransferase increased

NA

1

1

NA

0

0

1.5185185

6.833333

1.2058824

NORMAL to HIGH

0 to 1

Y

NA

Placebo

Placebo

28

1015

2014-01-02

2014-07-02

2014-01-02

2014-07-02

NA

2014-07-02T11:45

NA

NA

701

63

YEARS

F

WHITE

HISPANIC OR LATINO

Pbo

Placebo

Pbo

Placebo

USA

2013-12-26

-7

2014-01-02

H

2014-07-02 23:59:59

H

182

NA

2014-07-02

COMPLETED

NA

2014-01-02

NA

NA

NA

NA

NA

NA

NA

2014-07-02

Y

White

18-64

NA

NA

NA

NA

NA

CDISCPILOT01

LB

01-701-1015

76

ALT

Alanine Aminotransferase

CHEMISTRY

18

U/L

6

34

18

18

U/L

6

34

NORMAL

NA

5

WEEK 4

28

2014-01-30T08:50

29

2014-01-02

2014-07-02

Placebo

Placebo

2014-01-30

29

ALT

Alanine Aminotransferase (U/L)

3

CHEMISTRY

18

NA

6

34

NA

Week 4

5

Y

NORMAL

LAST

NA

27

NA

NORMAL

-9

-33.333333

NA

Alanine aminotransferase increased

NA

0

0

NA

0

0

0.6666667

3.000000

0.5294118

NORMAL to NORMAL

0 to 0

Y

NA

Placebo

Placebo

30

1015

2014-01-02

2014-07-02

2014-01-02

2014-07-02

NA

2014-07-02T11:45

NA

NA

701

63

YEARS

F

WHITE

HISPANIC OR LATINO

Pbo

Placebo

Pbo

Placebo

USA

2013-12-26

-7

2014-01-02

H

2014-07-02 23:59:59

H

182

NA

2014-07-02

COMPLETED

NA

2014-01-02

NA

NA

NA

NA

NA

NA

NA

2014-07-02

Y

White

18-64

NA

NA

NA

NA

NA

CDISCPILOT01

LB

01-701-1015

106

ALT

Alanine Aminotransferase

CHEMISTRY

26

U/L

6

34

26

26

U/L

6

34

NORMAL

NA

7

WEEK 6

42

2014-02-12T12:56

42

2014-01-02

2014-07-02

Placebo

Placebo

2014-02-12

42

ALT

Alanine Aminotransferase (U/L)

3

CHEMISTRY

26

NA

6

34

NA

Week 6

7

Y

NORMAL

LAST

NA

27

NA

NORMAL

-1

-3.703704

NA

Alanine aminotransferase increased

NA

0

0

NA

0

0

0.9629630

4.333333

0.7647059

NORMAL to NORMAL

0 to 0

Y

NA

Placebo

Placebo

31

1015

2014-01-02

2014-07-02

2014-01-02

2014-07-02

NA

2014-07-02T11:45

NA

NA

701

63

YEARS

F

WHITE

HISPANIC OR LATINO

Pbo

Placebo

Pbo

Placebo

USA

2013-12-26

-7

2014-01-02

H

2014-07-02 23:59:59

H

182

NA

2014-07-02

COMPLETED

NA

2014-01-02

NA

NA

NA

NA

NA

NA

NA

2014-07-02

Y

White

18-64

NA

NA

NA

NA

NA

CDISCPILOT01

LB

01-701-1015

136

ALT

Alanine Aminotransferase

CHEMISTRY

22

U/L

6

34

22

22

U/L

6

34

NORMAL

NA

8

WEEK 8

56

2014-03-05T12:25

63

2014-01-02

2014-07-02

Placebo

Placebo

2014-03-05

63

ALT

Alanine Aminotransferase (U/L)

3

CHEMISTRY

22

NA

6

34

NA

Week 8

8

Y

NORMAL

LAST

NA

27

NA

NORMAL

-5

-18.518518

NA

Alanine aminotransferase increased

NA

0

0

NA

0

0

0.8148148

3.666667

0.6470588

NORMAL to NORMAL

0 to 0

Y

NA

Placebo

Placebo

32

1015

2014-01-02

2014-07-02

2014-01-02

2014-07-02

NA

2014-07-02T11:45

NA

NA

701

63

YEARS

F

WHITE

HISPANIC OR LATINO

Pbo

Placebo

Pbo

Placebo

USA

2013-12-26

-7

2014-01-02

H

2014-07-02 23:59:59

H

182

NA

2014-07-02

COMPLETED

NA

2014-01-02

NA

NA

NA

NA

NA

NA

NA

2014-07-02

Y

White

18-64

NA

NA

NA

NA

NA

CDISCPILOT01

LB

01-701-1015

166

ALT

Alanine Aminotransferase

CHEMISTRY

27

U/L

6

34

27

27

U/L

6

34

NORMAL

NA

9

WEEK 12

84

2014-03-26T15:15

84

2014-01-02

2014-07-02

Placebo

Placebo

2014-03-26

84

ALT

Alanine Aminotransferase (U/L)

3

CHEMISTRY

27

NA

6

34

NA

Week 12

9

Y

NORMAL

LAST

NA

27

NA

NORMAL

0

0.000000

NA

Alanine aminotransferase increased

NA

0

0

NA

0

0

1.0000000

4.500000

0.7941176

NORMAL to NORMAL

0 to 0

Y

NA

Placebo

Placebo

33

1015

2014-01-02

2014-07-02

2014-01-02

2014-07-02

NA

2014-07-02T11:45

NA

NA

701

63

YEARS

F

WHITE

HISPANIC OR LATINO

Pbo

Placebo

Pbo

Placebo

USA

2013-12-26

-7

2014-01-02

H

2014-07-02 23:59:59

H

182

NA

2014-07-02

COMPLETED

NA

2014-01-02

NA

NA

NA

NA

NA

NA

NA

2014-07-02

Y

White

18-64

NA

NA

NA

NA

NA

## Flagging Elevated Values (`CRITy`, `CRITyFL`)

A standard convention of `ADLBHY` datasets, are various `CRITy` and `CRITyFL` columns to describe the conditions necessary to reach that particular criterion of Hy’s Law and the actual flag itself to indicate whether or not the condition was reached.

Using `mutate()`, `call_derivation()` and `derive_var_merged_exist_flag()`, we can create these columns that indicate the the 3-fold or greater than upper limit of normal of ALT/AST and the 2-fold or greater than upper limit of normal of BILI.

To increase visibility and for simplicity, we will retain only columns that are relevant to a Hy’s Law analysis for now.

    adlb_annotated <- adlb %>%
      slice_derivation(
        derive_vars_crit_flag,
        args = params(
          values_yn = TRUE
        ),
        derivation_slice(
          filter = PARAMCD %in% c("AST", "ALT"),
          args = params(
            condition = AVAL / ANRHI >= 3,
            description = paste(PARAMCD, ">=3xULN")
          )
        ),
        derivation_slice(
          filter = PARAMCD == "BILI",
          args = params(
            condition = AVAL / ANRHI >= 2,
            description = "BILI >= 2xULN"
          )
        )
      ) %>%
      select(STUDYID, USUBJID, TRT01A, PARAMCD, LBSEQ, ADT, AVISIT, ADY, AVAL, ANRHI, CRIT1, CRIT1FL)

USUBJID | PARAMCD | AVISIT | AVAL | ANRHI | CRIT1 | CRIT1FL
--- | --- | --- | --- | --- | --- | ---
01-701-1015 | ALT | Baseline | 27 | 34 | ALT >=3xULN | N
01-701-1015 | ALT | Week 2 | 41 | 34 | ALT >=3xULN | N
01-701-1015 | ALT | Week 4 | 18 | 34 | ALT >=3xULN | N
01-701-1015 | ALT | Week 6 | 26 | 34 | ALT >=3xULN | N
01-701-1015 | ALT | Week 8 | 22 | 34 | ALT >=3xULN | N
01-701-1015 | ALT | Week 12 | 27 | 34 | ALT >=3xULN | N
01-701-1015 | ALT | Week 16 | 17 | 34 | ALT >=3xULN | N
01-701-1015 | ALT | Week 20 | 21 | 34 | ALT >=3xULN | N
01-701-1015 | ALT | Week 24 | 23 | 34 | ALT >=3xULN | N
01-701-1015 | ALT | Week 26 | 23 | 34 | ALT >=3xULN | N

## Subsetting by `LBTESTCD` and Joining by Potential Events

If an elevated ALT/AST event reaches the threshold for Hy’s Law, we need to search for any elevated BILI events within a certain time-window, usually up to 14 days after the elevated ALT/AST event (this window may vary by organization). By,

1. Splitting our dataset into its ALT/AST and BILI subsets, respectively, and
2. Joining these two datasets using `derive_vars_joined()` while using the `filter_join` argument to only join together the relevant flagged BILI records that have a corresponding flagged ALT/AST record (prior up to 14 days but may vary for trial/organization) that would indicate a potential Hy’s Law event,

the resulting dataset is helpful for deriving additional parameters. The dataset may also prove useful for a listing where you have to display the two lab-records in one row to showcase the potential event.

    altast_records <- adlb_annotated %>%
      filter(PARAMCD %in% c("AST", "ALT"))

    bili_records <- adlb_annotated %>%
      filter(PARAMCD %in% c("BILI"))

    hylaw_records <- derive_vars_joined(
      dataset = altast_records,
      dataset_add = bili_records,
      by_vars = exprs(STUDYID, USUBJID),
      order = exprs(ADY),
      join_type = "all",
      filter_join = 0 <= ADT.join - ADT & ADT.join - ADT <= 14 & CRIT1FL == "Y" & CRIT1FL.join == "Y",
      new_vars = exprs(BILI_DT = ADT, BILI_CRITFL = CRIT1FL),
      mode = "first"
    )

USUBJID | PARAMCD | AVISIT | ADT | CRIT1FL | BILI_DT | BILI_CRITFL
--- | --- | --- | --- | --- | --- | ---
01-705-1186 | ALT | Week 2 | 2014-01-23 | Y | 2014-01-23 | Y
01-705-1186 | ALT | Week 4 | 2014-01-29 | Y | 2014-01-29 | Y
01-705-1186 | AST | Week 2 | 2014-01-23 | Y | 2014-01-23 | Y
01-705-1186 | AST | Unscheduled 4.1 | 2014-01-26 | Y | 2014-01-26 | Y
01-705-1186 | AST | Week 4 | 2014-01-29 | Y | 2014-01-29 | Y
01-705-1186 | AST | Unscheduled 4.2 | 2014-02-01 | Y | 2014-02-01 | Y
01-705-1292 | AST | Week 12 | 2014-02-07 | Y | NA | NA
01-705-1310 | ALT | Week 8 | 2013-12-26 | Y | NA | NA
01-705-1310 | AST | Week 8 | 2013-12-26 | Y | NA | NA
01-708-1286 | ALT | Week 24 | 2014-02-23 | Y | NA | NA

## How to Create New Parameters and Rows

Using `derive_param_exist_flag()` you can create a variety of parameters for your final dataset with `AVAL = 1/0` for your specific Hy’s Law analysis. Below is an example of how to indicate a potential Hy’s Law event, with `PARAMCD` set as `"HYSLAW"` and `PARAM` set to `"ALT/AST >= 3xULN and BILI >= 2xULN"` for each patient using the flags from the prior dataset. This method allows for flexibility as well, if parameters for each visit was desired, you would add `AVISIT` and `ADT` to the `select()` and `by_vars` lines as denoted from the following code.

Additional modifications can be made such as:

- Parameter to indicate worsening of condition
- Any sort of baseline/post-baseline based analysis
- Flags for other lab values like ALP if modified in above too

    hylaw_records_pts_visits <- hylaw_records %>%
      select(STUDYID, USUBJID, TRT01A) %>% # add AVISIT, ADT for by visit
      distinct()

    hylaw_records_fls <- hylaw_records %>%
      select(STUDYID, USUBJID, TRT01A, CRIT1FL, BILI_CRITFL) %>% # add AVISIT, ADT for by visit
      distinct()

    hylaw_params <- derive_param_exist_flag(
      dataset_ref = hylaw_records_pts_visits,
      dataset_add = hylaw_records_fls,
      condition = CRIT1FL == "Y" & BILI_CRITFL == "Y",
      false_value = "N",
      missing_value = "N",
      by_vars = exprs(STUDYID, USUBJID, TRT01A), # add AVISIT, ADT for by visit
      set_values_to = exprs(
        PARAMCD = "HYSLAW",
        PARAM = "ALT/AST >= 3xULN and BILI >= 2xULN",
        AVAL = yn_to_numeric(AVALC)
      )
    )

USUBJID | PARAMCD | PARAM | AVALC | AVAL
--- | --- | --- | --- | ---
01-705-1186 | HYSLAW | ALT/AST >= 3xULN and BILI >= 2xULN | Y | 1
01-701-1015 | HYSLAW | ALT/AST >= 3xULN and BILI >= 2xULN | N | 0
01-701-1023 | HYSLAW | ALT/AST >= 3xULN and BILI >= 2xULN | N | 0
01-701-1028 | HYSLAW | ALT/AST >= 3xULN and BILI >= 2xULN | N | 0
01-701-1033 | HYSLAW | ALT/AST >= 3xULN and BILI >= 2xULN | N | 0
01-701-1034 | HYSLAW | ALT/AST >= 3xULN and BILI >= 2xULN | N | 0
01-701-1047 | HYSLAW | ALT/AST >= 3xULN and BILI >= 2xULN | N | 0
01-701-1097 | HYSLAW | ALT/AST >= 3xULN and BILI >= 2xULN | N | 0
01-705-1292 | HYSLAW | ALT/AST >= 3xULN and BILI >= 2xULN | N | 0
01-705-1310 | HYSLAW | ALT/AST >= 3xULN and BILI >= 2xULN | N | 0

The last step would be binding these rows back to whatever previous dataset is appropriate based on your data specifications, in this case, it would be best suited to bind back to our `adlb_annotated` object.

## Conclusion

    adlbhy <- adlb_annotated %>%
      bind_rows(hylaw_params)

USUBJID | PARAMCD | AVISIT | AVALC | AVAL | CRIT1 | CRIT1FL
--- | --- | --- | --- | --- | --- | ---
01-701-1015 | ALT | Baseline | NA | 27 | ALT >=3xULN | N
01-701-1015 | ALT | Week 2 | NA | 41 | ALT >=3xULN | N
01-701-1015 | ALT | Week 4 | NA | 18 | ALT >=3xULN | N
01-701-1015 | ALT | Week 6 | NA | 26 | ALT >=3xULN | N
01-701-1015 | ALT | Week 8 | NA | 22 | ALT >=3xULN | N
01-701-1015 | ALT | Week 12 | NA | 27 | ALT >=3xULN | N
01-701-1015 | ALT | Week 16 | NA | 17 | ALT >=3xULN | N
01-701-1015 | ALT | Week 20 | NA | 21 | ALT >=3xULN | N
01-701-1015 | ALT | Week 24 | NA | 23 | ALT >=3xULN | N
01-701-1015 | ALT | Week 26 | NA | 23 | ALT >=3xULN | N

Here we demonstrated what is the base-case that may be asked of as a trial programmer. The reality is that Hy’s Law and assessing potential DILI events can get rather complex quite quickly. Differences in assessment across organizations and specific trials might require modifications, which may include:

- additional `CRITy` and `CRITyFL` columns for different cutoffs like 5xULN, 10xULN, 20xULN
- checking for elevated values of additional labs like alkaline phosphatase (ALP)
- appearance of certain adverse events associated with some of these elevated lab-values
- different criteria cutoffs that depend on baseline values or characteristics
- other parameters such as worsening of condition

We hope by demonstrating the flexibility of `admiral` functions and using a general workflow to create the necessary parameters for an `ADLBHY`, that creating this final dataset becomes simplified and easily scalable. Ideally, this is ready for your organization’s standard macros or previous code for TLFs and outputs as well. This is our first attempt at breaking down and summarizing this topic. We welcome feedback and ideas to improve this guide!

# Example Script

ADaM | Sourcing Command
--- | ---
`ADLBHY` | `use_ad_template("ADLBHY")`

1. In the walk through below we will use the `ADLB` dataset created from the call `use_ad_template("adlb")`. Due to the size of the dataset, we only included the following `USUBJID`s:

   - `01-701-1015`, `01-701-1023`, `01-701-1028`, `01-701-1033`, `01-701-1034`, `01-701-1047`, `01-701-1097`, `01-705-1186`, `01-705-1292`, `01-705-1310`, `01-708-1286`.
   ↩︎