Skip to content

Generate or edit plan / timepoint from analysis function #59

@saumil-sh

Description

@saumil-sh

to change the structure of the trial via timepoint swapping:

set.seed(123)
 
data <- rbind(
  cbind(
    subject_id = 1:20,
    measurement_time = 1,
    value = rnorm(20, mean = 50)
  ),
  cbind(
    subject_id = 1:20,
    measurement_time = 4,
    value = rnorm(20, mean = 50)
  )
)
pop1 <- Population$new("Arm A", data = data.frame(data))
 
timepoints <- data.frame(
  time = c(1,2,3.1,4,5,6),
  arm = rep("Arm A", 6),
  dropper = c(2L, rep(1L, 5)),
  enroller = rep(3L, 6)
)
timepoints2 <- data.frame(
  time = c(1,2,3.1,4,5,6),
  arm = rep("Arm A", 6),
  dropper = c(2L, rep(1L, 5)),
  enroller = c(rep(3L,4),rep(0L, 2))
)
# --- Timers with multiple timepoints ---
t <- Timer$new(name = "TrialTimers") # Use your updated Timers from earlier
add_timepoints(t, timepoints)
 
t$add_condition(
  time==2 |time==4 |time==5,
  analysis = function(d, tt) {
    res=mean(d$value)
    if(tt==4){
      t$timelist <- list()     # not NULL
      add_timepoints(t, timepoints2)

    } else(return(res))
  },
  name = "overall_mean"
)
 
trial <- Trial$new(
  name = "Trial A",
  timer = t,
  population = list(pop1)
)
 
# --- Run ---
trial$run()

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions