From 67f465f0ddf91cdfc2b4c34b0256e4b7a6425cc6 Mon Sep 17 00:00:00 2001 From: Ali Date: Wed, 25 Feb 2026 12:12:35 +0100 Subject: [PATCH 1/3] simulation preserves input covariates column names --- R/sim_cox_age_data.R | 2 +- tests/testthat/test-sim_cox_age_data_baseline.R | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/R/sim_cox_age_data.R b/R/sim_cox_age_data.R index e19ea27..e27774e 100644 --- a/R/sim_cox_age_data.R +++ b/R/sim_cox_age_data.R @@ -66,7 +66,7 @@ sim_cox_age_data <- function(n, } time <- age_exit - entry_age - colnames(x) <- if (is.null(colnames(x))) paste0("Exp", seq_len(p)) else colnames(x) + colnames(x) <- if (is.null(colnames(covariates))) paste0("Exp", seq_len(p)) else colnames(covariates) out <- data.frame( id = seq_len(n), diff --git a/tests/testthat/test-sim_cox_age_data_baseline.R b/tests/testthat/test-sim_cox_age_data_baseline.R index a9383d1..64ef09a 100644 --- a/tests/testthat/test-sim_cox_age_data_baseline.R +++ b/tests/testthat/test-sim_cox_age_data_baseline.R @@ -35,6 +35,23 @@ test_that("sim_cox_age_data simulates with a constant baseline hazard", { ) }) +test_that("sim_cox_age_data preserves covariate column names", { + set.seed(321) + covs <- matrix(c(0, 1, 1, 0), nrow = 2, byrow = TRUE) + colnames(covs) <- c("smoking", "bmi_cat") + + out <- sim_cox_age_data( + n = 2, + entry_age = c(40, 41), + censor_age = c(45, 46), + beta = c(0.2, -0.1), + covariates = covs, + baseline_hazard = 0.05 + ) + + expect_equal(colnames(out), c("id", "entry_age", "censor_age", "event", "smoking", "bmi_cat")) +}) + test_that("scalar ages recycle to length n", { set.seed(99) out <- sim_cox_age_data( From b686eba4240fb7f3dfea242b85c0a8925bd24b3d Mon Sep 17 00:00:00 2001 From: Ali Date: Wed, 25 Feb 2026 12:13:17 +0100 Subject: [PATCH 2/3] update vignette commented outputs --- ...l-data-with-a-constant-baseline-hazard.Rmd | 24 +++++++++---------- ...data-with-age-specific-baseline-hazard.Rmd | 24 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/vignettes/survival-data-with-a-constant-baseline-hazard.Rmd b/vignettes/survival-data-with-a-constant-baseline-hazard.Rmd index 198f5c7..93753fa 100644 --- a/vignettes/survival-data-with-a-constant-baseline-hazard.Rmd +++ b/vignettes/survival-data-with-a-constant-baseline-hazard.Rmd @@ -70,7 +70,7 @@ print(fit) The achieved incidence rate is stored as an attribute (events / person-time): ```r -attr(sim, "achieved_incidence_rate") +print(attr(sim, "achieved_incidence_rate")) # [1] 0.01163777 ``` @@ -96,14 +96,14 @@ print(fit) # survival::coxph(formula = survival::Surv(entry_age, censor_age, # event) ~ Exp1 + Exp2, data = sim) -# coef exp(coef) se(coef) z p -# Exp1 0.53005 1.69902 0.05563 9.529 <2e-16 -# Exp2 0.57055 1.76924 0.05447 10.475 <2e-16 +# coef exp(coef) se(coef) z p +# Exp1 0.46686 1.59498 0.05846 7.986 1.39e-15 +# Exp2 0.46808 1.59692 0.05649 8.286 < 2e-16 -# Likelihood ratio test=189.6 on 2 df, p=< 2.2e-16 -# n= 1000, number of events= 336 +# Likelihood ratio test=126.7 on 2 df, p=< 2.2e-16 +# n= 1000, number of events= 316 print(attr(sim, "achieved_incidence_rate")) -# [1] 0.02058137 +# [1] 0.01893861 beta_2 <- c(1.5, 1.5) sim_2 <- HDccAnalysis::sim_cox_age_data( @@ -123,11 +123,11 @@ print(fit_2) # event) ~ Exp1 + Exp2, data = sim_2) # coef exp(coef) se(coef) z p -# Exp1 1.47632 4.37679 0.07301 20.22 <2e-16 -# Exp2 1.46515 4.32819 0.07185 20.39 <2e-16 +# Exp1 1.46640 4.33360 0.07387 19.85 <2e-16 +# Exp2 1.50335 4.49673 0.07297 20.60 <2e-16 -# Likelihood ratio test=739.5 on 2 df, p=< 2.2e-16 -# n= 1000, number of events= 323 +# Likelihood ratio test=744.9 on 2 df, p=< 2.2e-16 +# n= 1000, number of events= 331 print(attr(sim_2, "achieved_incidence_rate")) -# [1] 0.02068137 +# [1] 0.02102166 ``` \ No newline at end of file diff --git a/vignettes/survival-data-with-age-specific-baseline-hazard.Rmd b/vignettes/survival-data-with-age-specific-baseline-hazard.Rmd index 40c32d2..bd7b338 100644 --- a/vignettes/survival-data-with-age-specific-baseline-hazard.Rmd +++ b/vignettes/survival-data-with-age-specific-baseline-hazard.Rmd @@ -83,7 +83,7 @@ print(fit) The achieved incidence rate (events per person-time): ```r -attr(sim, "achieved_incidence_rate") +print(attr(sim, "achieved_incidence_rate")) # [1] 0.01367849 ``` @@ -109,14 +109,14 @@ print(fit) # survival::coxph(formula = survival::Surv(entry_age, censor_age, # event) ~ Exp1 + Exp2, data = sim) -# coef exp(coef) se(coef) z p -# Exp1 0.40245 1.49549 0.05116 7.866 3.66e-15 -# Exp2 0.57387 1.77512 0.05277 10.875 < 2e-16 +# coef exp(coef) se(coef) z p +# Exp1 0.40482 1.49903 0.05459 7.415 1.21e-13 +# Exp2 0.49940 1.64774 0.05532 9.027 < 2e-16 -# Likelihood ratio test=175 on 2 df, p=< 2.2e-16 -# n= 1000, number of events= 367 +# Likelihood ratio test=130.8 on 2 df, p=< 2.2e-16 +# n= 1000, number of events= 325 print(attr(sim, "achieved_incidence_rate")) -# [1] 0.0212904 +# [1] 0.0187728 beta_2 <- c(1.5, 1.5) sim_2 <- HDccAnalysis::sim_cox_age_data( @@ -136,11 +136,11 @@ print(fit_2) # event) ~ Exp1 + Exp2, data = sim_2) # coef exp(coef) se(coef) z p -# Exp1 1.47227 4.35912 0.06993 21.05 <2e-16 -# Exp2 1.38520 3.99564 0.07145 19.39 <2e-16 +# Exp1 1.47836 4.38573 0.07176 20.60 <2e-16 +# Exp2 1.48883 4.43190 0.07324 20.33 <2e-16 -# Likelihood ratio test=726.9 on 2 df, p=< 2.2e-16 -# n= 1000, number of events= 349 +# Likelihood ratio test=737.9 on 2 df, p=< 2.2e-16 +# n= 1000, number of events= 320 print(attr(sim_2, "achieved_incidence_rate")) -# [1] 0.02121945 +# [1] 0.01927724 ``` \ No newline at end of file From 8775546e6852c72ca9e62382fd99c9068eb64621 Mon Sep 17 00:00:00 2001 From: Ali Date: Wed, 25 Feb 2026 12:13:57 +0100 Subject: [PATCH 3/3] update version to 0.1.1 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 95c5081..abbb7fc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: HDccAnalysis Title: High-Dimensional Case-Cohort Analysis -Version: 0.1.0 +Version: 0.1.1 Authors@R: c( person("Ali", "Farnudi", email = "farnudia@iarc.who.int",