|
| 1 | +## code to prepare `SyntheticData` dataset |
| 2 | +## Based on real clinical trial summary statistics (SMA study) |
| 3 | +## Covariates are generated via copula to mimic realistic correlation structure |
| 4 | + |
| 5 | +library(copula) |
| 6 | +library(rdborrow) |
| 7 | + |
| 8 | +set.seed(202403) |
| 9 | + |
| 10 | +# ===== Copula for correlated covariates ===== |
| 11 | +normal <- copula::normalCopula(param = c(0.8), dim = 4, dispstr = "ar1") |
| 12 | + |
| 13 | +# ===== Generate internal (RCT) covariates ===== |
| 14 | +# x1 = SMA_Type (0 = Type II, 1 = Type III) |
| 15 | +# x2 = SMN2_Copy_Number (0 = 3 copies, 1 = 4 copies) |
| 16 | +# x3 = Scoliosis (0 = No, 1 = Yes) |
| 17 | +# x4 = Age_Enrollment |
| 18 | +X_int <- simulate_X_copula( |
| 19 | + n = 200, |
| 20 | + p = 4, |
| 21 | + cp = normal, |
| 22 | + margins = c("binom", "binom", "binom", "exp"), |
| 23 | + paramMargins = list( |
| 24 | + list(size = 1, prob = 0.7), |
| 25 | + list(size = 1, prob = 0.9), |
| 26 | + list(size = 1, prob = 0.3), |
| 27 | + list(rate = 1 / 10) |
| 28 | + ) |
| 29 | +) |
| 30 | + |
| 31 | +X_int$x4 <- round(X_int$x4) + 1 |
| 32 | +# x5 = Baseline outcome (Y0), modeled as linear function of covariates |
| 33 | +X_int$x5 <- 30 + 10 * X_int$x1 + 7 * X_int$x2 + |
| 34 | + (-6) * X_int$x3 + (-0.5) * X_int$x4 + |
| 35 | + rnorm(200, mean = 0, sd = 10) |
| 36 | + |
| 37 | +# ===== Generate external control covariates ===== |
| 38 | +X_ext <- simulate_X_copula( |
| 39 | + n = 100, |
| 40 | + p = 4, |
| 41 | + cp = normal, |
| 42 | + margins = c("binom", "binom", "binom", "exp"), |
| 43 | + paramMargins = list( |
| 44 | + list(size = 1, prob = 0.7), |
| 45 | + list(size = 1, prob = 0.9), |
| 46 | + list(size = 1, prob = 0.3), |
| 47 | + list(rate = 1 / 10) |
| 48 | + ) |
| 49 | +) |
| 50 | + |
| 51 | +X_ext$x4 <- round(X_ext$x4) + 1 |
| 52 | +# External baseline outcome has different intercept/coefficients |
| 53 | +X_ext$x5 <- 50 + 10 * X_ext$x1 + 2 * X_ext$x2 + |
| 54 | + (-1) * X_ext$x3 + (-0.3) * X_ext$x4 + |
| 55 | + rnorm(100, mean = 0, sd = 10) |
| 56 | + |
| 57 | +# ===== Outcome model specifications ===== |
| 58 | +varnames <- c("1", paste0("x", 1:5)) |
| 59 | + |
| 60 | +# Coefficients: intercept, SMA_Type, SMN2_Copy, Scoliosis, Age, Y0 |
| 61 | +# Treatment effect (A) and noise SD noted in comments |
| 62 | +model_form_x_t1 <- setNames( |
| 63 | + c(10.0, 0.05, -1.5, -1.0, -0.2, -0.1), varnames |
| 64 | +) # effect = 1.5, sigma = 4.0 |
| 65 | + |
| 66 | +model_form_x_t2 <- setNames( |
| 67 | + c(6.0, 0.5, -0.5, -1.0, -0.3, -0.06), varnames |
| 68 | +) # effect = 1.8, sigma = 4.0 |
| 69 | + |
| 70 | +model_form_x_t3 <- setNames( |
| 71 | + c(5.0, 1.9, 1.4, -1.3, -0.4, -0.15), varnames |
| 72 | +) # effect = 1.6, sigma = 4.0 |
| 73 | + |
| 74 | +model_form_x_t4 <- setNames( |
| 75 | + c(1.2, 1.0, 2.0, -0.5, -0.4, -0.10), varnames |
| 76 | +) # effect = 2.5, sigma = 5.0 |
| 77 | + |
| 78 | +outcome_model_specs <- list( |
| 79 | + list( |
| 80 | + effect = 0, model_form_x = model_form_x_t1, |
| 81 | + noise_mean = 0, noise_sd = 4 |
| 82 | + ), |
| 83 | + list( |
| 84 | + effect = 1.0, model_form_x = model_form_x_t2, |
| 85 | + noise_mean = 0, noise_sd = 4 |
| 86 | + ), |
| 87 | + list( |
| 88 | + effect = 2.0, model_form_x = model_form_x_t3, |
| 89 | + noise_mean = 0, noise_sd = 4 |
| 90 | + ), |
| 91 | + list( |
| 92 | + effect = 5.0, model_form_x = model_form_x_t4, |
| 93 | + noise_mean = 0, noise_sd = 4 |
| 94 | + ) |
| 95 | +) |
| 96 | + |
| 97 | +# ===== Simulate trial data ===== |
| 98 | +SyntheticData <- simulate_trial( |
| 99 | + X_int, |
| 100 | + X_ext, |
| 101 | + num_treated = 100, |
| 102 | + OLE_flag = TRUE, |
| 103 | + T_cross = 2, |
| 104 | + outcome_model_specs |
| 105 | +) |
| 106 | + |
| 107 | +# ===== Save to data/ ===== |
| 108 | +usethis::use_data(SyntheticData, overwrite = TRUE) |
0 commit comments