Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion R/sim_cox_age_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-sim_cox_age_data_baseline.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
24 changes: 12 additions & 12 deletions vignettes/survival-data-with-a-constant-baseline-hazard.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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(
Expand All @@ -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
```
24 changes: 12 additions & 12 deletions vignettes/survival-data-with-age-specific-baseline-hazard.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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(
Expand All @@ -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
```
Loading