Skip to content

Commit

Permalink
Correcting computation of fraction of start month observed
Browse files Browse the repository at this point in the history
  • Loading branch information
Admin_mschuemi authored and Admin_mschuemi committed Nov 9, 2023
1 parent 85d3a93 commit ba0714a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Bugfixes

1. Handling edge case in `computeTimeStability()` when there is only 1 month.

2. Correcting computation of fraction of start month observed for `computeTimeStability()` (was off by 1/31).


SelfControlledCaseSeries 5.0.0
==============================
Expand Down
2 changes: 1 addition & 1 deletion R/Diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ computeTimeStability <- function(studyPopulation, sccsModel = NULL, maxRatio = 1
checkmate::assertNumeric(alpha, lower = 0, upper = 1, len = 1, add = errorMessages)
checkmate::reportAssertions(collection = errorMessages)

data <- SelfControlledCaseSeries:::computeOutcomeRatePerMonth(studyPopulation, sccsModel)
data <- computeOutcomeRatePerMonth(studyPopulation, sccsModel)
if (nrow(data) < 2) {
result <- tibble(ratio = NA,
p = 1,
Expand Down
4 changes: 2 additions & 2 deletions R/SccsDataConversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ convertDateToMonth <- function(date) {

computeMonthFraction <- function(date, post = FALSE) {
# For simplicity assume all months have 31 days. Could use lubridate package to be more precise.
# Assume day it self is included
# Assume day itself is included
if (post) {
return((31-as.numeric(format(date, "%d")))/31)
return((31-as.numeric(format(date, "%d")) + 1)/31)
} else {
return(as.numeric(format(date, "%d"))/31)
}
Expand Down

0 comments on commit ba0714a

Please sign in to comment.