Skip to content

Commit

Permalink
Truncating simulated usage at 0 when using negative slope. Droppping …
Browse files Browse the repository at this point in the history
…simulation scripts moved to study repo
  • Loading branch information
schuemie committed Nov 5, 2024
1 parent a7a805e commit bb04c0c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 473 deletions.
12 changes: 9 additions & 3 deletions R/Simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,19 @@ simulateBatch <- function(settings, ageFun, seasonFun, calendarTimeFun, caseIdOf

# Generate eras ----------------------------------------------------------------------------------
cumulativeIntensity <- function(t, usageRate, usageRateSlope) {
usageRate * t + 0.5 * usageRateSlope * t^2
if (usageRateSlope < 0) {
t <- pmin(-usageRate / usageRateSlope, t)
}
return(usageRate * t + 0.5 * usageRateSlope * t^2)
}

inverseCumulativeIntensity <- function(u, usageRate, usageRateSlope, days) {
if (usageRateSlope == 0) {
t <- u * days
} else {
if (usageRateSlope < 0) {
days <- pmin(-usageRate / usageRateSlope, days)
}
lambdaT <- usageRate * days + 0.5 * usageRateSlope * days^2
t <- (-usageRate + sqrt(usageRate^2 + 2 * usageRateSlope * u * lambdaT)) / usageRateSlope
}
Expand All @@ -218,8 +224,8 @@ simulateBatch <- function(settings, ageFun, seasonFun, calendarTimeFun, caseIdOf
u <- runif(nEvents)
startDay <- sapply(u,
inverseCumulativeIntensity,
usageRate = settings$usageRate[i],
usageRateSlope = settings$usageRateSlope[i],
usageRate = usageRate,
usageRateSlope = usageRateSlope,
days = observationDays[idx]) |>
round() |>
unique() |>
Expand Down
234 changes: 0 additions & 234 deletions extras/EndOfExposureSimulations.R

This file was deleted.

Loading

0 comments on commit bb04c0c

Please sign in to comment.