# \donttest{
# An example dataset
test_data <- data.frame(
IDs = c(
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 22, 23, 23, 24, 24, 24, 24, 24
),
Diags = c(
"DZ36", "DZ38", "DZ40", "DZ42", "DC20", "DI252",
"DP290", "DI71", "DH340", "DG30", "DJ40", "DM353",
"DK26", "DK700", "DK711", "DE106", "DE112", "DG82",
"DZ940", "DC80", "DB20", "DK74", "DK704", "DE101",
"DE102", "DB20", "DK74", "DK704", "DE101", "DE102"
),
time = as.Date(c(
"2001-01-30", "2004-05-20", "2007-01-02", "2013-12-01",
"2017-04-30", "2001-01-30", "2004-05-20", "2007-01-02",
"2013-12-01", "2017-04-30", "2001-01-30", "2004-05-20",
"2007-01-02", "2013-12-01", "2017-04-30", "2001-01-30",
"2004-05-20", "2007-01-02", "2013-12-01", "2017-04-30",
"2001-01-30", "2004-05-20", "2007-01-02", "2013-12-01",
"2017-04-30", "2001-01-30", "2004-05-20", "2007-01-02",
"2013-12-01", "2017-04-30"
)),
match_date = as.Date(c(
"2001-10-15", "2005-10-15", "2011-10-15", "2021-10-15",
"2021-10-15", "2001-10-15", "2005-10-15", "2011-10-15",
"2021-10-15", "2021-10-15", "2001-10-15", "2005-10-15",
"2011-10-15", "2021-10-15", "2021-10-15", "2001-10-15",
"2005-10-15", "2011-10-15", "2021-10-15", "2021-10-15",
"2001-10-15", "2005-10-15", "2011-10-15", "2021-10-15",
"2021-10-15", "2001-10-15", "2005-10-15", "2011-10-15",
"2021-10-15", "2021-10-15"
))
)
# Minimal example
charlson_score(
data = test_data,
Person_ID = IDs,
diagnosis_variable = Diags
)
# Minimal example with all index diagnosis variables
charlson_score(
data = test_data,
Person_ID = IDs,
diagnosis_variable = Diags,
amount_output = "all"
)
# Imposing uniform date restrictions to diagnoses
charlson_score(
data = test_data,
Person_ID = IDs,
diagnosis_variable = Diags,
time_variable = time,
end_date = as.Date("2012-01-01")
)
# Imposing differing date restriction to diagnoses
charlson_score(
data = test_data,
Person_ID = IDs,
diagnosis_variable = Diags,
time_variable = time,
end_date = match_date
)
# Imposing both a start and end to the lookup period for
# relevant diagnoses
charlson_score(
data = test_data,
Person_ID = IDs,
diagnosis_variable = Diags,
time_variable = time,
end_date = match_date,
days_before_end_date = 365.25
)
# }
Run the code above in your browser using DataLab