fit_msm | R Documentation |
fit_msm(
object,
weight_cols = c("weight", "sample_weight"),
modify_weights = NULL
)
## S4 method for signature 'trial_sequence'
fit_msm(
object,
weight_cols = c("weight", "sample_weight"),
modify_weights = NULL
)
object |
A |
weight_cols |
character vector of column names in expanded outcome dataset, ie |
modify_weights |
a function to transform the weights (or Before the outcome marginal structural model can be fit, the outcome model must be specified with
The model is fit based on the |
A modified trial_sequence
object with updated outcome_model
slot.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.