# Generate example data
set.seed(123)
# Parameters
# Total number of patients
n_patients <- 5000
# Arbitrary group labels
groups <- sample(x = LETTERS[1:2], size = n_patients, replace = TRUE)
# Trauma types
trauma_type_values <- sample(
x = c("Blunt", "Penetrating"),
size = n_patients,
replace = TRUE
)
# RTS values
rts_values <- sample(
x = seq(from = 0, to = 7.8408, by = 0.005),
size = n_patients,
replace = TRUE
)
# patient ages
ages <- sample(
x = seq(from = 0, to = 100, by = 1),
size = n_patients,
replace = TRUE
)
# ISS scores
iss_scores <- sample(
x = seq(from = 0, to = 75, by = 1),
size = n_patients,
replace = TRUE
)
# Generate survival probabilities (Ps)
Ps <- traumar::probability_of_survival(
trauma_type = trauma_type_values,
age = ages,
rts = rts_values,
iss = iss_scores
)
# Simulate survival outcomes based on Ps
survival_outcomes <- rbinom(n_patients, size = 1, prob = Ps)
# Create data frame
data <- data.frame(Ps = Ps, survival = survival_outcomes, groups = groups) |>
dplyr::mutate(death = dplyr::if_else(survival == 1, 0, 1))
# Example usage of the `rmm` function
rmm(data = data, Ps_col = Ps,
outcome_col = survival,
Divisor1 = 4,
Divisor2 = 4,
n_samples = 10
)
# pivot!
rmm(data = data, Ps_col = Ps,
outcome_col = survival,
Divisor1 = 4,
Divisor2 = 4,
n_samples = 10,
pivot = TRUE
)
# Create example grouping variable (e.g., hospital)
hospital <- sample(c("Hospital A", "Hospital B"), n_patients, replace = TRUE)
# Create data frame
data <- data.frame(
Ps = Ps,
survival = survival_outcomes,
hospital = hospital
) |>
dplyr::mutate(death = dplyr::if_else(survival == 1, 0, 1))
# Example usage of the `rmm` function with grouping by hospital
rmm(
data = data,
Ps_col = Ps,
outcome_col = survival,
group_vars = "hospital",
Divisor1 = 4,
Divisor2 = 4,
n_samples = 10
)
# Pivoted output for easier visualization
rmm(
data = data,
Ps_col = Ps,
outcome_col = survival,
group_vars = "hospital",
Divisor1 = 4,
Divisor2 = 4,
n_samples = 10,
pivot = TRUE
)
Run the code above in your browser using DataLab