Calculates comorbidities and outcomes (including time to for the latter) from DIA, OP and ekod variables from National Patient Registry.
create_sosvar(
type,
name,
sosdata,
cohortdata,
patid = lopnr,
indexdate = indexdtm,
add_unique,
sosdate = sosdtm,
censdate,
allowedcenslimit = 0,
noof = FALSE,
comduration = FALSE,
starttime = ifelse(type == "com", 0, 1),
stoptime,
diakod,
opkod,
ekod,
diakodneg = FALSE,
opkodneg = FALSE,
ekodneg = FALSE,
diavar = DIA_all,
opvar = OP_all,
evar = ekod_all,
valsclass = "num",
meta_reg = "NPR (in+out)",
meta_pos,
warnings = TRUE
)
Possible values are "out" and "com". Is the resulting variable an outcome (and time to is calculated) or comorbidity?
Name of resulting variable (prefix sos_out_ is added to outcome and sos_com_ to comorbidity).
Data where DIA, OP, Ekod variables are found.
Data containing the cohort with at least columns patid and indexdate.
Patient identifier. Default is lopnr.
Index date for the patient (usually date of admission or discharge entered into SwedeHF). Default is indexdtm.
If patid and indexdate are not unique in cohortdata, this identifies unique posts.
Date of incident (comorbidity or outcome) in sosdata. Default is sosdtm.
Vector of dates. Only applicable for type = "out". Outcomes are allowed up until this day (usually date of death or end follow-up).
Optional single value with allowed time unit between sosdate and censdate that still makes the sosdate be a valid event. Used for example when patients who are discharged day after death should still be counted as an event. Can cause unexpected results if the sos_data contains information > than last follow-up.
Should comorbs/outcomes be number of or first? Default it first (FALSE). No time to is calculated for noof = TRUE and type = "out".
Should duration of the comorbidity be calculated (TRUE). Default is FALSE.
If type = "out" amount of time (in days) AFTER indexdate to start counting outcomes. If type = "com" amount of time (in days) PRIOR to indexdate. Indexdate = 0, all values prior to indexdate are negative. Default is 1 ("out") and 0 ("com").
If type = "out" amount of time (in days) AFTER indexdate to be counted. Note that censdate will be adjusted to stoptime. If type = "com" amount of time (in days) PRIOR to indexdate. Indexdate = 0, all values prior to indexdate are negative. Default is any time prior to starttime is considered a comorbidity and any time after starttime is considered an outcome.
String of icd codes as a regular expression defining the outcome/comorbidity. Should start with blank space " ". Also see diakodneg.
String of procedure codes as a regular expression defining the outcome/comorbidity. Should start with blank space " ". Also see opkodneg.
String of e codes as a regular expression defining the outcome/comorbidity. Should start with blank space " ". Also see ekodneg.
Should return non-matching codes in diakod? Default is FALSE.
Should return non-matching codes in opkod? Default is FALSE.
Should return non-matching codes in ekod? Default is FALSE.
Column where diakod is found. All codes should start with blank space " ". Default is DIA_all.
Column where opkod is found. All codes should start with blank space " ". Default is OP_all.
Column where ekod is found. All codes should start with blank space " ". Default is ekod_all.
optional argument specifying the class of the comorbidities/outcomes. Allowed values are "num" (numeric: 1, 0), "char" (character: "Yes", "No"), "fac" (factor: "Yes", "No"). Default is "num".
Optional argument specifying registries used. Printed in metadatatable. Default is "NPR (in+out)".
Optional argument specifying positions used to search for outcomes/comorbidities. Printed in metadatatable.
Should warnings be printed. Default is FALSE.
dataset with column containing comorbidity/outcome. Also dataset metaout that writes directly to global enviroment with information on constructed variables.
sos_data <- prep_sosdata(sos_data, evar = "ekod")
rs_data <- create_sosvar(
sosdata = sos_data,
cohortdata = rs_data,
patid = id,
indexdate = indexdtm,
sosdate = sosdtm,
type = "com",
name = "cv1y",
diakod = " I",
stoptime = -365.25,
warnings = FALSE
)