trial_seq_object <- trial_sequence("ITT") |>
set_data(data_censored) |>
set_outcome_model(
adjustment_terms = ~age_s,
followup_time_terms = ~ stats::poly(followup_time, degree = 2)
) |>
set_expansion_options(output = save_to_datatable(), chunk_size = 500) |>
expand_trials() |>
load_expanded_data()
fit_msm(trial_seq_object)
# Using modify_weights functions ----
# returns a function that truncates weights to limits
limit_weight <- function(lower_limit, upper_limit) {
function(w) {
w[w > upper_limit] <- upper_limit
w[w < lower_limit] <- lower_limit
w
}
}
# calculate 1st and 99th percentile limits and truncate
p99_weight <- function(w) {
p99 <- quantile(w, prob = c(0.01, 0.99), type = 1)
limit_weight(p99[1], p99[2])(w)
}
# set all weights to 1
all_ones <- function(w) {
rep(1, length(w))
}
fit_msm(trial_seq_object, modify_weights = limit_weight(0.01, 4))
fit_msm(trial_seq_object, modify_weights = p99_weight)
Run the code above in your browser using DataLab