Skip to content

Commit

Permalink
Adding option to simulate monotonic calender time effects
Browse files Browse the repository at this point in the history
  • Loading branch information
schuemie committed Nov 29, 2024
1 parent 857b28e commit 6f228ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions R/Simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ createSimulationRiskWindow <- function(start = 0,
#' @param seasonKnots Number of knots in the seasonality spline.
#' @param includeCalendarTimeEffect Include a calendar time effect for the outcome?
#' @param calendarTimeKnots Number of knots in the calendar time spline.
#' @param calenderTimeMonotonic Should the calender time effect be monotonic?
#' @param outcomeId The ID to be used for the outcome.
#'
#' @return
Expand Down Expand Up @@ -122,6 +123,7 @@ createSccsSimulationSettings <- function(meanPatientTime = 4 * 365,
seasonKnots = 5,
includeCalendarTimeEffect = TRUE,
calendarTimeKnots = 5,
calenderTimeMonotonic = FALSE,
outcomeId = 10) {
errorMessages <- checkmate::makeAssertCollection()
checkmate::assertNumeric(meanPatientTime, lower = 0, len = 1, add = errorMessages)
Expand All @@ -148,6 +150,7 @@ createSccsSimulationSettings <- function(meanPatientTime = 4 * 365,
checkmate::assertInt(seasonKnots, lower = 2, add = errorMessages)
checkmate::assertLogical(includeCalendarTimeEffect, len = 1, add = errorMessages)
checkmate::assertInt(calendarTimeKnots, lower = 2, add = errorMessages)
checkmate::assertLogical(calenderTimeMonotonic, len = 1, add = errorMessages)
checkmate::assertInt(outcomeId, add = errorMessages)
checkmate::reportAssertions(collection = errorMessages)

Expand Down Expand Up @@ -397,6 +400,13 @@ simulateSccsData <- function(nCases, settings) {
if (settings$includeCalendarTimeEffect) {
calendarTime <- seq(settings$minCalendarTime, settings$maxCalendarTime, length.out = settings$calendarTimeKnots)
calendarTimeRisk <- runif(settings$calendarTimeKnots, -2, 2)
if (settings$calenderTimeMonotonic) {
increasing <- calendarTimeRisk[1] > 0
calendarTimeRisk <- cumsum(abs(calendarTimeRisk))
if (!increasing) {
calendarTimeRisk <- -calendarTimeRisk
}
}
calendarTimeFun <- splinefun(as.numeric(calendarTime), calendarTimeRisk)
} else {
calendarTimeFun <- NULL
Expand Down
2 changes: 1 addition & 1 deletion man/computeExposureChange.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/createSccsSimulationSettings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f228ef

Please sign in to comment.