winsorize_ccw_weights.Rd
Remove extreme weights from the long data.frame generated by generate_ccw()
to avoid influential observations.
Uses stats::quantile()
.
winsorize_ccw_weights(df, quantiles = c(0.01, 0.99), per_clone = FALSE)
A data.frame with one row per clone per observation period that contains weights for each patient-period as returned by generate_ccw()
A vector of two values between 0 and 1 that define the lower and upper quantiles to use for winsorization. Default is c(0.01, 0.99).
Boolean indicating whether to winsorize the weights according to quantiles per clone (TRUE) or across all clones (FALSE). Default is FALSE. Weights get winsorized for all patient-periods in both cases.
The same data.frame with weights winsorized.
# Load the toy dataset
data(dummy_data)
# Create clones
clones <- create_clones(dummy_data,
id = "id",
event = "event",
time_to_event = "timetoevent",
exposure = "exposure",
time_to_exposure = "timetoexposure",
ced_window = 100)
#> Updating 4 patients' exposure and time-to-exposure based on CED window
clones_long <- cast_clones_to_long(clones)
clones_long_w <- generate_ccw(clones_long, predvars = c("cov1"))
clones_long_w_wins <- winsorize_ccw_weights(clones_long_w)