Skip to contents

It creates columns to indicate number of occurrences of intersection with a cohort

Usage

addCohortIntersectCount(
  x,
  targetCohortTable,
  targetCohortId = NULL,
  indexDate = "cohort_start_date",
  censorDate = NULL,
  targetStartDate = "cohort_start_date",
  targetEndDate = "cohort_end_date",
  window = list(c(0, Inf)),
  nameStyle = "{cohort_name}_{window_name}",
  name = NULL
)

Arguments

x

Table with individuals in the cdm.

targetCohortTable

name of the cohort that we want to check for overlap.

targetCohortId

vector of cohort definition ids to include.

indexDate

Variable in x that contains the date to compute the intersection.

censorDate

whether to censor overlap events at a specific date or a column date of x.

targetStartDate

date of reference in cohort table, either for start (in overlap) or on its own (for incidence).

targetEndDate

date of reference in cohort table, either for end (overlap) or NULL (if incidence).

window

window to consider events of.

nameStyle

naming of the added column or columns, should include required parameters.

name

Name of the new table, if NULL a temporary table is returned.

Value

The original table (x) with one added column per intersection with the desired cohort in a specific window. One column will be created for each combination of window and cohort. The value of the column will be the number of intersections in the desired window, or NA if the individual is not in observation at any time in the window.

Examples

# \donttest{
library(PatientProfiles)

cdm <- mockPatientProfiles(source = "duckdb")

cdm$cohort1 |>
  addCohortIntersectCount(
    targetCohortTable = "cohort2"
  )
#> # Source:   table<og_006_1775495232> [?? x 7]
#> # Database: DuckDB 1.5.1 [unknown@Linux 6.17.0-1008-azure:R 4.5.3/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    3          3 1920-11-02        1946-05-23     
#>  2                    1          1 1965-09-24        1983-04-19     
#>  3                    2         10 1946-07-31        1946-11-17     
#>  4                    3          2 1952-01-03        1966-09-11     
#>  5                    1          6 1925-12-31        1930-02-14     
#>  6                    2          7 1945-05-23        1947-04-28     
#>  7                    1          9 1975-04-06        1996-03-13     
#>  8                    2          5 1992-08-17        1994-06-07     
#>  9                    2          8 1928-12-07        1931-11-13     
#> 10                    2          4 1928-01-04        1928-08-15     
#> # ℹ 3 more variables: cohort_1_0_to_inf <dbl>, cohort_3_0_to_inf <dbl>,
#> #   cohort_2_0_to_inf <dbl>

# }