[Stable]

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
)

Arguments

type

Possible values are "out" and "com". Is the resulting variable an outcome (and time to is calculated) or comorbidity?

name

Name of resulting variable (prefix sos_out_ is added to outcome and sos_com_ to comorbidity).

sosdata

Data where DIA, OP, Ekod variables are found.

cohortdata

Data containing the cohort with at least columns patid and indexdate.

patid

Patient identifier. Default is lopnr.

indexdate

Index date for the patient (usually date of admission or discharge entered into SwedeHF). Default is indexdtm.

add_unique

If patid and indexdate are not unique in cohortdata, this identifies unique posts.

sosdate

Date of incident (comorbidity or outcome) in sosdata. Default is sosdtm.

censdate

Vector of dates. Only applicable for type = "out". Outcomes are allowed up until this day (usually date of death or end follow-up).

allowedcenslimit

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.

noof

Should comorbs/outcomes be number of or first? Default it first (FALSE). No time to is calculated for noof = TRUE and type = "out".

comduration

Should duration of the comorbidity be calculated (TRUE). Default is FALSE.

starttime

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").

stoptime

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.

diakod

String of icd codes as a regular expression defining the outcome/comorbidity. Should start with blank space " ". Also see diakodneg.

opkod

String of procedure codes as a regular expression defining the outcome/comorbidity. Should start with blank space " ". Also see opkodneg.

ekod

String of e codes as a regular expression defining the outcome/comorbidity. Should start with blank space " ". Also see ekodneg.

diakodneg

Should return non-matching codes in diakod? Default is FALSE.

opkodneg

Should return non-matching codes in opkod? Default is FALSE.

ekodneg

Should return non-matching codes in ekod? Default is FALSE.

diavar

Column where diakod is found. All codes should start with blank space " ". Default is DIA_all.

opvar

Column where opkod is found. All codes should start with blank space " ". Default is OP_all.

evar

Column where ekod is found. All codes should start with blank space " ". Default is ekod_all.

valsclass

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".

meta_reg

Optional argument specifying registries used. Printed in metadatatable. Default is "NPR (in+out)".

meta_pos

Optional argument specifying positions used to search for outcomes/comorbidities. Printed in metadatatable.

warnings

Should warnings be printed. Default is FALSE.

Value

dataset with column containing comorbidity/outcome. Also dataset metaout that writes directly to global enviroment with information on constructed variables.

Examples


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
)