Singh_2025_donidalorsen <- function() {
  description <- "Longitudinal exposure-response model relating per-4-week normalized hereditary angioedema (HAE) attack rate to 4-week-averaged plasma prekallikrein (PKK) concentration in adult and adolescent HAE patients receiving subcutaneous donidalorsen (Singh 2025). Sigmoidal Emax response driven by PKK with per-subject covariate effects of baseline HAE attack rate on Emax (power form) and baseline PKK on EC50 (power form). IIV on Emax (log-normal, CV 27.9%) and Hill (log-normal, CV 131%); no IIV on EC50 in the final model (the paper reports the EC50-IIV variant was numerically unstable during stepwise covariate evaluation). Per-4-week attack count is drawn from a Poisson likelihood with mean equal to the sigmoidal attack rate; the paper's generalized-Poisson dispersion parameter is not reported so extraction uses the standard Poisson approximation (documented in vignette Errata). Age, body weight, sex, and treatment-emergent ADA status were screened but not retained in the final model. Upstream PKK trajectories are generated by the paired Diep 2026 popPK/PD model (modellib('Diep_2026_donidalorsen')); this exposure-response model consumes the 4-week-averaged PKK as a time-varying covariate."
  reference   <- "Singh P, Witjes H, Kleijn HJ, Diep JK, Bordone L, Newman KB, Gao X, Cohn DM. Exposure-Response Analysis of Donidalorsen for the Treatment of Hereditary Angioedema. Clin Transl Sci. 2025;18(11):e70388. doi:10.1111/cts.70388"
  vignette    <- "Singh_2025_donidalorsen"
  units       <- list(time = "week", dosing = "(none; upstream PK model supplies PKK)", concentration = "mg/L (plasma prekallikrein)")

  covariateData <- list(
    PKK = list(
      description        = "Per-4-week average plasma prekallikrein concentration (PKKavg,4W) used as the exposure driver of the sigmoidal Emax attack-rate model",
      units              = "mg/L",
      type               = "continuous",
      reference_category = NULL,
      notes              = "Time-varying regressor. For donidalorsen-treated patients the paper computed PKKavg,4W as the individual model-predicted PKK averaged across each 4-week interval from an upstream popPK/PD (Diep 2026; this registry: modellib('Diep_2026_donidalorsen')). For placebo patients the paper used the observed PKK. The model reads PKK at each observation row via LOCF (piecewise-constant covariate semantics matching the paper's per-4-week averaging).",
      source_name        = "PKKavg,4W"
    ),
    PKK_BL = list(
      description        = "Per-subject baseline plasma prekallikrein concentration",
      units              = "mg/L",
      type               = "continuous",
      reference_category = NULL,
      notes              = "Time-fixed per subject. Enters EC50 via the power form printed on page 3 of Singh 2025: the equation denominator carries (BLPKK/122)^bPKK multiplied against EC50^Hill. The 122 mg/L reference is the paper's normalization anchor (matches the Section 2.3 simulation baseline PKK of 122 mg/L; the 132 mg/L value in the Figure 1 caption is the donidalorsen-treated-cohort mean, not the equation's normalization anchor). For donidalorsen-treated patients the baseline is the initial condition of the upstream Diep 2026 PD compartment; for placebo patients the paper used the observed baseline PKK. Cohort mean (SD) baseline PKK in OASIS-HAE (Table S1): 126 (31.8) Q4W, 144 (41.1) Q8W, 118 (27.0) placebo, 128 (34.2) overall.",
      source_name        = "BLPKK"
    ),
    HAERATE_BL = list(
      description        = "Per-subject baseline per-4-week normalized HAE attack rate during the 56-day screening period",
      units              = "attacks per 4 weeks",
      type               = "continuous",
      reference_category = NULL,
      notes              = "Time-fixed per subject. Per the OASIS-HAE protocol quoted on page 3 of Singh 2025: 'BLRATE was calculated as the number of investigator-confirmed HAE attacks during the 56-day run-in period divided by the number of days contributed to the run-in period multiplied by 28 days.' Enters Emax via the power form Emax * (BLRATE/3)^bHAE (equation page 3). The 3 attacks-per-4-week reference is the paper's normalization anchor (matches the Section 2.3 simulation baseline attack rate of 3.0; the 3.47 value in the Figure 1 caption is the donidalorsen-treated-cohort mean, not the equation's normalization anchor). Cohort mean (SD) baseline attack rate in OASIS-HAE (Table S1): 3.62 (2.18) Q4W, 3.17 (2.14) Q8W, 2.90 (1.66) placebo, 3.32 (2.04) overall.",
      source_name        = "BLRATE"
    )
  )

  covariatesDataExcluded <- list(
    WT = list(
      description = "Total body weight",
      units       = "kg",
      type        = "continuous",
      notes       = "Screened during forward inclusion / backward elimination (p<0.01 / p<0.001 thresholds; Singh 2025 Section 2.2) but not retained in the final ER model. Cohort mean (SD) 81.7 (21.9) kg (Table S1)."
    ),
    AGE = list(
      description = "Subject age",
      units       = "years",
      type        = "continuous",
      notes       = "Screened but not retained. Cohort mean (SD) 37 (14) years (Table S1)."
    ),
    SEXF = list(
      description = "Sex (1 = female, 0 = male)",
      units       = "(binary)",
      type        = "binary",
      notes       = "Screened but not retained. 52.4% female overall (Table S1)."
    ),
    ADA_POS = list(
      description = "Treatment-emergent antidrug antibody status (1 = ADA-positive, 0 = ADA-negative)",
      units       = "(binary)",
      type        = "binary",
      notes       = "Screened but not retained. Paper Section 2.2: 'Treatment-emergent ADAs were defined as ADAs that developed any time after the initial drug administration in a patient without preexisting ADAs or a preexisting ADA titer that increased to >=8-fold greater than baseline.' 16.7% ADA-positive overall (Table S1)."
    )
  )

  population <- list(
    species                     = "human",
    n_subjects                  = 84L,
    n_studies                   = 1L,
    n_donidalorsen_q4w          = 41L,
    n_donidalorsen_q8w          = 21L,
    n_placebo                   = 22L,
    n_external_valid_active     = 11L,
    n_external_valid_placebo    = 6L,
    age_range                   = "adult and adolescent (>=12 years; cohort mean 37 y, SD 14)",
    age_median                  = "not published (cohort mean 37 years)",
    weight_range                = "cohort mean 81.7 kg (SD 21.9)",
    sex_female_pct              = 52.4,
    race_ethnicity              = c(
      White                              = 90.5,
      Black_or_African_American          = 2.4,
      Asian                              = 1.2,
      American_Indian_or_Alaskan_Native  = 3.6,
      Other                              = 2.4
    ),
    disease_state               = "Adult and adolescent patients with hereditary angioedema (94.0% HAE-C1INH Type 1, 6.0% HAE-C1INH Type 2) with >=2 investigator-confirmed HAE attacks during the 56-day screening period. 4.8% pretreated with lanadelumab.",
    dose_range                  = "Subcutaneous donidalorsen 80 mg once every 4 weeks (Q4W) or 80 mg once every 8 weeks (Q8W) for 24 weeks; placebo comparator arm.",
    ada_status_positive_pct     = 16.7,
    baseline_hae_attack_rate_mean_per4w = 3.32,
    baseline_hae_attack_rate_sd_per4w   = 2.04,
    baseline_pkk_mean_mgL       = 128,
    baseline_pkk_sd_mgL         = 34.2,
    studies                     = "Phase 3 OASIS-HAE (NCT05139810; N=84 = 41 Q4W + 21 Q8W + 22 placebo). External validation used 17 patients from the Phase 2 study (NCT04030598; 11 donidalorsen 80 mg Q4W + 6 placebo).",
    notes                       = "The exposure-response model was developed on OASIS-HAE data only; external validation used the Phase 2 study but did not refit. The upstream PK/PD used to generate PKK trajectories is Diep 2026 (this registry: modellib('Diep_2026_donidalorsen')), which was fit to a larger pooled cohort (n=177 across four studies including OASIS-HAE)."
  )

  ini({
    # ---- Structural sigmoidal Emax parameters (Singh 2025 Table 1 final-model column) ----
    # Model equation printed on page 3 of Singh 2025 (verbatim, using paper notation):
    #
    #   per_4_week_HAE_attack_rate =
    #     (BLRATE/3)^bHAE * Emax *
    #       [ PKK^Hill / ( (BLPKK/122)^bPKK * EC50^Hill + PKK^Hill ) ]
    #
    # where BLRATE = per-subject baseline per-4-week HAE attack rate (canonical
    # HAERATE_BL), BLPKK = per-subject baseline PKK (canonical PKK_BL), PKK =
    # per-4-week average PKK exposure (canonical PKK). The reference anchors
    # 3 attacks/4W and 122 mg/L are the paper's normalization values (they
    # coincide with the Section 2.3 simulation baselines 3.0 and 122 mg/L).
    # IIV on Emax and Hill only; the final model omits IIV on EC50 (Singh 2025
    # Section 2.2, page 3: 'the model without IIV on EC50 was used for a formal
    # stepwise covariate evaluation').
    lemax <- log(4.50)
    label("Log per-4-week normalized HAE attack rate at infinite PKK for the reference patient (Emax, attacks/4 weeks)")
    # Singh 2025 Table 1 Emax = 4.50 attacks/4W (RSE 9.6%)

    lec50 <- log(110)
    label("Log 4-week-averaged plasma PKK at half-maximum attack rate for the reference patient (EC50, mg/L)")
    # Singh 2025 Table 1 EC50 = 110 mg/L (RSE 0.8%)

    lhill <- log(2.60)
    label("Log Hill coefficient of the sigmoidal PKK-attack-rate relationship (unitless)")
    # Singh 2025 Table 1 Hill = 2.60 (RSE 16%)

    # ---- Covariate-effect exponents on Emax and EC50 (Singh 2025 Table 1) ----
    # Power-form exponents. Estimated (not fixed) with RSEs 7.9% and 14.3%.
    # Reference anchors: HAERATE_BL_ref = 3 attacks/4W; PKK_BL_ref = 122 mg/L.
    e_haerate_bl_emax <- 1.03
    label("Power exponent of baseline HAE attack rate on Emax (unitless)")
    # Singh 2025 Table 1 bHAE = 1.03 (RSE 7.9%); reference anchor HAERATE_BL/3 (page 3 equation)

    e_pkk_bl_ec50 <- 0.13
    label("Power exponent of baseline PKK on the EC50^Hill denominator term (unitless)")
    # Singh 2025 Table 1 bPKK = 0.13 (RSE 14.3%); reference anchor PKK_BL/122 (page 3 equation)

    # ---- IIV (Singh 2025 Table 1; log-normal eta, omega^2 = log(CV^2 + 1)) ----
    # etalemax variance = log(1 + 0.279^2) = 0.074975 -> CV 27.9%
    # etalhill variance = log(1 + 1.31^2)  = 0.999412 -> CV 131%
    etalemax ~ 0.074975
    # Singh 2025 Table 1 IIV on Emax = 27.9% CV -> log(0.279^2 + 1) = 0.074975 (shrinkage 42.7%)

    etalhill ~ 0.999412
    # Singh 2025 Table 1 IIV on Hill = 131% CV -> log(1.31^2 + 1) = 0.999412 (shrinkage 27.1%)
  })

  model({
    # ---- 1. Individual sigmoidal-Emax parameters ----
    # Emax carries the baseline-attack-rate covariate effect via the power
    # form (HAERATE_BL/3)^bHAE (Singh 2025 page 3 equation; reference 3
    # attacks/4W).
    emax_i <- exp(lemax + etalemax) * (HAERATE_BL / 3)^e_haerate_bl_emax

    # EC50 has no IIV; the baseline-PKK covariate effect is applied via the
    # denominator scaling (BLPKK/122)^bPKK * EC50^Hill (Singh 2025 page 3
    # equation; reference 122 mg/L). Equivalent effective EC50 is
    # EC50 * (PKK_BL/122)^(bPKK / Hill).
    ec50_i <- exp(lec50) * (PKK_BL / 122)^(e_pkk_bl_ec50 / exp(lhill + etalhill))

    hill_i <- exp(lhill + etalhill)

    # ---- 2. Sigmoidal Emax attack rate ----
    # Attack rate is a monotonically increasing function of the 4-week-averaged
    # plasma PKK. At PKK = 0 (complete prekallikrein suppression) the rate
    # is 0. At PKK >> EC50_i (no drug effect / untreated) the rate approaches
    # emax_i (subject's baseline-scaled Emax). Reads PKK from the covariate
    # column with LOCF semantics (piecewise-constant per 4-week interval).
    attack_rate <- emax_i * PKK^hill_i / (ec50_i^hill_i + PKK^hill_i)

    # ---- 3. Observation ----
    # Poisson likelihood on the per-4-week HAE attack count with mean equal
    # to the sigmoidal attack rate. Singh 2025 Section 2.2 specifies a
    # generalized-Poisson regression to accommodate overdispersion, but the
    # overdispersion parameter is not reported in Table 1. Extraction uses
    # the standard Poisson approximation; see the vignette's Assumptions and
    # deviations section for rationale and a worked negative-binomial
    # post-processing recipe.
    hae_attacks <- attack_rate
    hae_attacks ~ pois(attack_rate)
  })
}
