Skip to content

Commit edb4762

Browse files
authored
279 data sim bug (#289)
* failing test w/ bug * was failing for wrong reasons * fun fix * vbump
1 parent 0717586 commit edb4762

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: psborrow2
33
Title: Bayesian Dynamic Borrowing Analysis and Simulation
4-
Version: 0.0.3.2
4+
Version: 0.0.3.3
55
Authors@R: c(
66
person(
77
given = "Matt",

R/simulate_data.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ cut_off_after_last <- function(time) {
325325
cut_off_after_events <- function(n) {
326326
.datasim_cut_off(
327327
fun = function(data) {
328-
cut_time <- sort(data$enrollment + data$eventtime)[n]
328+
data_s1 <- data[data$status == 1, ]
329+
cut_time <- sort(data_s1$enrollment + data_s1$eventtime)[n]
329330
after_cut_off <- data$enrollment + data$eventtime > cut_time
330331
data$status <- ifelse(after_cut_off, 0, data$status)
331332
data$eventtime <- ifelse(after_cut_off, cut_time - data$enrollment, data$eventtime)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<!-- badges: start -->
44

5-
[![Version](https://img.shields.io/static/v1.svg?label=github.com/genentech&message=v.0.0.3.2&color=DC0073)](https://github.com/Genentech/psborrow2)
5+
[![Version](https://img.shields.io/static/v1.svg?label=github.com/genentech&message=v.0.0.3.3&color=DC0073)](https://github.com/Genentech/psborrow2)
66
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-green.svg)](https://www.tidyverse.org/lifecycle/#stable)
77

88
<!-- badges: end -->

tests/testthat/test-simulate_data.R

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,24 @@ test_that("cut_off_after_last works as expected", {
177177
test_that("cut_off_after_events works as expected", {
178178
result <- cut_off_after_events(n = 2)
179179
expect_class(result, "DataSimCutOff")
180-
test_data <- data.frame(id = 1:4, eventtime = c(2, 5, 2, 4), enrollment = c(1, 2, 3, 7), status = c(1, 0, 1, 1))
180+
test_data <- data.frame(
181+
id = 1:8,
182+
status = rep(c(1, 0), length.out = 8),
183+
eventtime = rep(1:4, each = 2),
184+
enrollment = rep(2:5, length.out = 8)
185+
)
186+
181187
cutoff_data <- result@fun(test_data)
188+
189+
# for n = 2, 2nd event is at 5 time units: pts 1 and 5
182190
expected_data <- data.frame(
183-
id = 1:3, eventtime = c(2, 3, 2), enrollment = 1:3, status = c(1, 0, 1)
191+
id = c(1, 2, 3, 5, 6, 7), # Lose pts who enroll on/after 5 time units
192+
status = c(1, 0, 0, 1, 0, 0), # Reassign pts who have events > 5 time units (enroll+event)
193+
eventtime = c(1, 1, 1, 3, 2, 1), # Max follow-up is 5 units,
194+
enrollment = rep(c(2,3,4), length.out = 6)
184195
)
185-
expect_equal(cutoff_data, expected_data)
196+
197+
expect_equal(cutoff_data, expected_data, ignore_attr = TRUE)
186198
})
187199

188200
# set_cut_off --------

0 commit comments

Comments
 (0)