Skip to contents

This function is useful for verifying that raw or residual phenotype risk scores of diagnosed individuals (cases) tend to be higher than scores of undiagnosed individuals (controls).

Usage

getDxStatus(
  demos,
  icdOccurrences,
  minUniqueAges = 2L,
  diseaseDxIcdMap = phers::diseaseDxIcdMap
)

Arguments

demos

A data.table having one row per person in the cohort. Must have a column person_id.

icdOccurrences

A data.table of occurrences of ICD codes for each person in the cohort. Must have columns person_id, icd, flag, and occurrence_age.

minUniqueAges

Integer indicating the minimum number of unique ICD code entry ages required to classify a person as a case. Persons with at least one, but fewer than minUniqueAges entry ages, are assigned as neither cases nor controls.

diseaseDxIcdMap

A data.table of the mapping between diseases and the corresponding ICD codes that indicate a diagnosis. Must have columns disease_id, icd, and flag. Default is diseaseDxIcdMap.

Value

A data.table with columns person_id, disease_id, and dx_status

(1 indicates a case, 0 indicates a control, -1 indicates neither).

Examples

library('data.table')


icdSample1 = merge(icdSample, demoSample[, .(person_id, dob)], by = 'person_id')
icdSample1[, occurrence_age := as.numeric((entry_date - dob)/365.25)]
#>     person_id    icd flag entry_date        dob occurrence_age
#>  1:         1    365    9 2014-03-10 1925-05-24      88.796699
#>  2:         1    366    9 2014-11-07 1925-05-24      89.459259
#>  3:         1    734    9 2014-05-28 1925-05-24      89.012989
#>  4:         1 759.82    9 2014-02-15 1925-05-24      88.733728
#>  5:         2    441    9 2011-10-10 1976-06-05      35.346012
#>  6:         2  524.0    9 2012-11-04 1976-06-05      36.416511
#>  7:         2  718.4    9 2014-10-28 1976-06-05      38.395977
#>  8:         2 759.82    9 2014-12-29 1976-06-05      38.565724
#>  9:         2 759.82    9 2015-10-03 1976-06-05      39.326847
#> 10:         3    366    9 2005-09-28 1942-07-02      63.239370
#> 11:         3    734    9 2007-03-17 1942-07-02      64.704120
#> 12:         4    441    9 2019-10-15 1986-03-22      33.566328
#> 13:         5  331.9    9 2011-03-08 1969-07-01      41.684307
#> 14:         5 362.07    9 2011-06-07 1969-07-01      41.933451
#> 15:         5 369.25    9 2011-05-06 1969-07-01      41.845840
#> 16:         5 812.10    9 2011-03-26 1969-07-01      41.733588
#> 17:         6 811.11    9 2014-04-27 2001-01-10      13.291612
#> 18:         6  958.3    9 2005-06-14 2001-01-10       4.423713
#> 19:         6  V33.1    9 2004-12-14 2001-01-10       3.925424
#> 20:         7  062.8    9 2010-10-13 1973-11-05      36.938331
#> 21:         7 607.83    9 2010-10-13 1973-11-05      36.938331
#> 22:         7 712.17    9 2010-10-13 1973-11-05      36.938331
#> 23:         7 785.52    9 2010-10-13 1973-11-05      36.938331
#> 24:         7 788.30    9 2010-10-13 1973-11-05      36.938331
#> 25:         8    077    9 2017-03-30 2009-06-02       7.824870
#> 26:         8    256    9 2017-03-01 2009-06-02       7.745473
#> 27:         9  391.1    9 2013-05-17 2001-04-29      12.049971
#> 28:         9 756.13    9 2014-05-14 2001-04-29      13.041073
#> 29:        10 711.81    9 2011-06-20 2002-01-17       9.420733
#> 30:        11 361.04    9 2016-10-03 2013-03-27       3.522563
#> 31:        11  775.9    9 2016-11-23 2013-03-27       3.662194
#> 32:        11  960.6    9 2016-10-13 2013-03-27       3.549942
#> 33:        12  480.9    9 2017-12-10 1951-03-13      66.745830
#> 34:        12  916.2    9 2017-12-10 1951-03-13      66.745830
#> 35:        12 V18.51    9 2017-12-10 1951-03-13      66.745830
#> 36:        13 534.61    9 2014-07-09 2010-11-26       3.615044
#> 37:        13  773.5    9 2016-08-27 2010-11-26       5.750567
#> 38:        14  020.5    9 2014-03-01 1980-11-03      33.321550
#> 39:        14  982.0    9 2014-03-01 1980-11-03      33.321550
#> 40:        15  031.0    9 2012-05-06 1995-03-19      17.133533
#> 41:        15 202.15    9 2012-05-06 1995-03-19      17.133533
#> 42:        15  404.1    9 2012-05-06 1995-03-19      17.133533
#> 43:        15 404.10    9 2012-05-06 1995-03-19      17.133533
#> 44:        15 758.31    9 2012-05-06 1995-03-19      17.133533
#> 45:        16 641.81    9 2015-01-13 1947-03-28      67.797530
#> 46:        16 642.00    9 2015-01-13 1947-03-28      67.797530
#> 47:        17  224.2    9 2016-12-28 1991-07-14      25.459982
#> 48:        17 296.36    9 2017-04-16 1991-07-14      25.758408
#> 49:        17  441.4    9 2016-04-13 1991-07-14      24.750879
#> 50:        17  690.8    9 2014-12-02 1991-07-14      23.387429
#> 51:        17  904.6    9 2014-10-06 1991-07-14      23.231372
#> 52:        18 363.20    9 2011-02-11 1976-05-19      34.734167
#> 53:        18 368.12    9 2011-04-08 1976-05-19      34.887487
#> 54:        18  410.5    9 2011-06-15 1976-05-19      35.073661
#> 55:        18 772.12    9 2011-06-14 1976-05-19      35.070923
#> 56:        19  110.1    9 2010-06-29 1938-02-27      72.332488
#> 57:        19 747.41    9 2008-09-28 1938-02-27      70.583001
#> 58:        19 803.44    9 2004-02-26 1938-02-27      65.994363
#> 59:        19  821.1    9 2007-11-10 1938-02-27      69.698675
#> 60:        19 952.14    9 2010-08-08 1938-02-27      72.442002
#> 61:        20  268.9    9 2018-03-07 2006-09-25      11.447654
#> 62:        20  534.2    9 2017-02-15 2006-09-25      10.393582
#> 63:        20 663.40    9 2019-07-01 2006-09-25      12.764560
#> 64:        20 755.11    9 2017-05-10 2006-09-25      10.623561
#>     person_id    icd flag entry_date        dob occurrence_age
icdSample1[, `:=`(entry_date = NULL, dob = NULL)]
#>     person_id    icd flag occurrence_age
#>  1:         1    365    9      88.796699
#>  2:         1    366    9      89.459259
#>  3:         1    734    9      89.012989
#>  4:         1 759.82    9      88.733728
#>  5:         2    441    9      35.346012
#>  6:         2  524.0    9      36.416511
#>  7:         2  718.4    9      38.395977
#>  8:         2 759.82    9      38.565724
#>  9:         2 759.82    9      39.326847
#> 10:         3    366    9      63.239370
#> 11:         3    734    9      64.704120
#> 12:         4    441    9      33.566328
#> 13:         5  331.9    9      41.684307
#> 14:         5 362.07    9      41.933451
#> 15:         5 369.25    9      41.845840
#> 16:         5 812.10    9      41.733588
#> 17:         6 811.11    9      13.291612
#> 18:         6  958.3    9       4.423713
#> 19:         6  V33.1    9       3.925424
#> 20:         7  062.8    9      36.938331
#> 21:         7 607.83    9      36.938331
#> 22:         7 712.17    9      36.938331
#> 23:         7 785.52    9      36.938331
#> 24:         7 788.30    9      36.938331
#> 25:         8    077    9       7.824870
#> 26:         8    256    9       7.745473
#> 27:         9  391.1    9      12.049971
#> 28:         9 756.13    9      13.041073
#> 29:        10 711.81    9       9.420733
#> 30:        11 361.04    9       3.522563
#> 31:        11  775.9    9       3.662194
#> 32:        11  960.6    9       3.549942
#> 33:        12  480.9    9      66.745830
#> 34:        12  916.2    9      66.745830
#> 35:        12 V18.51    9      66.745830
#> 36:        13 534.61    9       3.615044
#> 37:        13  773.5    9       5.750567
#> 38:        14  020.5    9      33.321550
#> 39:        14  982.0    9      33.321550
#> 40:        15  031.0    9      17.133533
#> 41:        15 202.15    9      17.133533
#> 42:        15  404.1    9      17.133533
#> 43:        15 404.10    9      17.133533
#> 44:        15 758.31    9      17.133533
#> 45:        16 641.81    9      67.797530
#> 46:        16 642.00    9      67.797530
#> 47:        17  224.2    9      25.459982
#> 48:        17 296.36    9      25.758408
#> 49:        17  441.4    9      24.750879
#> 50:        17  690.8    9      23.387429
#> 51:        17  904.6    9      23.231372
#> 52:        18 363.20    9      34.734167
#> 53:        18 368.12    9      34.887487
#> 54:        18  410.5    9      35.073661
#> 55:        18 772.12    9      35.070923
#> 56:        19  110.1    9      72.332488
#> 57:        19 747.41    9      70.583001
#> 58:        19 803.44    9      65.994363
#> 59:        19  821.1    9      69.698675
#> 60:        19 952.14    9      72.442002
#> 61:        20  268.9    9      11.447654
#> 62:        20  534.2    9      10.393582
#> 63:        20 663.40    9      12.764560
#> 64:        20 755.11    9      10.623561
#>     person_id    icd flag occurrence_age

dxStatus = getDxStatus(demoSample, icdSample1)