
It creates columns to indicate number of occurrences of intersection with a cohort
Source:R/addCohortIntersect.R
addCohortIntersectCount.RdIt creates columns to indicate number of occurrences of intersection with a cohort
Arguments
- x
A table containing individuals in a CDM reference.
- targetCohortTable
Name of the cohort table to intersect with.
- targetCohortId
Cohort definition IDs to include from
targetCohortTable. IfNULL, all cohorts are included.- indexDate
Name of a date column in
x, or a single date to use for all rows, used as the reference date.- censorDate
Date or name of a date column in
xon which to censor follow-up. IfNULL, no censoring is applied.- targetStartDate
Name or names of start-date columns in the target tables to use for the intersection.
- targetEndDate
Name or names of end-date columns in the target tables to use for the intersection. If
NULL, the target is treated as a point event.- window
Window or windows of time relative to
indexDateto consider.- nameStyle
Naming pattern for the added column or columns. It should include the required formatting variables. If more than one
tableNameis provided, it must include{table_name}.- name
Name of the new table. If
NULL, a temporary table is returned.- type
Type of the created column(s). Counts, days, age, and observation durations can be
"numeric"or"integer". Flag columns can also be"logical". Field columns can use"auto"to preserve the source type, or can be converted to"numeric","integer","logical", or"character".
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"
)
#> # A query: ?? x 7
#> # Database: DuckDB 1.5.4 [unknown@Linux 6.17.0-1020-azure:R 4.6.1/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <int> <date> <date>
#> 1 2 4 1938-11-03 1966-06-19
#> 2 3 2 1923-07-17 1924-01-01
#> 3 3 7 1966-03-26 1967-01-07
#> 4 2 1 1958-04-21 1968-10-23
#> 5 2 9 1977-08-20 1988-09-27
#> 6 2 8 1915-01-05 1923-04-25
#> 7 1 5 1960-09-16 1966-09-28
#> 8 1 3 1918-04-15 1918-08-16
#> 9 2 10 1952-11-28 1955-02-05
#> 10 2 6 1949-05-21 1956-02-25
#> # ℹ 3 more variables: cohort_2_0_to_inf <dbl>, cohort_1_0_to_inf <dbl>,
#> # cohort_3_0_to_inf <dbl>
# }