Simulate covariates
simu_cov.Rd
This function generates continuous and binary covariates through simulating from a multivariate normal distribution. Outcomes are further converted to binary variables using quantiles of the normal distribution calculated from the probability provided. Then the covariates are added to the external trial and treatment arm indicators.
Arguments
- ssObj
an object of class
.covClass
generated inset_n
- covObj
an object of class
.covClass
generated inset_cov
- driftHR
hazard ratio of external control and internal control arms
- HR
a list of hazard ratio of treatment and control arms
- nsim
number of simulation. Default is 5
- seed
the seed of R‘s random number generator. Default is the first element of .Random.seed
- path
file name for saving the output including folder path
Examples
# simulate patient-level data with 1 continuous covariate
sample = set_n(ssC = 10, ssE = 20, ssExt = 40)
cov1 = set_cov(n_cat = 0, n_cont = 1, mu_int = 0, mu_ext = 0, var = 1)
simu_cov(ssObj = sample, covObj = cov1, HR = 0.5, driftHR = 1, nsim = 2)
#> The sample size for internal control, internal treatment, and external control arms are 10, 20, and 40, respectively.
#> Set seed to 10403
#> ------------------- #1of 2simulation: #1of HR =0.5, #1of driftHR = 1, seed =10403
#> ------------------- #2of 2simulation: #1of HR =0.5, #1of driftHR = 1, seed =10404
#> Simulated covariates are not saved.
#> [,1]
#> [1,] numeric,350
#> [2,] numeric,350
# simulate patient-level data with 1 binary and 2 continuous covariate
cov2 = set_cov(n_cat = 1, n_cont = 2, mu_int = 0, mu_ext = 0, var = 1,
cov = 0.3, prob_int = 0.2, prob_ext = 0.3)
#> User provides one mean of covariate in internal trials. This value is used for all covariates
#> User provides one mean of covariate in external trials. This value is used for all covariates
#> User provides one number for variance. This variance is used for all covariates
#> User provides one number: 0.3 for covariance. This covariance is used for all covariates
simu_cov(ssObj = sample, covObj = cov2, HR = 0.5, driftHR = 1, nsim = 2)
#> The sample size for internal control, internal treatment, and external control arms are 10, 20, and 40, respectively.
#> Set seed to 10403
#> ------------------- #1of 2simulation: #1of HR =0.5, #1of driftHR = 1, seed =10403
#> ------------------- #2of 2simulation: #1of HR =0.5, #1of driftHR = 1, seed =10404
#> Simulated covariates are not saved.
#> [,1]
#> [1,] numeric,490
#> [2,] numeric,490