{"id":19140141,"url":"https://github.com/feakster/qdiabetes","last_synced_at":"2025-05-06T23:16:20.565Z","repository":{"id":39668467,"uuid":"231418641","full_name":"Feakster/qdiabetes","owner":"Feakster","description":"R package using the algorithms of ClinRisk to calculate the risk of developing type 2 diabetes.","archived":false,"fork":false,"pushed_at":"2021-03-26T13:16:57.000Z","size":4422,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-06T23:16:13.436Z","etag":null,"topics":["clinrisk","diabetes","diabetes-prediction","diabetes-risk","diabetes-risk-prediction","package","prognostic","qdiabetes-algorithm","qtools","r","r-package","risk"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Feakster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-02T16:25:04.000Z","updated_at":"2024-11-23T01:20:47.000Z","dependencies_parsed_at":"2022-08-21T01:10:10.224Z","dependency_job_id":null,"html_url":"https://github.com/Feakster/qdiabetes","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Feakster%2Fqdiabetes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Feakster%2Fqdiabetes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Feakster%2Fqdiabetes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Feakster%2Fqdiabetes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Feakster","download_url":"https://codeload.github.com/Feakster/qdiabetes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252782835,"owners_count":21803410,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clinrisk","diabetes","diabetes-prediction","diabetes-risk","diabetes-risk-prediction","package","prognostic","qdiabetes-algorithm","qtools","r","r-package","risk"],"created_at":"2024-11-09T07:16:30.264Z","updated_at":"2025-05-06T23:16:20.541Z","avatar_url":"https://github.com/Feakster.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# QDiabetes \u003cimg src=\"man/figures/logo.png\" height=\"139px\" align=\"right\" /\u003e\n\n\u003c!-- Badges --\u003e\n[![license](https://img.shields.io/badge/license-AGPL--3-blue)](https://choosealicense.com/licenses/agpl-3.0/)\n[![platform-support](https://img.shields.io/badge/R-%3E%3D2.10-blue)](https://www.r-project.org/)\n[![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable)\n[![github-workflow](https://github.com/Feakster/qdiabetes/workflows/R-CMD-check/badge.svg)](https://github.com/Feakster/qdiabetes/actions)\n\u003c!--[![CRANstatus](https://www.r-pkg.org/badges/version/qdiabetes)](https://cran.r-project.org/package=qdiabetes)--\u003e\n\u003c!--[![CRANdownloads](https://cranlogs.r-pkg.org/badges/grand-total/qdiabetes)](https://cran.r-project.org/package=qdiabetes)--\u003e\n\n## General info\n\nThis project is an R package for calculating the risk of developing type 2 diabetes. The package uses R implementations of the QDiabetes algorithms, which were initially derived by [ClinRisk](https://clinrisk.co.uk/ClinRisk/Welcome.html) using the C++ programming language. The QDiabetes package comprises QDiabetes-2013 and [QDiabetes-2018](https://qdiabetes.org/), although older (and eventually more recent) versions of QDiabetes may be included in future releases.\n\n## Disclaimer\n\nClinRisk do not support of endorse this code. End users should see the original C++ source as the \u0026lsquo;gold standard\u0026rsquo; open source implementation. Please note that the _QDiabetes_ R package has been created as a research tool for scientific purposes only. The _QDiabetes_ R package has not been granted Medicines and Healthcare products Regulatory Agency (MHRA) approval as a medical device, and hence, should not be used as part of any individualised risk assessment.\n\n## History\n\nThe first QDiabetes algorithm (termed \u0026ldquo;QDScore\u0026rdquo; at the time) was published in 2009\u003csup\u003e[1](#ref1)\u003c/sup\u003e. In 2011, two substantial changes were made, whereby the age range permissible by the algorithm was expanded from 25\u0026ndash;79 to 25\u0026ndash;84, and the smoking status variable was expanded from two levels [current smoker and non-smoker] to five levels [non-smoker, ex-smoker, light smoker (1\u0026ndash;9/day), moderate smoker (10\u0026ndash;19/day) and heavy smoker (\u0026ge;20/day)]. In 2012, QDiabetes-2013 was released, and from 2013 to 2016 the algorithm coefficients were periodically updated, until 2017, when the more expansive QDiabetes-2018 algorithm was published\u003csup\u003e[2](#ref2)\u003c/sup\u003e. At some point along the way, QDiabetes switched from sourcing Townsend deprivation data from the 2001 to the 2011 UK Census, however, the point at which this occurred is not clear. For now, all the can be said for certain is that the original 2009 QDScore algorithm used Townsend data from the 2001 UK Census, while QDiabetes-2018 uses Townsend data from the 2011 UK Census. More details about the variables used in QDiabetes-2013 and QDiabetes-2018 can be found in the following sections.\n\n## QDiabetes-2013\n\nThe QDiabetes-2013 algorithm consists of two separate risk prediction models (one per gender), in which the following 11 variables are used to calculate risk:\n\n* **Gender** [`sex`]\n    - Female \u0026mdash; `\"Female\"`\n    - Male \u0026mdash; `\"Male\"`\n* **Age** [`age`], in years\n* **Body mass index** [`bmi`], in kg/m\u003csup\u003e2\u003c/sup\u003e\n* **Ethnicity** [`ethn`], nine categories:\n    - White or not stated \u0026mdash; `\"WhiteNA\"`\n    - Indian \u0026mdash; `\"Indian\"`\n    - Pakistani \u0026mdash; `\"Pakistani\"`\n    - Bangladeshi \u0026mdash; `\"Bangladeshi\"`\n    - Black Caribbean \u0026mdash; `\"BlackCaribbean\"`\n    - Black African \u0026mdash; `\"BlackAfrican\"`\n    - Chinese \u0026mdash; `\"Chinese\"`\n    - Other Asian \u0026mdash; `\"OtherAsian\"`\n    - Other ethnic group \u0026mdash; `\"Other\"`\n* **Smoking status** [`smoke`], five levels:\n    - Non-smoker \u0026mdash; `\"Non\"`\n    - Ex-smoker \u0026mdash; `\"Ex\"`\n    - Light smoker (1\u0026ndash;9/day) \u0026mdash; `\"Light\"`\n    - Moderate smoker (10\u0026ndash;19/day) \u0026mdash; `\"Moderate\"`\n    - Heavy smoker (\u0026ge;20/day) \u0026mdash; `\"Heavy\"`\n* **Deprivation** [`tds`], as measured by Townsend scores, where higher values indicate higher levels of deprivation\n* **Family history of diabetes in first degree relative** [`fhdm`]\n* **History of treated hypertension** [`htn`], being diagnosis of hypertension and treatment with at least one hypertensive drug\n* **History of cardiovascular disease** [`cvd`], defined as: ischaemic heart disease, stroke, or transient ischaemic attack\n* **History of use of corticosteroids** [`ster`] listed in British National Formulary chapter 6.3.2, including oral or injections of systemic: [prednisolone](https://en.wikipedia.org/wiki/Prednisolone), [betamethasone](https://en.wikipedia.org/wiki/Betamethasone), [cortisone](https://en.wikipedia.org/wiki/Cortisone), depo-medrone, [dexamethasone](https://en.wikipedia.org/wiki/Dexamethasone), [deflazacort](https://en.wikipedia.org/wiki/Deflazacort), efcortesol, [hydrocortisone](https://en.wikipedia.org/wiki/Hydrocortisone), [methylprednisolone](https://en.wikipedia.org/wiki/Methylprednisolone), or [triamcinolone](https://en.wikipedia.org/wiki/Triamcinolone)\n* **Survival time** [`surv`], being the time period over which risk of developing type-2 diabetes is to be calculated.\n\nThe QDiabetes-2013 algorithm is implemented within the `QDR2013()` function of the _QDiabetes_ package.\n\n## QDiabetes-2018\n\nThe QDiabetes-2018 algorithm is actually six separate risk predictions models (three sub-models, subdivided by gender).\n\n### Model A\n\nThe basic (core) model, \u0026lsquo;model A\u0026rsquo;, uses the same risk predictors as QDiabetes-2013, with the omission of the **Survival time** variable (in favour of a fixed 10-year survival window), and the addition of the following 6 variables:\n\n* _**History of gestational diabetes**_ [`gdm`] _(women only)_\n* _**History of polycystic ovary syndrome**_ [`pcos`] _(women only)_\n* **History of learning disabilities** [`learn`]\n* **History of schizophrenia or bipolar affective disorder** [`psy`]\n* **History of use of statins** [`stat`]\n* **History of use of second generation \"atypical\" antipsychotics** [`apsy`], including: [amisulpride](https://en.wikipedia.org/wiki/Amisulpride), [aripiprazole](https://en.wikipedia.org/wiki/Aripiprazole), [clozapine](https://en.wikipedia.org/wiki/Clozapine), [lurasidone](https://en.wikipedia.org/wiki/Lurasidone), [olanzapine](https://en.wikipedia.org/wiki/Olanzapine), [paliperidone](https://en.wikipedia.org/wiki/Paliperidone), [quetiapine](https://en.wikipedia.org/wiki/Quetiapine), [risperidone](https://en.wikipedia.org/wiki/Risperidone), [sertindole](https://en.wikipedia.org/wiki/Sertindole), and [zotepine](https://en.wikipedia.org/wiki/Zotepine)\n\nModel A of the QDiabetes-2018 algorithm is implemented within the `QDR2018A()` function of the _QDiabetes_ package.\n\n### Model B\n\n\u0026lsquo;Model B\u0026rsquo;, uses the same variables as model A, with the addition of:\n\n* **Fasting plasma glucose level** [`fpg`], in mmol/L\n\nModel B of the QDiabetes-2018 algorithm is implemented within the `QDR2018B()` function of the _QDiabetes_ package.\n\n### Model C\n\n\u0026lsquo;Model C\u0026rsquo;, uses the same variables as model A, with the addition of:\n\n* **Glycated haemoglobin A\u003csub\u003e1c\u003c/sub\u003e value** [`hba1c`], in mmol/mol\n\nModel C of the QDiabetes-2018 algorithm is implemented within the `QDR2018C()` function of the _QDiabetes_ package.\n\n## Installation\n\nYou can install the released version of _QDiabetes_ from [CRAN](https://cran.r-project.org/web/packages/QDiabetes/index.html) with:\n\n```r\ninstall.packages(\"QDiabetes\")\n```\n\nAlternatively, the development version may be installed from [GitHub](https://github.com/Feakster/qdiabetes) with:\n\n```r\nif (!{\"remotes\" %in% installed.packages()}) install.packages(\"remotes\")\nremotes::install_github(\"Feakster/qdiabetes\")\n```\n\n## Package ethos\n\nIn building this package, we wanted to make something that was simple to write and easy to maintain ([KISS principles](https://en.wikipedia.org/wiki/KISS_principle)), performant, but compatible with the latest and older versions of R. With this in mind, we have written this package to be as faithful to R\u0026rsquo;s core language as possible, using minimal dependencies. Hence, you will not find any _Rcpp_ here. Instead, all functions have been written entirely in _base_ R; the only exception being the `getTDS()` function, which uses the `median()` function from the _stats_ package (although we may re-write this at some point). All other packages listed under \u0026ldquo;Suggests\u0026rdquo; in the DESCRIPTION file only serve to illustrate the use of _QDiabetes_ in examples or vignettes, or in testing the package. The primary factor limiting the package\u0026rsquo;s compatibility with older versions of R is the data storage method CRAN require us to use for the data frame backend of the `getTDS()` function. Owing to the memory footprint of this object (\u0026asymp;200MB), we need to make use of XZ compression to reduce the overall size of the package as much as possible. XZ compression was first implemented in [R version 2.10](https://cran-archive.r-project.org/bin/windows/base/old/2.10.0/NEWS.R-2.10.0).\n\n## Note\n\nMany of the default values used in the risk prediction functions of this package were selected to be representative of a UK population. These values are only intended to minimise the amount of typing required when using the risk prediction functions in an exploratory manner. They are unlikely to be useful in a research setting, and you would need to know the exact values to assign to all function parameters in order to make an accurate risk prediction. Hence, while you can get risk predictions from the `QDR2013()` and `QDR2018A()` functions through the specification of only `sex`, `age`, and `bmi`, you would be assuming White or missing ethnicity, non-smoking status, a Townsend deprivation score of 0, and the complete absence of any relevant medical history/conditions and concomitant drug therapies. In the case of `QDR2013()`, you would also be assuming that a 10-year risk window is desired.\n\n## Examples\n\nBelow are some very simple examples using the _QDiabetes_ package. Note that for convenience, either BMI [`bmi`] or height [`ht`] and weight [`wt`] may be specified in any of the risk prediction functions in this package.\n\nIn the interest of making life a little easier, a `getTDS()` helper function has been added to the package, which uses a lookup table to obtain Townsend deprivation scores from full or partial UK postcodes.\n\n```r\n### Load Package Namespace ###\nlibrary(QDiabetes)\n\n### Simple Usage ###\nQDR2013(sex = \"Female\", age = 35, bmi = 25)\n# [1] 0.6324508\nQDR2018A(sex = \"Male\", age = 45, bmi = 35)\n# [1] 9.88593\nQDR2018B(sex = \"Female\", age = 65, bmi = 30, fpg = 6)\n# [1] 18.43691\nQDR2018C(sex = \"Male\", age = 25, bmi = 40, hba1c = 42)\n# [1] 8.226301\n\n### Making Use of the getTDS() Helper Function ###\ngetTDS(\"OX2 6GG\")\n# [1] 2.022583\nQDR2013(sex = \"Female\", age = 41, ht = 1.65, wt = 60, tds = getTDS(\"OX3 9DU\"))\n# [1] 0.5004499\nQDR2018A(sex = \"Male\", age = 33, bmi = 26, tds = getTDS(\"OX3 7LF\"))\n# [1] 0.6472644\n\n### Making Use of Vectorisation ###\ngetTDS(c(\"OX3 7LF\", \"OX2 6NW\", \"OX2 6GG\", \"OX1 4AR\"))\n#    OX37LF    OX26NW    OX26GG    OX14AR\n# -1.032394  1.640422  2.022583  2.309777\nQDR2013(sex = \"Female\", age = 35, bmi = seq(20, 40, 5))\n#        20        25        30        35        40\n# 0.1801226 0.6324508 1.7885233 3.8983187 6.2964702\nQDR2018A(sex = \"Female\", age = seq(25, 75, 10), bmi = 35)\n#       25        35        45        55        65        75\n# 1.085179  2.921454  5.893499  9.082108 10.713717  9.567516\nQDR2018B(sex = \"Male\", age = 65, bmi = 35, fpg = 2:6)\n#         2          3          4          5          6\n# 0.9123063  0.5911511  1.8416081  7.8554831 30.8096968\nQDR2018C(sex = \"Female\", age = 80, bmi = 28, hba1c = seq(15, 45, 5))\n#          15           20           25           30           35           40           45\n# 0.008084487  0.033019655  0.121238952  0.412396004  1.320727239  4.005759509 11.409509026\n\n### Data Frame Usage ###\ndata(dat_qdr) # Synthetic sample data\n\n## Using base R ##\ndat_qdr[[\"risk\"]] \u003c- with(dat_qdr, QDR2013(sex = sex,\n                                           age = age,\n                                           ht = ht,\n                                           wt = wt,\n                                           ethn = ethn,\n                                           smoke = smoke,\n                                           tds = tds,\n                                           htn = htn,\n                                           cvd = cvd,\n                                           ster = ster))\n\n## Using dplyr ##\nlibrary(dplyr)\ndf_qdr \u003c- as_tibble(dat_qdr)\ndf_qdr \u003c- df_qdr %\u003e%\n  mutate(risk = QDR2013(sex = sex,\n                        age = age,\n                        ht = ht,\n                        wt = wt,\n                        ethn = ethn,\n                        smoke = smoke,\n                        tds = tds,\n                        htn = htn,\n                        cvd = cvd,\n                        ster = ster))\n\n## Using data.table ##\nlibrary(data.table)\ndt_qdr \u003c- as.data.table(dat_qdr)\ndt_qdr[, risk := QDR2013(sex = sex,\n                         age = age,\n                         ht = ht,\n                         wt = wt,\n                         ethn = ethn,\n                         smoke = smoke,\n                         tds = tds,\n                         htn = htn,\n                         cvd = cvd,\n                         ster = ster)]\n```\n\n## Known issues\n\nSee [Issues](https://github.com/Feakster/qdiabetes/issues) on the QDiabetes GitHub repository.\n\n## Similar packages\n\n* [QRISK3](https://github.com/YanLiUK/QRISK3): An R implementation of ClinRisk\u0026rsquo;s [QRISK3](https://www.qrisk.org/three/) risk prediction algorithms.\n\n## Funding\n\nThis project was funded by the National Institute for Health Research (NIHR) School for Primary Care Research (SPCR) [project number: [412](https://www.spcr.nihr.ac.uk/projects/412-quantifying-the-risk-of-type-2-diabetes-across-the-uk)]. The views expressed are those of the author(s) and not necessarily those of the NIHR or the Department of Health and Social Care.\n\n\u003cimg src=\"man/figures/nihr-logo.png\" height=\"40px\" align=\"float:left\" /\u003e\n\n## References\n\n\u003ca name=\"ref1\"\u003e1\u003c/a\u003e: [Hippisley-Cox J, Coupland C, Robson J, Sheikh A \u0026 Brindle P. (2009). Predicting risk of type 2 diabetes in England and Wales: prospective derivation and validation of QDScore. _BMJ_ **338**, b880](https://doi.org/10.1136/bmj.b880)\n\n\u003ca name=\"ref2\"\u003e2\u003c/a\u003e: [Hippisley-Cox J \u0026 Coupland C. (2017). Development and validation of QDiabetes-2018 risk prediction algorithm to estimate future risk of type 2 diabetes: cohort study. _BMJ_ **359**, j5019](https://doi.org/10.1136/bmj.j5019)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeakster%2Fqdiabetes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeakster%2Fqdiabetes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeakster%2Fqdiabetes/lists"}