Skip to content

Commit

Permalink
More explicit behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
schuemie committed Aug 9, 2024
1 parent a5b7430 commit cc2652e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions R/SccsDataConversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ createSccsIntervalData <- function(studyPopulation,
cases = cases,
outcomes = outcomes,
eras = sccsData$eras,
includeAge = !isTRUE(all.equal(settings$ageDesignMatrix, matrix())),
includeAge = settings$includeAge,
ageOffset = settings$ageOffset,
ageDesignMatrix = settings$ageDesignMatrix,
includeSeason = !isTRUE(all.equal(settings$seasonDesignMatrix, matrix())),
includeSeason = settings$includeSeason,
seasonDesignMatrix = settings$seasonDesignMatrix,
includeCalendarTime = !isTRUE(all.equal(settings$calendarTimeDesignMatrix, matrix())),
includeCalendarTime = settings$includeCalendarTime,
calendarTimeOffset = settings$calendarTimeOffset,
calendarTimeDesignMatrix = settings$calendarTimeDesignMatrix,
timeCovariateCases = timeCovariateCases,
Expand Down Expand Up @@ -205,6 +205,7 @@ addAgeSettings <- function(settings,
if (is.null(ageCovariateSettings)) {
settings$ageOffset <- 0
settings$ageDesignMatrix <- matrix()
settings$includeAge <- FALSE
return(settings)
} else {
if (length(ageCovariateSettings$ageKnots) == 1) {
Expand All @@ -228,6 +229,7 @@ addAgeSettings <- function(settings,
knots = ageKnots[2:(length(ageKnots) - 1)],
Boundary.knots = ageKnots[c(1, length(ageKnots))],
degree = 2)
settings$includeAge <- TRUE
splineCovariateRef <- tibble(
covariateId = 100:(100 + length(ageKnots) - 1),
covariateName = paste(
Expand All @@ -253,6 +255,7 @@ addAgeSettings <- function(settings,
addSeasonalitySettings <- function(settings, seasonalityCovariateSettings, sccsData) {
if (is.null(seasonalityCovariateSettings)) {
settings$seasonDesignMatrix <- matrix()
settings$includeSeason <- FALSE
} else {
if (length(seasonalityCovariateSettings$seasonKnots) == 1) {
# Single number, should interpret as number of knots. Spread out knots evenly:
Expand All @@ -261,6 +264,7 @@ addSeasonalitySettings <- function(settings, seasonalityCovariateSettings, sccsD
seasonKnots <- seasonalityCovariateSettings$seasonKnots
}
settings$seasonDesignMatrix <- cyclicSplineDesign(1:12, knots = seasonKnots)
settings$includeSeason <- TRUE
splineCovariateRef <- tibble(
covariateId = 200:(200 + length(seasonKnots) - 2),
covariateName = paste(
Expand Down Expand Up @@ -290,13 +294,15 @@ addCalendarTimeSettings <- function(settings,
if (is.null(calendarTimeCovariateSettings)) {
settings$calendarTimeOffset <- 0
settings$calendarTimeDesignMatrix <- matrix()
settings$includeCalendarTime <- FALSE
return(settings)
} else if ((length(calendarTimeCovariateSettings$calendarTimeKnots) == 1 &&
calendarTimeCovariateSettings$calendarTimeKnots > nrow(studyPopulation$outcomes)) ||
(length(calendarTimeCovariateSettings$calendarTimeKnots) > nrow(studyPopulation$outcomes))) {
warning("There are more calendar time knots than cases. Removing calendar time from model")
settings$calendarTimeOffset <- 0
settings$calendarTimeDesignMatrix <- matrix()
settings$includeCalendarTime <- FALSE
return(settings)
} else {
if (length(calendarTimeCovariateSettings$calendarTimeKnots) == 1) {
Expand Down Expand Up @@ -341,6 +347,7 @@ addCalendarTimeSettings <- function(settings,
x = seq(firstKnot, lastKnot),
knotsPerSegment = calendarTimeKnotsInPeriods
)
settings$includeCalendarTime <- TRUE
splineCovariateRef <- tibble(
covariateId = 300 + seq_len(ncol(settings$calendarTimeDesignMatrix)) - 1,
covariateName = paste(
Expand Down

0 comments on commit cc2652e

Please sign in to comment.