OSCR

Multimodal MRI marker of cognition explains the association between cognition and mental health in the UK Biobank.

Code ↔ Paper

18 matches between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 18 matches
  1. [1] § Materials and methods › Brain MRI › Diffusion-weighted MRI (dwMRI) ↔ 3_MRI_preprocessing/01_GetMRIData_dwMRI_IDP.ipynb, lines 1399–1506 · score 0.89 · free water volume, diffusion tensor fitting, diffusion tensor mode, orientation dispersion, volume fraction, head motion
  2. [2] § Materials and methods › Brain MRI › MRI confounds ↔ 3_MRI_preprocessing/01_GetMRIData_dwMRI_IDP.ipynb, lines 1399–1506 · score 0.86 · median absolute, acquisition date, brain position, head motion, volumetric scaling, intensity scaling
  3. [3] § Materials and methods › Brain MRI › MRI confounds ↔ 3_MRI_preprocessing/04_GetMRIData_rsMRI_IDP_FullPartCorr_Confounds.ipynb, lines 1129–1315 · score 0.86 · median absolute, acquisition date, head motion, volumetric scaling, intensity scaling, UK Biobank
  4. [4] § Materials and methods › Brain MRI › Structural MRI (sMRI) ↔ 3_MRI_preprocessing/03_GetMRIData_sMRI.ipynb, lines 16–48 · score 0.85 · a2009s, FreeSurfer ASEG, FreeSurfer Desikan, subcortical volumes, matter volumes, brain volume
  5. [5] § Materials and methods › Mental health ↔ 2_Mental_Health/01_GetMHData.ipynb, lines 1847–1989 · score 0.81 · nervous system, mental distress, Mental health, addictions, bipolar, mania
  6. [6] § Materials and methods › Data › Cognition › Transformations of cognitive scores ↔ 1_Cognitive_preprocessing/04_GetGFactor_SingleSplit.Rmd, lines 33–47 · score 0.79 · incorrect matches, Prospective Memory, Pairs Matching, complete numeric, Reaction, log
  7. [7] § Materials and methods › Data › Cognition › Transformations of cognitive scores ↔ 1_Cognitive_preprocessing/02_CogData_Descriptive_5Folds.ipynb, lines 23–34 · score 0.78 · incorrect matches, Prospective Memory, Pairs Matching, complete numeric, Reaction, log
  8. [8] § Materials and methods › Mental health › Description of composite measures ↔ 2_Mental_Health/01_GetMHData.ipynb, lines 1847–1989 · score 0.77 · Hazardous alcohol, drinking alcohol, Alcohol dependence, moderate, AUDIT, log
  9. [9] § Materials and methods › Brain MRI › Diffusion-weighted MRI (dwMRI) ↔ 3_MRI_preprocessing/01_GetMRIData_dwMRI_IDP.ipynb, lines 1384–1397 · score 0.65 · FA skeleton, tracts common, white matter tracts, DTI, TBSS, voxel
  10. [10] § Materials and methods › Mental health › Description of composite measures ↔ 4_PLS/02_1_PLS_MH_SingleSplit.ipynb, lines 199–296 · score 0.64 · recurrent depression, depression triggered, GAD, loss, lifetime, harm
  11. [11] § Materials and methods › Data › Cognition › Transformations of cognitive scores ↔ 1_Cognitive_preprocessing/03_GetGFactor_5Folds.Rmd, lines 268–296 · score 0.62 · Fluid Intelligence score, Picture Vocabulary, trail, cognitive
  12. [12] § Materials and methods › Data › Cognition › Transformations of cognitive scores ↔ 1_Cognitive_preprocessing/04_GetGFactor_SingleSplit.Rmd, lines 92–115 · score 0.62 · Fluid Intelligence score, Picture Vocabulary, trail, cognitive
  13. [13] § Materials and methods › Data analysis › Machine learning ↔ 4_PLS/02_1_PLS_MH_SingleSplit.ipynb, lines 661–713 · score 0.59 · absolute error, squared error, MSE, MAE, R2, Pearson
  14. [14] § Materials and methods › Data analysis › Machine learning ↔ 4_PLS/01_PLS_MH_5Folds.ipynb, lines 74–137 · score 0.59 · absolute error, squared error, MSE, MAE, R2, fold
  15. [15] § Materials and methods › Mental health › Description of composite measures ↔ 2_Mental_Health/01_GetMHData.ipynb, lines 1475–1509 · score 0.57 · Probable Depression Status, PDS, Anxiety, Health, scores
  16. [16] § Results › Predictive modeling › Mental health ↔ 2_Mental_Health/01_GetMHData.ipynb, lines 1548–1691 · score 0.55 · mental distress, mental health, wellbeing, cannabis, happiness, unusual
  17. [17] § Materials and methods › Feature importance ↔ 4_PLS/01_PLS_MH_5Folds.ipynb, lines 190–232 · score 0.51 · Pearson correlations, predicting cognition, mental health, fold, transformation
  18. [18] § Materials and methods › Brain MRI › Resting-state functional MRI (rsMRI) ↔ 3_MRI_preprocessing/04_GetMRIData_rsMRI_IDP_FullPartCorr_Confounds.ipynb, lines 1400–1462 · score 0.50 · intensity scaling, artefact, echo, temporal, motion, Preprocessing

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Jupyter notebook · 1,989 lines · 81 KB · MIT · 4 matches

  1. # %%
  2. import pandas as pd
  3. import ukbiobank.utils.utils
  4. from ukbiobank.utils import loadCsv
  5. from ukbiobank.utils import addFields
  6. from ukbiobank.utils.utils import fieldIdsToNames
  7. import matplotlib.pyplot as plt
  8. import numpy as np
  9. # %%
  10. csv_path = '/UK_BB/ukbbdata/ukbb_oct23/ukb.csv'
  11. ukb = ukbiobank.ukbio(ukb_csv=csv_path)
  12. # %%
  13. # Diagnoses main ICD10
  14. diagnoses_df = ukbiobank.utils.utils.loadCsv(ukbio=ukb, fields=['eid', 41202])
  15. diagnoses_main_ukb = addFields(ukbio=ukb, df=diagnoses_df, fields=['eid', 41202])
  16. diagnoses_main_icd = ukbiobank.utils.utils.fieldIdsToNames(ukbio=ukb, df=diagnoses_main_ukb)
  17. diagnoses_main_icd.to_csv('/UK_BB/diagnoses/diagnoses_main_icd[ukb].csv', index=False)
  18. # %%
  19. # Diagnoses ICD10
  20. diagnoses_df = ukbiobank.utils.utils.loadCsv(ukbio=ukb, fields=['eid', 41270])
  21. diagnoses_ukb = addFields(ukbio=ukb, df=diagnoses_df, fields=['eid', 41270])
  22. diagnoses_icd = ukbiobank.utils.utils.fieldIdsToNames(ukbio=ukb, df=diagnoses_ukb)
  23. diagnoses_icd.to_csv('/UK_BB/diagnoses/diagnoses_icd.csv', index=False)
  24. # %%
  25. # Mental Health Instance 2 and Online
  26. # Instance 2
  27. dfmh_2 = ukbiobank.utils.utils.loadCsv(ukbio=ukb, fields=['eid',
  28. 20002,
  29. 20126,
  30. 20122,
  31. 20127,
  32. 20124,
  33. 20125,
  34. 20123,
  35. 1920,
  36. 1930,
  37. 1940,
  38. 1950,
  39. 1960,
  40. 1970,
  41. 1980,
  42. 1990,
  43. 2000,
  44. 2010,
  45. 2020,
  46. 2030,
  47. 2040,
  48. 4526,
  49. 4537,
  50. 4548,
  51. 4559,
  52. 4570,
  53. 4581,
  54. 2050,
  55. 2060,
  56. 2070,
  57. 2080,
  58. 2090,
  59. 2100,
  60. 4598,
  61. 4609,
  62. 4620,
  63. 4631,
  64. 5375,
  65. 5386,
  66. 4642,
  67. 4653,
  68. 6156,
  69. 5663,
  70. 5674,
  71. 6145,
  72. 1031,
  73. 6160,
  74. 2110,
  75. 1031,
  76. 6160,
  77. 2110], instance=2)
  78. # Online
  79. dfmh_online = ukbiobank.utils.utils.loadCsv(ukbio=ukb, fields=['eid',
  80. 20002,
  81. 20499,
  82. 20500,
  83. 20544,
  84. 20446,
  85. 20441,
  86. 20547,
  87. 20433,
  88. 20434,
  89. 20445,
  90. 20447,
  91. 20532,
  92. 20435,
  93. 20438,
  94. 20449,
  95. 20450,
  96. 20436,
  97. 20439,
  98. 20440,
  99. 20442,
  100. 20448,
  101. 20518,
  102. 20510,
  103. 20507,
  104. 20519,
  105. 20514,
  106. 20511,
  107. 20513,
  108. 20508,
  109. 20534,
  110. 20546,
  111. 20437,
  112. 20533,
  113. 20517,
  114. 20535,
  115. 20536,
  116. 20502,
  117. 20501,
  118. 20492,
  119. 20548,
  120. 20493,
  121. 20550,
  122. 20419,
  123. 20541,
  124. 20429,
  125. 20421,
  126. 20425,
  127. 20537,
  128. 20539,
  129. 20427,
  130. 20418,
  131. 20423,
  132. 20420,
  133. 20422,
  134. 20540,
  135. 20543,
  136. 20428,
  137. 20505,
  138. 20512,
  139. 20506,
  140. 20509,
  141. 20516,
  142. 20515,
  143. 20520,
  144. 20426,
  145. 20542,
  146. 20549,
  147. 20417,
  148. 20538,
  149. 20552,
  150. 20431,
  151. 20406,
  152. 20401,
  153. 20456,
  154. 20457,
  155. 20503,
  156. 20504,
  157. 20551,
  158. 20404,
  159. 20415,
  160. 20432,
  161. 20414,
  162. 20403,
  163. 20416,
  164. 20413,
  165. 20407,
  166. 20412,
  167. 20409,
  168. 20408,
  169. 20411,
  170. 20405,
  171. 20410,
  172. 20455,
  173. 20453,
  174. 20454,
  175. 20461,
  176. 20462,
  177. 20468,
  178. 20474,
  179. 20463,
  180. 20466,
  181. 20471,
  182. 20477,
  183. 20467,
  184. 20470,
  185. 20476,
  186. 20465,
  187. 20473,
  188. 20489,
  189. 20488,
  190. 20487,
  191. 20490,
  192. 20491,
  193. 20522,
  194. 20523,
  195. 20521,
  196. 20524,
  197. 20525,
  198. 20531,
  199. 20529,
  200. 20526,
  201. 20530,
  202. 20528,
  203. 20527,
  204. 20497,
  205. 20498,
  206. 20495,
  207. 20496,
  208. 20494,
  209. 20479,
  210. 20485,
  211. 20486,
  212. 20480,
  213. 20482,
  214. 20481,
  215. 20553,
  216. 20554,
  217. 20483,
  218. 20484,
  219. 20458,
  220. 20459,
  221. 20460,
  222. 1031,
  223. 6160,
  224. 2110
  225. ])
  226. # %%
  227. # Add fields
  228. # Instance 2
  229. mh_i2 = addFields(ukbio=ukb, df=dfmh_2, fields=['eid',
  230. 20002,
  231. 20126,
  232. 20122,
  233. 20127,
  234. 20124,
  235. 20125,
  236. 20123,
  237. 1920,
  238. 1930,
  239. 1940,
  240. 1950,
  241. 1960,
  242. 1970,
  243. 1980,
  244. 1990,
  245. 2000,
  246. 2010,
  247. 2020,
  248. 2030,
  249. 2040,
  250. 4526,
  251. 4537,
  252. 4548,
  253. 4559,
  254. 4570,
  255. 4581,
  256. 2050,
  257. 2060,
  258. 2070,
  259. 2080,
  260. 2090,
  261. 2100,
  262. 4598,
  263. 4609,
  264. 4620,
  265. 4631,
  266. 5375,
  267. 5386,
  268. 4642,
  269. 4653,
  270. 6156,
  271. 5663,
  272. 5674,
  273. 6145,
  274. 1031,
  275. 6160,
  276. 2110,
  277. 1031,
  278. 6160,
  279. 2110], instances=2)
  280. # Online
  281. mh_online = addFields(ukbio=ukb, df=dfmh_online, fields=['eid',
  282. 20002,
  283. 20499,
  284. 20500,
  285. 20544,
  286. 20446,
  287. 20441,
  288. 20547,
  289. 20433,
  290. 20434,
  291. 20445,
  292. 20447,
  293. 20532,
  294. 20435,
  295. 20438,
  296. 20449,
  297. 20450,
  298. 20436,
  299. 20439,
  300. 20440,
  301. 20442,
  302. 20448,
  303. 20518,
  304. 20510,
  305. 20507,
  306. 20519,
  307. 20514,
  308. 20511,
  309. 20513,
  310. 20508,
  311. 20534,
  312. 20546,
  313. 20437,
  314. 20533,
  315. 20517,
  316. 20535,
  317. 20536,
  318. 20502,
  319. 20501,
  320. 20492,
  321. 20548,
  322. 20493,
  323. 20550,
  324. 20419,
  325. 20541,
  326. 20429,
  327. 20421,
  328. 20425,
  329. 20537,
  330. 20539,
  331. 20427,
  332. 20418,
  333. 20423,
  334. 20420,
  335. 20422,
  336. 20540,
  337. 20543,
  338. 20428,
  339. 20505,
  340. 20512,
  341. 20506,
  342. 20509,
  343. 20516,
  344. 20515,
  345. 20520,
  346. 20426,
  347. 20542,
  348. 20549,
  349. 20417,
  350. 20538,
  351. 20552,
  352. 20431,
  353. 20406,
  354. 20401,
  355. 20456,
  356. 20457,
  357. 20503,
  358. 20504,
  359. 20551,
  360. 20404,
  361. 20415,
  362. 20432,
  363. 20414,
  364. 20403,
  365. 20416,
  366. 20413,
  367. 20407,
  368. 20412,
  369. 20409,
  370. 20408,
  371. 20411,
  372. 20405,
  373. 20410,
  374. 20455,
  375. 20453,
  376. 20454,
  377. 20461,
  378. 20462,
  379. 20468,
  380. 20474,
  381. 20463,
  382. 20466,
  383. 20471,
  384. 20477,
  385. 20467,
  386. 20470,
  387. 20476,
  388. 20465,
  389. 20473,
  390. 20489,
  391. 20488,
  392. 20487,
  393. 20490,
  394. 20491,
  395. 20522,
  396. 20523,
  397. 20521,
  398. 20524,
  399. 20525,
  400. 20531,
  401. 20529,
  402. 20526,
  403. 20530,
  404. 20528,
  405. 20527,
  406. 20497,
  407. 20498,
  408. 20495,
  409. 20496,
  410. 20494,
  411. 20479,
  412. 20485,
  413. 20486,
  414. 20480,
  415. 20482,
  416. 20481,
  417. 20553,
  418. 20554,
  419. 20483,
  420. 20484,
  421. 20458,
  422. 20459,
  423. 20460,
  424. 1031,
  425. 6160,
  426. 2110])
  427. # %%
  428. # Convert Field IDs to Field Names
  429. # Instance 2
  430. mh_i2_names = ukbiobank.utils.utils.fieldIdsToNames(ukbio=ukb, df=mh_i2)
  431. # Online
  432. mh_online_names = ukbiobank.utils.utils.fieldIdsToNames(ukbio=ukb, df=mh_online)
  433. # Merge Mental Health Instance 2 and Mental Health Online
  434. mh_i2_online = pd.merge(mh_i2_names, mh_online_names, on="eid", suffixes=('', '_drop'))
  435. mh_i2_online.columns.to_list()
  436. mh_i2_online = mh_i2_online.loc[:, ~mh_i2_online.columns.str.endswith('_drop')]
  437. mh_i2_online.to_csv('/UK_BB/mental_health/mh_instance2_online.csv', index=False)
  438. # %% [markdown]
  439. # ## Manage NaNs
  440. # %%
  441. # Drop NAs
  442. mh_diagnoses_drop_na = mh_i2_online.dropna(subset=[
  443. "Ever manic/hyper for 2 days-2.0",
  444. "Worry too long after embarrassment-2.0",
  445. "Loneliness, isolation-2.0",
  446. "Risk taking-2.0",
  447. "Happiness-2.0",
  448. "Guilty feelings-2.0",
  449. "Mood swings-2.0",
  450. "Sensitivity / hurt feelings-2.0",
  451. "Suffer from 'nerves'-2.0",
  452. "Frequency of depressed mood in last 2 weeks-2.0",
  453. "Seen doctor (GP) for nerves, anxiety, tension or depression-2.0",
  454. "Frequency of unenthusiasm / disinterest in last 2 weeks-2.0",
  455. "Work/job satisfaction-2.0",
  456. "Family relationship satisfaction-2.0",
  457. "Frequency of tenseness / restlessness in last 2 weeks-2.0",
  458. "Miserableness-2.0",
  459. "Ever highly irritable/argumentative for 2 days-2.0",
  460. "Ever depressed for a whole week-2.0",
  461. "Ever unenthusiastic/disinterested for a whole week-2.0",
  462. "Seen a psychiatrist for nerves, anxiety, tension or depression-2.0",
  463. "Fed-up feelings-2.0",
  464. "Friendships satisfaction-2.0",
  465. "Illness, injury, bereavement, stress in last 2 years-2.0",
  466. "Worrier / anxious feelings-2.0",
  467. "Financial situation satisfaction-2.0",
  468. "Health satisfaction-2.0",
  469. "Frequency of tiredness / lethargy in last 2 weeks-2.0",
  470. "Nervous feelings-2.0",
  471. "Irritability-2.0",
  472. "Tense / 'highly strung'-2.0",
  473. "Able to pay rent/mortgage as an adult-0.0",
  474. "Sexual interference by partner or ex-partner without consent as an adult-0.0",
  475. "Recent worrying too much about different things-0.0",
  476. "Belittlement by partner or ex-partner as an adult-0.0",
  477. "Ever taken cannabis-0.0",
  478. "Physical violence by partner or ex-partner as an adult-0.0",
  479. "Been in a confiding relationship as an adult-0.0",
  480. "Recent feelings of tiredness or low energy-0.0",
  481. "Recent changes in speed/amount of moving or speaking-0.0",
  482. "Ever worried more than most people would in similar situation-0.0",
  483. "Diagnosed with life-threatening illness-0.0",
  484. "Victim of physically violent crime-0.0",
  485. "Witnessed sudden violent death-0.0",
  486. "Victim of sexual assault-0.0",
  487. "Trouble falling or staying asleep, or sleeping too much-0.0",
  488. "Ever felt worried, tense, or anxious for most of a month or longer-0.0",
  489. "Frequency of drinking alcohol-0.0",
  490. "Ever been injured or injured someone else through drinking alcohol-0.0",
  491. "Ever had known person concerned about, or recommend reduction of, alcohol consumption-0.0",
  492. "Ever addicted to any substance or behaviour-0.0",
  493. "Been involved in combat or exposed to war-zone-0.0",
  494. "Recent restlessness-0.0",
  495. "Been in serious accident believed to be life-threatening-0.0",
  496. "Recent lack of interest or pleasure in doing things-0.0",
  497. "Sexually molested as a child-0.0",
  498. "Physically abused by family as a child-0.0",
  499. "Felt hated by family member as a child-0.0",
  500. "Ever contemplated self-harm-0.0",
  501. "Ever had prolonged feelings of sadness or depression-0.0",
  502. "Ever self-harmed-0.0",
  503. "Someone to take to doctor when needed as a child-0.0",
  504. "Ever thought that life not worth living-0.0",
  505. "Recent trouble relaxing-0.0",
  506. "Ever believed in an un-real conspiracy against self-0.0",
  507. "Ever heard an un-real voice-0.0",
  508. "Belief that own life is meaningful-0.0",
  509. "General happiness with own health-0.0",
  510. "General happiness-0.0",
  511. "Ever believed in un-real communications or signs-0.0",
  512. "Ever had prolonged loss of interest in normal activities-0.0",
  513. "Ever seen an un-real vision-0.0",
  514. "Repeated disturbing thoughts of stressful experience in past month-0.0",
  515. "Recent thoughts of suicide or self-harm-0.0",
  516. "Recent feelings of foreboding-0.0",
  517. "Recent poor appetite or overeating-0.0",
  518. "Recent feelings of depression-0.0",
  519. "Avoided activities or situations because of previous stressful experience in past month-0.0",
  520. "Recent inability to stop or control worrying-0.0",
  521. "Recent trouble concentrating on things-0.0",
  522. "Recent feelings of inadequacy-0.0",
  523. "Recent feelings or nervousness or anxiety-0.0",
  524. "Felt loved as a child-0.0",
  525. "Felt very upset when reminded of stressful experience in past month-0.0",
  526. "Ever sought or received professional help for mental distress-0.0",
  527. "Ever had period of mania / excitability-0.0",
  528. "Ever had period extreme irritability-0.0",
  529. "Recent easy annoyance or irritability-0.0",
  530. "Ever suffered mental distress preventing usual activities-0.0"], axis=0).reset_index(drop=True)
  531. mh_diagnoses_drop_na.to_csv('/UK_BB/mental_health/mh_diagnoses_drop_na.csv', index=False)
  532. # %% [markdown]
  533. # ## Extract diagnoses
  534. # %%
  535. targets = pd.read_csv('/UK_BB/cognitive/target.csv')
  536. mh = pd.merge(mh_diagnoses_drop_na, targets['eid'], on = 'eid')
  537. mh.to_csv('/UK_BB/mental_health/mh_instance2_online_matched_to_targets.csv', index=False)
  538. # %%
  539. mh = pd.read_csv('/Cog-Ment/CSVs/2024/mental_health/mh_instance2_online_matched_to_targets.csv')
  540. # %%
  541. # Extract and combine noncncer diagnoses
  542. mh_diagnoses = mh.copy()
  543. # Set a 'noncaner' column: Filter columns that start with 'Non-cancer illness code, self-reported'
  544. noncancer_cols = mh_diagnoses.filter(like='Non-cancer illness code, self-reported-').columns
  545. # Concatenate the values in the columns into a single string, separated by ';'
  546. mh_diagnoses["noncancer"] = mh_diagnoses[noncancer_cols].astype(str).apply(lambda x: x.str.cat(sep=";"), axis=1)
  547. # Extract diagnoses
  548. mh_diagnoses["Epilepsy"] = mh_diagnoses["noncancer"].str.contains("1264").astype(int)
  549. mh_diagnoses["Migraine"] = mh_diagnoses["noncancer"].str.contains("1265").astype(int)
  550. mh_diagnoses["Depression"] = mh_diagnoses["noncancer"].str.contains("1286").astype(int)
  551. mh_diagnoses["Anxiety/panic attacks"] = mh_diagnoses["noncancer"].str.contains("1287").astype(int)
  552. mh_diagnoses["Chronic/degenerative neurological problem & other neurological problem"] = mh_diagnoses["noncancer"].str.contains("|".join(["1258","1434"])).astype(int)
  553. mh_diagnoses["Head & spinal & peripheral nerve injury, Spinal cord & peripheral nerve disorder & cranial nerve problem/palsy & infection of NS & Cerebral palsy"] = mh_diagnoses["noncancer"].str.contains("|".join(["1254",
  554. "1251","1249","1244", "1433", "1267","1394","1266"])).astype(int)
  555. mh_diagnoses["Nervous breakdown, Schizophrenia, self-harm/suicide attempt, mania/bipolar, alcohol/substance abuse/dependency, PTSD, eating disorder, OCD"] = mh_diagnoses["noncancer"].str.contains("|".join(["1289","1288","1289",
  556. "1290","1291","1408", "1410", "1409", "1469", "1470", "1615"])).astype(int)
  557. mh_diagnoses["Stress, insomnia"] = mh_diagnoses["noncancer"].str.contains("|".join(["1614", "1616"])).astype(int)
  558. # Merge them into bigger groups
  559. mh_diagnoses["Neurological problem, NS injury, epilepsy"] = mh_diagnoses[["Epilepsy", "Head & spinal & peripheral nerve injury, Spinal cord & peripheral nerve disorder & cranial nerve problem/palsy & infection of NS & Cerebral palsy", "Chronic/degenerative neurological problem & other neurological problem"]].any(axis=1).astype(int) #.sum(axis=1).astype(int)
  560. mh_diagnoses["Stress, insomnia, migraine, nervous/mental problems"] = mh_diagnoses[["Stress, insomnia", "Migraine", "Nervous breakdown, Schizophrenia, self-harm/suicide attempt, mania/bipolar, alcohol/substance abuse/dependency, PTSD, eating disorder, OCD"]].any(axis=1).astype(int)
  561. # Drop 'Non-cancer illness' and other columns
  562. mh_diagnoses = mh_diagnoses.drop(columns=[col for col in mh_diagnoses.columns if 'Non-cancer illness' in col])
  563. mh_diagnoses = mh_diagnoses.drop(columns=["Epilepsy", "Head & spinal & peripheral nerve injury, Spinal cord & peripheral nerve disorder & cranial nerve problem/palsy & infection of NS & Cerebral palsy", "Chronic/degenerative neurological problem & other neurological problem"])
  564. mh_diagnoses = mh_diagnoses.drop(columns=["Stress, insomnia", "Migraine", "Nervous breakdown, Schizophrenia, self-harm/suicide attempt, mania/bipolar, alcohol/substance abuse/dependency, PTSD, eating disorder, OCD"])
  565. mh_diagnoses.to_csv('/UK_BB/mental_health/mh_noncancer_diagnoses.csv', index=False)
  566. # %%
  567. mh = mh_diagnoses.copy()
  568. # %% [markdown]
  569. # ## PHQ9
  570. # %%
  571. # PHQ9
  572. # Calculate the score ingonoring -818
  573. # PHQ: 20514, 20510, 20517, 20519, 20511, 20507, 20508, 20518, 20513: sum and subtract 9 to get the score
  574. # Recent lack of interest or pleasure in doing things-0.0
  575. # Recent feelings of depression
  576. # Trouble falling or staying asleep, or sleeping too much
  577. # Recent feelings of tiredness or low energy
  578. # Recent poor appetite or overeating
  579. # Recent feelings of inadequacy
  580. # Recent trouble concentrating on things
  581. # Recent changes in speed/amount of moving or speaking
  582. # Recent thoughts of suicide or self-harm
  583. # -818 Prefer not to answer
  584. # 1 Not at all
  585. # 2 Several days
  586. # 3 More than half the days
  587. # 4 Nearly every day
  588. # Replace -818 with 1 only for PHQ!
  589. mh[["Recent lack of interest or pleasure in doing things-0.0", "Recent feelings of depression-0.0", "Trouble falling or staying asleep, or sleeping too much-0.0",
  590. "Recent feelings of tiredness or low energy-0.0", "Recent poor appetite or overeating-0.0", "Recent feelings of inadequacy-0.0",
  591. "Recent trouble concentrating on things-0.0", "Recent changes in speed/amount of moving or speaking-0.0", "Recent thoughts of suicide or self-harm-0.0"]] = mh[["Recent lack of interest or pleasure in doing things-0.0", "Recent feelings of depression-0.0", "Trouble falling or staying asleep, or sleeping too much-0.0",
  592. "Recent feelings of tiredness or low energy-0.0", "Recent poor appetite or overeating-0.0", "Recent feelings of inadequacy-0.0",
  593. "Recent trouble concentrating on things-0.0", "Recent changes in speed/amount of moving or speaking-0.0", "Recent thoughts of suicide or self-harm-0.0"]].replace({-818: 1})
  594. # Check if replaced correctly
  595. print((mh[["Recent lack of interest or pleasure in doing things-0.0", "Recent feelings of depression-0.0", "Trouble falling or staying asleep, or sleeping too much-0.0",
  596. "Recent feelings of tiredness or low energy-0.0", "Recent poor appetite or overeating-0.0", "Recent feelings of inadequacy-0.0",
  597. "Recent trouble concentrating on things-0.0", "Recent changes in speed/amount of moving or speaking-0.0", "Recent thoughts of suicide or self-harm-0.0"]] == -818).sum())
  598. mh[["Recent lack of interest or pleasure in doing things-0.0", "Recent feelings of depression-0.0", "Trouble falling or staying asleep, or sleeping too much-0.0",
  599. "Recent feelings of tiredness or low energy-0.0", "Recent poor appetite or overeating-0.0", "Recent feelings of inadequacy-0.0",
  600. "Recent trouble concentrating on things-0.0", "Recent changes in speed/amount of moving or speaking-0.0", "Recent thoughts of suicide or self-harm-0.0"]].min()
  601. # %%
  602. # Calculate PHQ9 for after replacing -818 with 1
  603. mh["PHQ9"] = mh[[
  604. "Recent lack of interest or pleasure in doing things-0.0",
  605. "Recent feelings of depression-0.0",
  606. "Trouble falling or staying asleep, or sleeping too much-0.0",
  607. "Recent feelings of tiredness or low energy-0.0",
  608. "Recent poor appetite or overeating-0.0",
  609. "Recent feelings of inadequacy-0.0",
  610. "Recent trouble concentrating on things-0.0",
  611. "Recent changes in speed/amount of moving or speaking-0.0",
  612. "Recent thoughts of suicide or self-harm-0.0"
  613. ]].sum(axis=1, skipna=True).astype(int)
  614. # Standardize PHQ to 0-27
  615. mh["PHQ9"] = mh["PHQ9"].subtract(9)
  616. print('PHQ9 MIN:', mh["PHQ9"].min())
  617. print('PHQ9 MAX:', mh["PHQ9"].max())
  618. # %% [markdown]
  619. # ## Depression ever
  620. # %% [markdown]
  621. # At least one core symptom of depression, most or all of the day on most or all days for a two week period, with at least five depressive symptoms that represent a change from usual occurring over the same time-scale, with some or a lot of impairment.
  622. #
  623. # - Persistent sadness (20446) = Yes OR Loss of interest (20441) = Yes - CORE
  624. # - AND How much of day (20436) = Most of day or All day long
  625. # - AND Did you feel this way (20439) = Almost every day or Every day
  626. # - AND Impairment (20440) = Somewhat or A lot
  627. # - AND Total number of symptoms endorsed (core and others) >= 5:
  628. #
  629. # - Persistent sadness (core) 20446; Loss of interest (core) 20441; PLUS
  630. # - Tired or low energy 20449;
  631. # - Gain or loss of weight 20536 = Gain, Loss or Gain and loss;
  632. # - Sleep change 20532;
  633. # - Trouble concentrating 20435;
  634. # - Feeling worthless 20450;
  635. # - Thinking about death 20437
  636. # %%
  637. depr_ever_scores = []
  638. # Loop through each participant's variables
  639. for i in range(len(mh)):
  640. if (mh['Ever had prolonged feelings of sadness or depression-0.0'].iloc[i] > 0 or mh['Ever had prolonged loss of interest in normal activities-0.0'].iloc[i] > 0) and mh['Fraction of day affected during worst episode of depression-0.0'].iloc[i] > 2 and mh['Frequency of depressed days during worst episode of depression-0.0'].iloc[i] > 1 and mh['Impact on normal roles during worst period of depression-0.0'].iloc[i] > 1:
  641. num_symptoms = sum(j > 0 for j in [
  642. mh['Feelings of tiredness during worst episode of depression-0.0'].iloc[i],
  643. mh['Weight change during worst episode of depression-0.0'].iloc[i],
  644. mh['Did your sleep change?-0.0'].iloc[i],
  645. mh['Difficulty concentrating during worst depression-0.0'].iloc[i],
  646. mh['Feelings of worthlessness during worst period of depression-0.0'].iloc[i],
  647. mh['Thoughts of death during worst depression-0.0'].iloc[i],
  648. mh['Ever had prolonged feelings of sadness or depression-0.0'].iloc[i],
  649. mh['Ever had prolonged loss of interest in normal activities-0.0'].iloc[i]
  650. ])
  651. if num_symptoms >= 5:
  652. depr_ever_score = 1
  653. else:
  654. depr_ever_score = 0
  655. else:
  656. depr_ever_score = 0
  657. depr_ever_scores.append(depr_ever_score)
  658. mh = mh.assign(Depression_ever=depr_ever_scores)
  659. # %% [markdown]
  660. # ## Subthreshol depression
  661. # %%
  662. # Replace non-responders
  663. print(mh["Ever had prolonged feelings of sadness or depression-0.0"].median())
  664. mh["Ever had prolonged feelings of sadness or depression-0.0"] = mh["Ever had prolonged feelings of sadness or depression-0.0"].replace({-818:1, -121:1})
  665. # %%
  666. depr_sub_scores = []
  667. for i in range(len(mh)):
  668. diagnosed_with_depression = any(mh[f'Mental health problems ever diagnosed by a professional-0.{j}'].iloc[i] == 11 for j in range(1, 17))
  669. if mh['Depression_ever'].iloc[i] == 0 and (diagnosed_with_depression or mh['Depression'].iloc[i] == 1 or mh['Ever had prolonged feelings of sadness or depression-0.0'].iloc[i] > 0 or mh['Ever had prolonged loss of interest in normal activities-0.0'].iloc[i] > 0 or mh['PHQ9'].iloc[i] > 5):
  670. depr_sub_score = 1
  671. else:
  672. depr_sub_score = 0
  673. depr_sub_scores.append(depr_sub_score)
  674. mh = mh.assign(Depression_subthreshold=depr_sub_scores)
  675. # %% [markdown]
  676. # ## Bipolar I
  677. # %%
  678. bipolar_1_scores = []
  679. for i in range(len(mh)):
  680. if mh['Depression_ever'].iloc[i] == 1 and (mh['Ever had period of mania / excitability-0.0'].iloc[i] > 0 or mh['Ever had period extreme irritability-0.0'].iloc[i] > 0) and mh['Longest period of mania or irritability-0.0'].iloc[i] == 3 and mh['Severity of problems due to mania or irritability-0.0'].iloc[i] == 1:
  681. num_symptoms = sum(j > 0 for j in [
  682. mh['Manifestations of mania or irritability-0.1'].iloc[i], mh['Manifestations of mania or irritability-0.2'].iloc[i],
  683. mh['Manifestations of mania or irritability-0.3'].iloc[i], mh['Manifestations of mania or irritability-0.4'].iloc[i],
  684. mh['Manifestations of mania or irritability-0.5'].iloc[i], mh['Manifestations of mania or irritability-0.6'].iloc[i],
  685. mh['Manifestations of mania or irritability-0.7'].iloc[i], mh['Manifestations of mania or irritability-0.8'].iloc[i]])
  686. if (mh['Ever had period of mania / excitability-0.0'].iloc[i] == 0 and num_symptoms >= 4) or (mh['Ever had period of mania / excitability-0.0'].iloc[i] == 1 and num_symptoms >= 3):
  687. bipolar_1_score = 1
  688. else:
  689. bipolar_1_score = 0
  690. else:
  691. bipolar_1_score = 0
  692. bipolar_1_scores.append(bipolar_1_score)
  693. mh = mh.assign(Bipolar_1=bipolar_1_scores)
  694. # %% [markdown]
  695. # ## Bipolar II
  696. # %%
  697. bipolar_2_scores = []
  698. for i in range(len(mh)):
  699. if mh['Depression_ever'].iloc[i] == 1 and (mh['Ever had period of mania / excitability-0.0'].iloc[i] > 0 or mh['Ever had period extreme irritability-0.0'].iloc[i] > 0) and mh['Longest period of mania or irritability-0.0'].iloc[i] == 3:
  700. num_symptoms = sum(j > 0 for j in [
  701. mh['Manifestations of mania or irritability-0.1'].iloc[i], mh['Manifestations of mania or irritability-0.2'].iloc[i],
  702. mh['Manifestations of mania or irritability-0.3'].iloc[i], mh['Manifestations of mania or irritability-0.4'].iloc[i],
  703. mh['Manifestations of mania or irritability-0.5'].iloc[i], mh['Manifestations of mania or irritability-0.6'].iloc[i],
  704. mh['Manifestations of mania or irritability-0.7'].iloc[i], mh['Manifestations of mania or irritability-0.8'].iloc[i]])
  705. if (mh['Ever had period of mania / excitability-0.0'].iloc[i] == 0 and num_symptoms >= 4) or (mh['Ever had period of mania / excitability-0.0'].iloc[i] == 1 and num_symptoms >= 3):
  706. bipolar_2_score = 1
  707. else:
  708. bipolar_2_score = 0
  709. else:
  710. bipolar_2_score = 0
  711. bipolar_2_scores.append(bipolar_2_score)
  712. mh = mh.assign(Bipolar_2=bipolar_2_scores)
  713. # %% [markdown]
  714. # ## Depression single episode
  715. # %%
  716. depression_single = [1 if (mh['Depression_ever'].iloc[i] == 1 and mh['Bipolar_1'].iloc[i] == 0 and mh['Lifetime number of depressed periods-0.0'].iloc[i] == 1) else 0 for i in range(len(mh))]
  717. mh = mh.assign(Depression_single=depression_single)
  718. # %% [markdown]
  719. # ## Recurrent depression
  720. # %%
  721. depression_recurrent= [1 if (mh['Depression_ever'].iloc[i] == 1 and mh['Bipolar_1'].iloc[i] == 0 and (mh['Lifetime number of depressed periods-0.0'].iloc[i] > 1 or mh['Lifetime number of depressed periods-0.0'].iloc[i] == -999)) else 0 for i in range(len(mh))]
  722. mh = mh.assign(Depression_recurrent=depression_recurrent)
  723. # %% [markdown]
  724. # ## Depression single episode triggered by loss
  725. # %%
  726. depression_by_loss= [1 if (mh['Depression_single'].iloc[i] == 1 and mh['Depression possibly related to stressful or traumatic event-0.0'].iloc[i] == 1) else 0 for i in range(len(mh))]
  727. mh = mh.assign(Depression_triggered_by_loss=depression_by_loss)
  728. # %% [markdown]
  729. # ## Current depression
  730. # %%
  731. depr_current = []
  732. for i in range(len(mh)):
  733. if mh['Depression_ever'].iloc[i] == 1:
  734. num_sumptoms_main = sum(1 for j in [
  735. mh['Recent lack of interest or pleasure in doing things-0.0'].iloc[i],
  736. mh['Recent feelings of depression-0.0'].iloc[i],
  737. mh['Trouble falling or staying asleep, or sleeping too much-0.0'].iloc[i],
  738. mh['Recent feelings of tiredness or low energy-0.0'].iloc[i],
  739. mh['Recent poor appetite or overeating-0.0'].iloc[i],
  740. mh['Recent feelings of inadequacy-0.0'].iloc[i],
  741. mh['Recent trouble concentrating on things-0.0'].iloc[i],
  742. mh['Recent changes in speed/amount of moving or speaking-0.0'].iloc[i]
  743. ] if j > 2)
  744. num_sumptoms_sui = sum(1 for m in [mh['Recent thoughts of suicide or self-harm-0.0'].iloc[i]] if m > 1)
  745. num_symptoms_all = num_sumptoms_main + num_sumptoms_sui
  746. if num_symptoms_all >= 5:
  747. deprcurr_score = 1
  748. else:
  749. deprcurr_score = 0
  750. else:
  751. deprcurr_score = 0
  752. depr_current.append(deprcurr_score)
  753. mh = mh.assign(Depression_current=depr_current)
  754. # %% [markdown]
  755. # ## Current severe depression
  756. # %%
  757. depr_current_severe = [1 if (mh['Depression_current'].iloc[i] == 1 and mh['PHQ9'].iloc[i] > 15) else 0 for i in range(len(mh))]
  758. mh = mh.assign(Depression_current_severe=depr_current_severe)
  759. # %% [markdown]
  760. # ## Mania
  761. # %%
  762. mania_scores = []
  763. for i in range(len(mh)):
  764. if (mh['Ever had period of mania / excitability-0.0'].iloc[i] == 1 or mh['Ever had period extreme irritability-0.0'].iloc[i] == 1) and mh['Longest period of mania or irritability-0.0'].iloc[i] == 3:
  765. num_symptoms = sum(j > 0 for j in [
  766. mh['Manifestations of mania or irritability-0.1'].iloc[i], mh['Manifestations of mania or irritability-0.2'].iloc[i],
  767. mh['Manifestations of mania or irritability-0.3'].iloc[i], mh['Manifestations of mania or irritability-0.4'].iloc[i],
  768. mh['Manifestations of mania or irritability-0.5'].iloc[i], mh['Manifestations of mania or irritability-0.6'].iloc[i],
  769. mh['Manifestations of mania or irritability-0.7'].iloc[i], mh['Manifestations of mania or irritability-0.8'].iloc[i]])
  770. if (mh['Ever had period of mania / excitability-0.0'].iloc[i] == 1 and num_symptoms >= 3) or (mh['Ever had period of mania / excitability-0.0'].iloc[i] == 0 and num_symptoms >= 4):
  771. mania_score = 1
  772. else:
  773. mania_score = 0
  774. else:
  775. mania_score = 0
  776. mania_scores.append(mania_score)
  777. mh = mh.assign(Mania=bipolar_1_scores)
  778. # %%
  779. # Replace non-respondes with median
  780. mh[["Ever had prolonged loss of interest in normal activities-0.0", "Ever had period extreme irritability-0.0",
  781. "Ever had period of mania / excitability-0.0", "Ever felt worried, tense, or anxious for most of a month or longer-0.0",
  782. "Ever worried more than most people would in similar situation-0.0", "Ever taken cannabis-0.0", "Ever had prolonged feelings of sadness or depression-0.0"]].median()
  783. mh[["Ever had prolonged loss of interest in normal activities-0.0", "Ever had period extreme irritability-0.0",
  784. "Ever had period of mania / excitability-0.0", "Ever felt worried, tense, or anxious for most of a month or longer-0.0",
  785. "Ever worried more than most people would in similar situation-0.0", "Ever taken cannabis-0.0"]] = mh[[
  786. "Ever had prolonged loss of interest in normal activities-0.0", "Ever had period extreme irritability-0.0",
  787. "Ever had period of mania / excitability-0.0", "Ever felt worried, tense, or anxious for most of a month or longer-0.0",
  788. "Ever worried more than most people would in similar situation-0.0", "Ever taken cannabis-0.0"]].replace({-818:0, -121:0})
  789. # %% [markdown]
  790. # ## GAD-7 Score
  791. # %%
  792. print(mh[["Recent feelings or nervousness or anxiety-0.0", "Recent inability to stop or control worrying-0.0",
  793. "Recent worrying too much about different things-0.0", "Recent trouble relaxing-0.0", "Recent restlessness-0.0",
  794. "Recent easy annoyance or irritability-0.0", "Recent feelings of foreboding-0.0"]].median())
  795. mh[["Recent feelings or nervousness or anxiety-0.0", "Recent inability to stop or control worrying-0.0",
  796. "Recent worrying too much about different things-0.0", "Recent trouble relaxing-0.0", "Recent restlessness-0.0",
  797. "Recent easy annoyance or irritability-0.0", "Recent feelings of foreboding-0.0"]] = mh[["Recent feelings or nervousness or anxiety-0.0", "Recent inability to stop or control worrying-0.0",
  798. "Recent worrying too much about different things-0.0", "Recent trouble relaxing-0.0", "Recent restlessness-0.0",
  799. "Recent easy annoyance or irritability-0.0", "Recent feelings of foreboding-0.0"]].replace({-818: 1})
  800. mh["GAD7"] = mh[["Recent feelings or nervousness or anxiety-0.0", "Recent inability to stop or control worrying-0.0",
  801. "Recent worrying too much about different things-0.0", "Recent trouble relaxing-0.0", "Recent restlessness-0.0",
  802. "Recent easy annoyance or irritability-0.0", "Recent feelings of foreboding-0.0"]].sum(axis=1).astype(int).subtract(7)
  803. print('GAD7 MIN',mh["GAD7"].min())
  804. print('GAD7 MAX',mh["GAD7"].max())
  805. # %% [markdown]
  806. # ## GAD ever
  807. # %%
  808. gad_ever_scores = []
  809. for i in range(len(mh)):
  810. worried_tense = mh['Ever felt worried, tense, or anxious for most of a month or longer-0.0'].iloc[i] # yes == 1
  811. duration = mh['Longest period spent worried or anxious-0.0'].iloc[i] # >=6 / == -999
  812. most_days = mh['Worried most days during period of worst anxiety-0.0'].iloc[i] #yes == 1
  813. more_than_most = mh['Ever worried more than most people would in similar situation-0.0'].iloc[i]
  814. stronger_than_most = mh['Stronger worrying (than other people) during period of worst anxiety-0.0'].iloc[i] #yes == 1
  815. more_than_one = mh['Number of things worried about during worst period of anxiety-0.0'].iloc[i] # >1 (2More than one thing)
  816. diff_worries = mh['Multiple worries during worst period of anxiety-0.0'].iloc[i] #yes == 1
  817. diff_stop = mh['Difficulty stopping worrying during worst period of anxiety-0.0'].iloc[i] #yes == 1
  818. freq_stop= mh['Frequency of inability to stop worrying during worst period of anxiety-0.0'].iloc[i] #often
  819. freq_control = mh['Frequency of difficulty controlling worry during worst period of anxiety-0.0'].iloc[i] #often
  820. interference = mh['Impact on normal roles during worst period of anxiety-0.0'].iloc[i] # Some or A lot
  821. if worried_tense == 1 and (duration >= 6 or duration == -999) and most_days ==1 and (more_than_most == 1 or stronger_than_most == 1) and (more_than_one == 2 or diff_worries == 1) and (diff_stop==1 or freq_stop==3 or freq_control==3) and interference > 1:
  822. num_symptoms = sum(g > 0 for g in [
  823. mh['Restless during period of worst anxiety-0.0'].iloc[i],
  824. mh['Keyed up or on edge during worst period of anxiety-0.0'].iloc[i],
  825. mh['Easily tired during worst period of anxiety-0.0'].iloc[i],
  826. mh['Difficulty concentrating during worst period of anxiety-0.0'].iloc[i],
  827. mh['More irritable than usual during worst period of anxiety-0.0'].iloc[i],
  828. mh['Tense, sore, or aching muscles during worst period of anxiety-0.0'].iloc[i],
  829. mh['Frequent trouble falling or staying asleep during worst period of anxiety-0.0'].iloc[i]
  830. ])
  831. if num_symptoms >= 3:
  832. gad_ever_score = 1
  833. else:
  834. gad_ever_score = 0
  835. else:
  836. gad_ever_score = 0
  837. gad_ever_scores.append(gad_ever_score)
  838. mh = mh.assign(GAD_ever = gad_ever_scores)
  839. # %% [markdown]
  840. # ## Current anxiety
  841. # %%
  842. gad_current = [1 if (mh['GAD_ever'].iloc[i] == 1 and mh['GAD7'].iloc[i] >= 10) else 0 for i in range(len(mh))]
  843. mh = mh.assign(GAD_current = gad_current)
  844. # %% [markdown]
  845. # ## Current mild anxiety
  846. # %%
  847. gad_current_mild = [1 if (mh['GAD_ever'].iloc[i] == 1 and mh['GAD7'].iloc[i] >= 5 and mh['GAD7'].iloc[i] < 10) else 0 for i in range(len(mh))] # [5,10)
  848. mh = mh.assign(GAD_current_mild = gad_current_mild)
  849. # %% [markdown]
  850. # ## Current moderate anxiety
  851. # %%
  852. gad_current_moderate = [1 if (mh['GAD_ever'].iloc[i] == 1 and mh['GAD7'].iloc[i] >= 10 and mh['GAD7'].iloc[i] < 15) else 0 for i in range(len(mh))] # [10,15)
  853. mh = mh.assign(GAD_current_moderate = gad_current_moderate)
  854. # %% [markdown]
  855. # ## Current severe anxiety
  856. # %%
  857. gad_current_severe = [1 if (mh['GAD_ever'].iloc[i] == 1 and mh['GAD7'].iloc[i] >= 15) else 0 for i in range(len(mh))]# [15]
  858. mh = mh.assign(GAD_current_severe = gad_current_severe)
  859. # %% [markdown]
  860. # ## PCL
  861. # %% [markdown]
  862. # Sum of scores on questions representing the core symptoms of PTSD (subtract 5 to adjust)
  863. #
  864. #
  865. # Score 1-5 and sum
  866. # - 20497 Repeated disturbing thoughts of stressful experience in past month
  867. # - 20498 Felt very upset when reminded of stressful experience in past month
  868. # - 20495 Avoided activities or situations because of previous stressful experience in past month
  869. # - 20496 Felt distant from other people in past month
  870. # - 20494 Felt irritable or had angry outbursts in past month
  871. #
  872. #
  873. # -818 Prefer not to answer / 0 Not at all / 1 A little bit / 2 Moderately / 3 Quite a bit / 4 Extremely
  874. #
  875. # - 20508 Trouble concentrating (scored 1-4)
  876. #
  877. # -818 Prefer not to answer / 1 Not at all / 2 Several days / 3 More than half the days / 4 Nearly every day
  878. #
  879. #
  880. # Sum {
  881. # - 20497 Repeated disturbing thoughts of stressful experience in past month,
  882. # - 20498 Felt very upset when reminded of stressful experience in past month,
  883. # - 20495 Avoided activities or situations because of previous stressful experience in past month,
  884. # - 20496 Felt distant from other people in past month,
  885. # - 20494 Felt irritable or had angry outbursts in past month}
  886. #
  887. # - initially scored 0 to 4, replace -818 with 0 (median)
  888. #
  889. # - -818 Prefer not to answer / 1 Not at all / 2 Several days / 3 More than half the days / 4 Nearly every day
  890. #
  891. # - {20508 Trouble concentrating}
  892. # - scored 1,2,3,4
  893. # %%
  894. # PCL6
  895. # Medians
  896. print(mh[['Repeated disturbing thoughts of stressful experience in past month-0.0', 'Felt very upset when reminded of stressful experience in past month-0.0',
  897. 'Avoided activities or situations because of previous stressful experience in past month-0.0', 'Felt distant from other people in past month-0.0',
  898. 'Felt irritable or had angry outbursts in past month-0.0']].median())
  899. print(mh["Recent trouble concentrating on things-0.0"].median())
  900. mh[['Repeated disturbing thoughts of stressful experience in past month-0.0',
  901. 'Felt very upset when reminded of stressful experience in past month-0.0',
  902. 'Avoided activities or situations because of previous stressful experience in past month-0.0',
  903. 'Felt distant from other people in past month-0.0',
  904. 'Felt irritable or had angry outbursts in past month-0.0']] = mh[['Repeated disturbing thoughts of stressful experience in past month-0.0',
  905. 'Felt very upset when reminded of stressful experience in past month-0.0',
  906. 'Avoided activities or situations because of previous stressful experience in past month-0.0', 'Felt distant from other people in past month-0.0',
  907. 'Felt irritable or had angry outbursts in past month-0.0']].replace({-818: 0})
  908. mh["Recent trouble concentrating on things-0.0"] = mh["Recent trouble concentrating on things-0.0"].replace(-818,1)
  909. mh["PCL5"] = mh[['Repeated disturbing thoughts of stressful experience in past month-0.0', 'Felt very upset when reminded of stressful experience in past month-0.0',
  910. 'Avoided activities or situations because of previous stressful experience in past month-0.0', 'Felt distant from other people in past month-0.0',
  911. 'Felt irritable or had angry outbursts in past month-0.0']].sum(axis=1).astype(int)
  912. mh["PCL5"] = mh["PCL5"].add(5)
  913. # Calculate PCL6
  914. mh["PCL6"] = mh[['PCL5', 'Recent trouble concentrating on things-0.0']].sum(axis=1).astype(int)
  915. print('PCL6 MIN', mh["PCL6"].min())
  916. print('PCL6 MAX', mh["PCL6"].max())
  917. # %% [markdown]
  918. # ## PTSD
  919. # %%
  920. mh["PTSD"] = [1 if (mh["PCL6"].iloc[i] >=14) else 0 for i in range(len(mh))]
  921. mh = mh.rename(columns={'Self-harm: Life not worth living': 'Self-harm: Ever thought life not worth living', 'Ever thought that life not worth living': 'Frequency of "life not worth living" thoughts'})
  922. # %% [markdown]
  923. # ## AUDIT
  924. # %% [markdown]
  925. # AUDIT total score was created by taking the sum of items 1–10 for all participants, including those who endorsed currently never drinking alcohol (as they could still endorse past alcohol harm on items 9 and 10). We also created AUDIT subdomain scores by aggregating the scores from items 1–3, which include the information pertaining to alcohol consumption (AUDIT-C, N = 121,604), and from items 4–10, which indexes the information pertaining to alcohol problems (AUDIT-P, N = 121,604).
  926. # %%
  927. # Replace -818 with median
  928. # scored 0 to 4
  929. mh["Frequency of drinking alcohol-0.0"] = mh["Frequency of drinking alcohol-0.0"].replace(-818, mh["Frequency of drinking alcohol-0.0"].median())
  930. # scored 1 to 5 / 0-2
  931. columns_to_replace = [
  932. 'Amount of alcohol drunk on a typical drinking day-0.0',
  933. 'Frequency of consuming six or more units of alcohol-0.0',
  934. 'Frequency of inability to cease drinking in last year-0.0',
  935. 'Frequency of failure to fulfil normal expectations due to drinking alcohol in last year-0.0',
  936. 'Frequency of needing morning drink of alcohol after heavy drinking session in last year-0.0',
  937. 'Frequency of feeling guilt or remorse after drinking alcohol in last year-0.0',
  938. 'Frequency of memory loss due to drinking alcohol in last year-0.0',
  939. 'Ever been injured or injured someone else through drinking alcohol-0.0',
  940. 'Ever had known person concerned about, or recommend reduction of, alcohol consumption-0.0'
  941. ]
  942. for column in columns_to_replace:
  943. column_median = mh[column].median()
  944. mh[column] = mh[column].replace(-818, column_median)
  945. mh[[
  946. 'Amount of alcohol drunk on a typical drinking day-0.0',
  947. 'Frequency of consuming six or more units of alcohol-0.0',
  948. 'Frequency of inability to cease drinking in last year-0.0',
  949. 'Frequency of failure to fulfil normal expectations due to drinking alcohol in last year-0.0',
  950. 'Frequency of needing morning drink of alcohol after heavy drinking session in last year-0.0',
  951. 'Frequency of feeling guilt or remorse after drinking alcohol in last year-0.0',
  952. 'Frequency of memory loss due to drinking alcohol in last year-0.0',
  953. 'Ever been injured or injured someone else through drinking alcohol-0.0',
  954. 'Ever had known person concerned about, or recommend reduction of, alcohol consumption-0.0'
  955. ]].min()
  956. # %%
  957. # Recode 0,1,2 to 0,2,4
  958. mh[[
  959. "Ever been injured or injured someone else through drinking alcohol-0.0",
  960. "Ever had known person concerned about, or recommend reduction of, alcohol consumption-0.0"]] = mh[[
  961. "Ever been injured or injured someone else through drinking alcohol-0.0",
  962. "Ever had known person concerned about, or recommend reduction of, alcohol consumption-0.0"]].replace(1, 2)
  963. mh[[
  964. "Ever been injured or injured someone else through drinking alcohol-0.0",
  965. "Ever had known person concerned about, or recommend reduction of, alcohol consumption-0.0"]] = mh[[
  966. "Ever been injured or injured someone else through drinking alcohol-0.0",
  967. "Ever had known person concerned about, or recommend reduction of, alcohol consumption-0.0"]].replace(2, 4)
  968. # %%
  969. # Replace NaN with 0
  970. mh[['Amount of alcohol drunk on a typical drinking day-0.0',
  971. 'Frequency of consuming six or more units of alcohol-0.0',
  972. 'Frequency of inability to cease drinking in last year-0.0',
  973. 'Frequency of failure to fulfil normal expectations due to drinking alcohol in last year-0.0',
  974. 'Frequency of needing morning drink of alcohol after heavy drinking session in last year-0.0',
  975. 'Frequency of feeling guilt or remorse after drinking alcohol in last year-0.0',
  976. 'Frequency of memory loss due to drinking alcohol in last year-0.0']] = mh[['Amount of alcohol drunk on a typical drinking day-0.0',
  977. 'Frequency of consuming six or more units of alcohol-0.0',
  978. 'Frequency of inability to cease drinking in last year-0.0',
  979. 'Frequency of failure to fulfil normal expectations due to drinking alcohol in last year-0.0',
  980. 'Frequency of needing morning drink of alcohol after heavy drinking session in last year-0.0',
  981. 'Frequency of feeling guilt or remorse after drinking alcohol in last year-0.0',
  982. 'Frequency of memory loss due to drinking alcohol in last year-0.0']].replace(np.nan, 0)
  983. mh[mh["Frequency of drinking alcohol-0.0"] == 0][[
  984. 'Amount of alcohol drunk on a typical drinking day-0.0',
  985. 'Frequency of consuming six or more units of alcohol-0.0',
  986. 'Frequency of inability to cease drinking in last year-0.0',
  987. 'Frequency of failure to fulfil normal expectations due to drinking alcohol in last year-0.0',
  988. 'Frequency of needing morning drink of alcohol after heavy drinking session in last year-0.0',
  989. 'Frequency of feeling guilt or remorse after drinking alcohol in last year-0.0',
  990. 'Frequency of memory loss due to drinking alcohol in last year-0.0'
  991. ]].isna().sum()
  992. # %%
  993. # Recode 1-5 to 0-4
  994. mh[['Amount of alcohol drunk on a typical drinking day-0.0',
  995. 'Frequency of consuming six or more units of alcohol-0.0',
  996. 'Frequency of inability to cease drinking in last year-0.0',
  997. 'Frequency of failure to fulfil normal expectations due to drinking alcohol in last year-0.0',
  998. 'Frequency of needing morning drink of alcohol after heavy drinking session in last year-0.0',
  999. 'Frequency of feeling guilt or remorse after drinking alcohol in last year-0.0',
  1000. 'Frequency of memory loss due to drinking alcohol in last year-0.0']] = mh[['Amount of alcohol drunk on a typical drinking day-0.0',
  1001. 'Frequency of consuming six or more units of alcohol-0.0',
  1002. 'Frequency of inability to cease drinking in last year-0.0',
  1003. 'Frequency of failure to fulfil normal expectations due to drinking alcohol in last year-0.0',
  1004. 'Frequency of needing morning drink of alcohol after heavy drinking session in last year-0.0',
  1005. 'Frequency of feeling guilt or remorse after drinking alcohol in last year-0.0',
  1006. 'Frequency of memory loss due to drinking alcohol in last year-0.0']].replace({1:0, 2:1, 3:2, 4:3, 5:4})
  1007. # %%
  1008. # AUDIT
  1009. mh["AUDIT"] = mh[["Frequency of drinking alcohol-0.0",
  1010. 'Amount of alcohol drunk on a typical drinking day-0.0',
  1011. 'Frequency of consuming six or more units of alcohol-0.0',
  1012. 'Frequency of inability to cease drinking in last year-0.0',
  1013. 'Frequency of failure to fulfil normal expectations due to drinking alcohol in last year-0.0',
  1014. 'Frequency of needing morning drink of alcohol after heavy drinking session in last year-0.0',
  1015. 'Frequency of feeling guilt or remorse after drinking alcohol in last year-0.0',
  1016. 'Frequency of memory loss due to drinking alcohol in last year-0.0',
  1017. "Ever been injured or injured someone else through drinking alcohol-0.0",
  1018. "Ever had known person concerned about, or recommend reduction of, alcohol consumption-0.0"]].sum(axis=1).astype(int)
  1019. # (log)AUDIT
  1020. mh["AUDIT_log"] = np.log1p(mh["AUDIT"])
  1021. # %% [markdown]
  1022. # ## AUDIT-C
  1023. #
  1024. # Scores from items 1–3, which include the information pertaining to alcohol consumption
  1025. # %%
  1026. mh["AUDIT_C"] = mh[["Frequency of drinking alcohol-0.0",
  1027. 'Amount of alcohol drunk on a typical drinking day-0.0',
  1028. 'Frequency of consuming six or more units of alcohol-0.0']].sum(axis=1).astype(int)
  1029. mh["AUDIT_C_log"] = np.log1p(mh["AUDIT_C"])
  1030. # %% [markdown]
  1031. # ## AUDIT-P
  1032. #
  1033. # Items 4–10, which indexes the information pertaining to alcohol problems
  1034. # %%
  1035. mh["AUDIT_P"] = mh[['Frequency of inability to cease drinking in last year-0.0',
  1036. 'Frequency of failure to fulfil normal expectations due to drinking alcohol in last year-0.0',
  1037. 'Frequency of needing morning drink of alcohol after heavy drinking session in last year-0.0',
  1038. 'Frequency of feeling guilt or remorse after drinking alcohol in last year-0.0',
  1039. 'Frequency of memory loss due to drinking alcohol in last year-0.0',
  1040. "Ever been injured or injured someone else through drinking alcohol-0.0",
  1041. "Ever had known person concerned about, or recommend reduction of, alcohol consumption-0.0"]].sum(axis=1).astype(int)
  1042. mh["AUDIT_P_log"] = np.log1p(mh["AUDIT_P"])
  1043. # %% [markdown]
  1044. # ## Hazardous / Harmful Alcohol Use
  1045. # %%
  1046. mh["Hazardous_Alcohol_Use"] = np.where(mh["AUDIT"] >= 8, 1, 0)
  1047. # Alcohol dependence
  1048. mh["Alcohol_Dependence"] = np.where(mh["AUDIT"] >= 15, 1, 0)
  1049. mh["Alcohol_depencence_ever"] = np.where(mh["Ever physically dependent on alcohol-0.0"] == 1, 1, 0)
  1050. # %% [markdown]
  1051. # ## Cannabis
  1052. # %%
  1053. mh["Ever taken cannabis-0.0"] = mh["Ever taken cannabis-0.0"].replace(np.nan, mh["Ever taken cannabis-0.0"].median())
  1054. mh["Cannabis ever"] = np.where(mh["Ever taken cannabis-0.0"] > 0, 1, 0)
  1055. mh['Frequency of taking cannabis'] = mh["Ever taken cannabis-0.0"]
  1056. #20454[Maximum frequency of taking cannabis] frequency = every day {4}
  1057. mh["Cannabis daily"] = np.where(mh["Maximum frequency of taking cannabis-0.0"] == 4, 1, 0)
  1058. # %% [markdown]
  1059. # ## Childhood adverse events
  1060. # %%
  1061. # Replace -818 with median
  1062. columns_to_replace = ['Felt loved as a child-0.0', 'Physically abused by family as a child-0.0', 'Felt hated by family member as a child-0.0',
  1063. 'Sexually molested as a child-0.0', 'Someone to take to doctor when needed as a child-0.0']
  1064. for column in columns_to_replace:
  1065. column_median = mh[column].median()
  1066. mh[column] = mh[column].replace(-818, column_median)
  1067. # %%
  1068. # Based on answers to the five questions of Childhood Trauma Screen (CTS), all scored 1-5. A score over the threshold on any question is screen positive
  1069. mh[['Felt loved as a child-0.0', 'Physically abused by family as a child-0.0', 'Felt hated by family member as a child-0.0',
  1070. 'Sexually molested as a child-0.0', 'Someone to take to doctor when needed as a child-0.0']] = mh[['Felt loved as a child-0.0',
  1071. 'Physically abused by family as a child-0.0', 'Felt hated by family member as a child-0.0',
  1072. 'Sexually molested as a child-0.0', 'Someone to take to doctor when needed as a child-0.0']].replace({0:1, 1:2, 2:3, 3:4, 4:5})
  1073. # %%
  1074. mh['Childhood_adverse_events'] = [1 if (mh['Felt loved as a child-0.0'].iloc[i] <= 3 or mh['Physically abused by family as a child-0.0'].iloc[i] >= 2 or
  1075. mh['Felt hated by family member as a child-0.0'].iloc[i] >= 2 or mh['Sexually molested as a child-0.0'].iloc[i] >= 2 or mh['Someone to take to doctor when needed as a child-0.0'].iloc[i] <= 4) else 0 for i in range(len(mh))]
  1076. # %% [markdown]
  1077. # ## Adult adverse events
  1078. # %%
  1079. # Replace -818 with median
  1080. columns_to_replace = ['Been in a confiding relationship as an adult-0.0',
  1081. 'Physical violence by partner or ex-partner as an adult-0.0',
  1082. 'Belittlement by partner or ex-partner as an adult-0.0',
  1083. 'Sexual interference by partner or ex-partner without consent as an adult-0.0',
  1084. 'Able to pay rent/mortgage as an adult-0.0']
  1085. for column in columns_to_replace:
  1086. column_median = mh[column].median()
  1087. mh[column] = mh[column].replace(-818, column_median)
  1088. # %%
  1089. # Recode
  1090. mh[['Been in a confiding relationship as an adult-0.0',
  1091. 'Physical violence by partner or ex-partner as an adult-0.0',
  1092. 'Belittlement by partner or ex-partner as an adult-0.0',
  1093. 'Sexual interference by partner or ex-partner without consent as an adult-0.0',
  1094. 'Able to pay rent/mortgage as an adult-0.0']] = mh[['Been in a confiding relationship as an adult-0.0',
  1095. 'Physical violence by partner or ex-partner as an adult-0.0',
  1096. 'Belittlement by partner or ex-partner as an adult-0.0',
  1097. 'Sexual interference by partner or ex-partner without consent as an adult-0.0',
  1098. 'Able to pay rent/mortgage as an adult-0.0']].replace({0:1, 1:2, 2:3, 3:4, 4:5})
  1099. # %%
  1100. mh['Adult_adverse_events'] = [1 if (mh['Been in a confiding relationship as an adult-0.0'].iloc[i] <= 3 or mh['Physical violence by partner or ex-partner as an adult-0.0'].iloc[i] >= 2 or
  1101. mh['Belittlement by partner or ex-partner as an adult-0.0'].iloc[i] >= 2 or mh['Sexual interference by partner or ex-partner without consent as an adult-0.0'].iloc[i] >= 2 or mh['Able to pay rent/mortgage as an adult-0.0'].iloc[i] <= 4) else 0 for i in range(len(mh))]
  1102. # %% [markdown]
  1103. # ## Catastrophic trauma
  1104. # %%
  1105. # Replace -818 with median
  1106. columns_to_replace = ['Victim of sexual assault-0.0',
  1107. 'Victim of physically violent crime-0.0',
  1108. 'Been in serious accident believed to be life-threatening-0.0',
  1109. 'Witnessed sudden violent death-0.0',
  1110. 'Diagnosed with life-threatening illness-0.0',
  1111. 'Been involved in combat or exposed to war-zone-0.0']
  1112. for column in columns_to_replace:
  1113. column_median = mh[column].median()
  1114. mh[column] = mh[column].replace(-818, column_median)
  1115. # %%
  1116. mh['Catastrophic_trauma'] = [1 if (mh['Victim of sexual assault-0.0'].iloc[i] > 0 or
  1117. mh['Victim of physically violent crime-0.0'].iloc[i] > 0 or
  1118. mh['Been in serious accident believed to be life-threatening-0.0'].iloc[i] > 0 or
  1119. mh['Witnessed sudden violent death-0.0'].iloc[i] > 0 or
  1120. mh['Diagnosed with life-threatening illness-0.0'].iloc[i] > 0 or
  1121. mh['Been involved in combat or exposed to war-zone-0.0'].iloc[i] > 0) else 0 for i in range(len(mh))]
  1122. # %% [markdown]
  1123. # ## Wellbeing
  1124. # %%
  1125. # Replace -818 with median
  1126. columns_to_replace = ["General happiness-0.0", "General happiness with own health-0.0", "Belief that own life is meaningful-0.0"]
  1127. for column in columns_to_replace:
  1128. column_median = mh[column].median()
  1129. mh[column] = mh[column].replace(-818, column_median)
  1130. mh[column] = mh[column].replace(-121, column_median)
  1131. # %%
  1132. mh[["General happiness-0.0",
  1133. "General happiness with own health-0.0"]] = mh[["General happiness-0.0", "General happiness with own health-0.0"]].replace({1:6, 2:5, 3:4, 4:3, 5:2, 6:1})
  1134. # %%
  1135. # Was:
  1136. #1Extremely happy
  1137. #2Very happy
  1138. #3Moderately happy
  1139. #4Moderately unhappy
  1140. #5Very unhappy
  1141. #6Extremely unhappy
  1142. #Become
  1143. #1Extremely unhappy
  1144. #2Very unhappy
  1145. #3Moderately unhappy
  1146. #4Moderately happy
  1147. #5Very happy
  1148. #6Extremely happy
  1149. # %%
  1150. # Wellbeing
  1151. mh["Wellbeing"] = mh[["General happiness-0.0", "General happiness with own health-0.0", "Belief that own life is meaningful-0.0"]].sum(axis=1).astype(int)
  1152. # %% [markdown]
  1153. # ## Unusual experience
  1154. # %%
  1155. mh[["Ever believed in an un-real conspiracy against self-0.0",
  1156. "Ever believed in un-real communications or signs-0.0",
  1157. "Ever heard an un-real voice-0.0", "Ever seen an un-real vision-0.0"]] = mh[[
  1158. "Ever believed in an un-real conspiracy against self-0.0",
  1159. "Ever believed in un-real communications or signs-0.0",
  1160. "Ever heard an un-real voice-0.0", "Ever seen an un-real vision-0.0"]].replace({-818:0, -121:0})
  1161. # %%
  1162. # Unusual experience
  1163. # Heard unreal voice 20463 = yes
  1164. # OR Saw unreal vision 20471 = yes
  1165. # OR Believed unreal conspiracy 20468 = yes
  1166. # OR Believed unreal communication or signs 20474 = yes
  1167. unexp = [(mh['Ever heard an un-real voice-0.0'].iloc[i], mh['Ever seen an un-real vision-0.0'].iloc[i],
  1168. mh['Ever believed in an un-real conspiracy against self-0.0'].iloc[i],
  1169. mh['Ever believed in un-real communications or signs-0.0'].iloc[i]) for i in range(len(mh))]
  1170. unusualexp = [1 if (u[0] > 0 or u[1] > 0 or u[2] > 0 or u[3] > 0) else 0 for u in unexp]
  1171. #%% Add to the df
  1172. mh = mh.assign(Unusual_exp=unusualexp)
  1173. # Recent unusual experience
  1174. # Frequency in last year 20467>0
  1175. ususrec = [(mh['Frequency of unusual or psychotic experiences in past year-0.0'].iloc[i]) for i in range(len(mh))]
  1176. unusualexprecent = [1 if (u>0) else 0 for u in ususrec]
  1177. mh = mh.assign(Unusual_exp_recent=unusualexprecent)
  1178. # Unusual_exp_recent
  1179. Unusual_exp_recent = mh.loc[mh['Unusual_exp_recent'] == 1][['Frequency of unusual or psychotic experiences in past year-0.0']]
  1180. # %% [markdown]
  1181. # ## Self-harm
  1182. # %%
  1183. # Life not worth living
  1184. # 20479 life NWL = yes (1 or 2)
  1185. mh["Self-harm: Life not worth living"] = np.where(mh["Ever thought that life not worth living-0.0"] > 0, 1, 0)
  1186. # NWL
  1187. NWL = mh.loc[mh['Self-harm: Life not worth living'] == 1][["Ever thought that life not worth living-0.0"]]
  1188. # Self harm
  1189. # 20480 Self harmed = Yes
  1190. mh["Self-harmed"] = np.where(mh["Ever self-harmed-0.0"] > 0, 1, 0)
  1191. #%% SH
  1192. SH = mh.loc[mh['Self-harmed'] == 1][["Ever self-harmed-0.0"]]
  1193. # Non-suicidal self-harm
  1194. # 20480 Self harmed = Yes
  1195. # 20483 Attempted suicide = No
  1196. # 51 said "prefer not to answer"
  1197. nonsuish = [(mh['Ever self-harmed-0.0'].iloc[i], mh['Ever attempted suicide-0.0'].iloc[i]) for i in range(len(mh))]
  1198. nonsuiselfharm = [1 if (s[0] > 0 and s[1] == 0) else 0 for s in nonsuish]
  1199. mh = mh.assign(Non_suicidal_SH=nonsuiselfharm)
  1200. # Non_suicidal self-harm
  1201. Non_suicidal_SH = mh.loc[mh['Non_suicidal_SH'] == 1][['Ever self-harmed-0.0', 'Ever attempted suicide-0.0']]
  1202. # Suicide attempt
  1203. # 20483 Attempted suicide = Yes
  1204. mh["Sui_attempt"] = np.where(mh["Ever attempted suicide-0.0"] > 0, 1, 0)
  1205. Sui_attempt = mh.loc[mh['Sui_attempt'] == 1][["Ever attempted suicide-0.0"]]
  1206. # Replace
  1207. mh[["Ever thought that life not worth living-0.0",
  1208. "Ever contemplated self-harm-0.0", "Ever self-harmed-0.0"]] = mh[["Ever thought that life not worth living-0.0",
  1209. "Ever contemplated self-harm-0.0", "Ever self-harmed-0.0"]].replace({-818:0, -121:0})
  1210. # %% [markdown]
  1211. # ## Addictions
  1212. # %%
  1213. mh["Ever addicted to any substance or behaviour-0.0"] = mh["Ever addicted to any substance or behaviour-0.0"].replace({-818:0, -121:0})
  1214. mh["Addiction_ever"] = np.where(mh["Ever addicted to any substance or behaviour-0.0"] == 1, 1, 0)
  1215. mh['Substance_addiction'] = [1 if (sa[0] == 1 or sa[1] == 1 or sa[2] == 1) else 0 for sa in [(mh['Ever addicted to alcohol-0.0'].iloc[i], mh['Ever addicted to illicit or recreational drugs-0.0'].iloc[i],
  1216. mh['Ever addicted to prescription or over-the-counter medication-0.0'].iloc[i]) for i in range(len(mh))]]
  1217. mh['Current_addiction'] = [1 if (c[0] == 1 or c[1]== 1 or c[2] == 1 or c[3] == 1) else 0 for c in [(mh['Ongoing addiction or dependence on illicit or recreational drugs-0.0'].iloc[i], mh['Ongoing addiction or dependence to over-the-counter medication-0.0'].iloc[i],
  1218. mh['Ongoing addiction to alcohol-0.0'].iloc[i], mh['Ongoing behavioural or miscellanous addiction-0.0'].iloc[i]) for i in range(len(mh))]]
  1219. # %% [markdown]
  1220. # ## Any distress
  1221. # %%
  1222. columns_to_replace = ["Ever sought or received professional help for mental distress-0.0", "Ever suffered mental distress preventing usual activities-0.0"]
  1223. for column in columns_to_replace:
  1224. column_median = mh[column].median()
  1225. mh[column] = mh[column].replace(-818, column_median)
  1226. mh[column] = mh[column].replace(-121, column_median)
  1227. # %%
  1228. any_distress = []
  1229. for i in range(len(mh)):
  1230. if mh['Ever sought or received professional help for mental distress-0.0'].iloc[i] == 1 or mh['Ever suffered mental distress preventing usual activities-0.0'].iloc[i] == 1 or mh['Depression_ever'].iloc[i] == 1 or mh['GAD_ever'].iloc[i] == 1 or mh['Ever addicted to any substance or behaviour-0.0'].iloc[i] == 1 or mh['Mania'].iloc[i] == 1 or mh['Bipolar_1'].iloc[i] == 1 or mh['Bipolar_2'].iloc[i] == 1 or mh['PTSD'].iloc[i] == 1 or mh['Unusual_exp'].iloc[i] == 1 or mh['Unusual_exp_recent'].iloc[i] == 1 or mh['Self-harmed'].iloc[i] or any(mh[f'Mental health problems ever diagnosed by a professional-0.{j}'].iloc[i] > 0 for j in range(1, 17)):
  1231. any_distress_score = 1
  1232. else:
  1233. any_distress_score = 0
  1234. any_distress.append(any_distress_score)
  1235. mh = mh.assign(Any_distress=any_distress)
  1236. #mh["Any_distress"] = [1 if mh['Ever sought or received professional help for mental distress-0.0'].iloc[i] == 1 or mh['Ever suffered mental distress preventing usual activities-0.0'].iloc[i] == 1 or mh['Depression_ever'].iloc[i] == 1 or mh['GAD_ever'].iloc[i] == 1 or mh['Addiction_ever'].iloc[i] == 1 or mh['Mania'].iloc[i] == 1 or mh['Bipolar_1'].iloc[i] == 1 or mh['Bipolar_2'].iloc[i] == 1 or mh['PTSD'].iloc[i] == 1 or mh['Unusual_exp'].iloc[i] == 1 or mh['Unusual_exp_recent'].iloc[i] == 1 or mh['Self-harmed'].iloc[i] or any(mh[f'Mental health problems ever diagnosed by a professional-0.{j}'].iloc[i] > 0 for j in range(1, 17)) else 0 for i in range(len(mh))]
  1237. # %% [markdown]
  1238. # ## Happiness
  1239. # %%
  1240. columns_to_replace = ["Happiness-2.0", "Family relationship satisfaction-2.0", "Financial situation satisfaction-2.0", "Friendships satisfaction-2.0", "Work/job satisfaction-2.0", "Health satisfaction-2.0"]
  1241. for column in columns_to_replace:
  1242. column_median = mh[column].median()
  1243. mh[column] = mh[column].replace(-1, column_median)
  1244. mh[column] = mh[column].replace(-3, column_median)
  1245. mh[["Happiness-2.0",
  1246. "Family relationship satisfaction-2.0",
  1247. "Financial situation satisfaction-2.0",
  1248. "Friendships satisfaction-2.0",
  1249. "Work/job satisfaction-2.0",
  1250. "Health satisfaction-2.0"]] = mh[["Happiness-2.0",
  1251. "Family relationship satisfaction-2.0",
  1252. "Financial situation satisfaction-2.0",
  1253. "Friendships satisfaction-2.0",
  1254. "Work/job satisfaction-2.0",
  1255. "Health satisfaction-2.0"]].replace({1:6, 2:5, 3:4, 4:3, 5:2, 6:1, 7:0})
  1256. # %%
  1257. columns_to_replace = [
  1258. 'Recent poor appetite or overeating-0.0',
  1259. 'Recent trouble concentrating on things-0.0',
  1260. 'Recent changes in speed/amount of moving or speaking-0.0',
  1261. 'Frequency of taking cannabis',
  1262. 'Trouble falling or staying asleep, or sleeping too much-0.0',
  1263. 'Recent feelings of tiredness or low energy-0.0',
  1264. 'Recent lack of interest or pleasure in doing things-0.0',
  1265. 'Recent feelings of depression-0.0',
  1266. 'Recent feelings of inadequacy-0.0',
  1267. 'Ever had period of mania / excitability-0.0',
  1268. 'Ever had period extreme irritability-0.0',
  1269. 'Recent thoughts of suicide or self-harm-0.0'
  1270. ]
  1271. for column in columns_to_replace:
  1272. column_median = mh[column].median()
  1273. mh[column] = mh[column].replace(-818, column_median)
  1274. mh[column] = mh[column].replace(-121, column_median)
  1275. # %% [markdown]
  1276. # ## NS-12
  1277. # %% [markdown]
  1278. # N-12 (0–12)
  1279. #
  1280. # - Mood swings
  1281. # - Miserableness 1930
  1282. # - Irritability 1940
  1283. # - Sensitivity/hurt feelings 1950
  1284. # - Fed-up feelings 1960
  1285. # - Nervous feelings 1970
  1286. # - Worrier/anxious feelings 1980
  1287. # - Tense/“highly strung” 1990
  1288. # - Worry too long after embarrassment 2000
  1289. # - Suffer from “nerves” 2010
  1290. # - Loneliness, isolation 2020
  1291. # - Guilty feelings 2030
  1292. # %%
  1293. # N-12 (0–12)
  1294. print(mh[["Mood swings-2.0", "Miserableness-2.0", "Irritability-2.0", "Sensitivity / hurt feelings-2.0",
  1295. "Fed-up feelings-2.0", "Nervous feelings-2.0", "Worrier / anxious feelings-2.0", "Tense / 'highly strung'-2.0",
  1296. "Worry too long after embarrassment-2.0", "Suffer from 'nerves'-2.0", "Loneliness, isolation-2.0", "Guilty feelings-2.0"]].median())
  1297. # Replace - 1 / -3 with 0
  1298. mh[["Mood swings-2.0", "Miserableness-2.0", "Irritability-2.0", "Sensitivity / hurt feelings-2.0",
  1299. "Fed-up feelings-2.0", "Nervous feelings-2.0", "Worrier / anxious feelings-2.0", "Tense / 'highly strung'-2.0",
  1300. "Worry too long after embarrassment-2.0", "Suffer from 'nerves'-2.0", "Loneliness, isolation-2.0", "Guilty feelings-2.0"]] = mh[["Mood swings-2.0", "Miserableness-2.0", "Irritability-2.0", "Sensitivity / hurt feelings-2.0",
  1301. "Fed-up feelings-2.0", "Nervous feelings-2.0", "Worrier / anxious feelings-2.0", "Tense / 'highly strung'-2.0",
  1302. "Worry too long after embarrassment-2.0", "Suffer from 'nerves'-2.0", "Loneliness, isolation-2.0", "Guilty feelings-2.0"]].replace({-1:0, -3:0})
  1303. mh['NS12'] = mh[["Mood swings-2.0", "Miserableness-2.0", "Irritability-2.0", "Sensitivity / hurt feelings-2.0",
  1304. "Fed-up feelings-2.0", "Nervous feelings-2.0", "Worrier / anxious feelings-2.0", "Tense / 'highly strung'-2.0",
  1305. "Worry too long after embarrassment-2.0", "Suffer from 'nerves'-2.0", "Loneliness, isolation-2.0", "Guilty feelings-2.0"]].sum(axis=1).astype(int)
  1306. print(mh['NS12'].min())
  1307. print(mh['NS12'].max())
  1308. # %% [markdown]
  1309. # ## Probable depression status
  1310. # %% [markdown]
  1311. # Probable depression status
  1312. #
  1313. # - Ever depressed 4598 OR Ever unenthusiastic/disinterested 4631
  1314. # - Duration of the longest period of depression 4609
  1315. # - Duration of the longest period of unenthusiasm/disinterest 5375
  1316. # - Seen doctor (GP) for nerves, anxiety, tension, and depression 2090
  1317. # - Seen psychiatrist for nerves, anxiety, tension, and depression 2100
  1318. #
  1319. #
  1320. # - Depression status was set to 1 if subjects responded
  1321. # - yes to variable IDs 4598 OR 4631 (ever depressed ever unenthusiastic/disinterested),
  1322. # - AND reported a duration of at least 1 week to variable IDs 4609 OR 5375 (depressionjunenthusiasm/disinterest)
  1323. # - AND had seen either a GP or psychiatrist for nerves, anxiety, tension, depression (i.e., responded yes to variable IDs, 2090 or 2100)
  1324. # %%
  1325. # Probable depression status
  1326. pdslist = [(mh['Ever depressed for a whole week-2.0'].iloc[i],
  1327. mh['Ever unenthusiastic/disinterested for a whole week-2.0'].iloc[i],
  1328. mh['Longest period of depression-2.0'].iloc[i],
  1329. mh['Longest period of unenthusiasm / disinterest-2.0'].iloc[i],
  1330. mh['Seen doctor (GP) for nerves, anxiety, tension or depression-2.0'].iloc[i],
  1331. mh['Seen a psychiatrist for nerves, anxiety, tension or depression-2.0'].iloc[i]) for i in range(len(mh))]
  1332. pds = []
  1333. for p in pdslist:
  1334. if (p[0] > 0 or p[1] > 0) and (p[2] >= 1 or p[3] >= 1) and (p[4] > 0 or p[5] > 0):
  1335. pds_score = 1
  1336. else:
  1337. pds_score = 0
  1338. pds.append(pds_score)
  1339. mh = mh.assign(PDS=pds)
  1340. # %%
  1341. # Replace -1/-3 - 0
  1342. mh[["Risk taking-2.0", "Seen a psychiatrist for nerves, anxiety, tension or depression-2.0", "Seen doctor (GP) for nerves, anxiety, tension or depression-2.0",
  1343. "Ever unenthusiastic/disinterested for a whole week-2.0", "Ever highly irritable/argumentative for 2 days-2.0", "Ever manic/hyper for 2 days-2.0"]] = mh[["Risk taking-2.0",
  1344. "Seen a psychiatrist for nerves, anxiety, tension or depression-2.0", "Seen doctor (GP) for nerves, anxiety, tension or depression-2.0",
  1345. "Ever unenthusiastic/disinterested for a whole week-2.0", "Ever highly irritable/argumentative for 2 days-2.0", "Ever manic/hyper for 2 days-2.0"]].replace({-1:0, -3:0})
  1346. # -1/-3 - 1
  1347. mh["Ever depressed for a whole week-2.0"] = mh["Ever depressed for a whole week-2.0"].replace({-1:3, -3:3})
  1348. # %% [markdown]
  1349. # ## Recent depressive symptoms
  1350. # %% [markdown]
  1351. # RDS-4 (4-16):
  1352. #
  1353. # - Frequency of depressed mood in last 2 weeks 2050
  1354. # - Frequency of unenthusiasm/disinterest in last 2 weeks 2060
  1355. # - Frequency of tenseness/restlessness in last 2 weeks 2070
  1356. # - Frequency of tiredness/lethargy in last 2 weeks 2080
  1357. # %%
  1358. # RDS-4 (4-16):
  1359. print(mh[['Frequency of depressed mood in last 2 weeks-2.0','Frequency of unenthusiasm / disinterest in last 2 weeks-2.0',
  1360. 'Frequency of tenseness / restlessness in last 2 weeks-2.0', 'Frequency of tiredness / lethargy in last 2 weeks-2.0']].median())
  1361. # Replace -3 and -1
  1362. mh[['Frequency of depressed mood in last 2 weeks-2.0','Frequency of unenthusiasm / disinterest in last 2 weeks-2.0',
  1363. 'Frequency of tenseness / restlessness in last 2 weeks-2.0', 'Frequency of tiredness / lethargy in last 2 weeks-2.0']] = mh[['Frequency of depressed mood in last 2 weeks-2.0','Frequency of unenthusiasm / disinterest in last 2 weeks-2.0',
  1364. 'Frequency of tenseness / restlessness in last 2 weeks-2.0', 'Frequency of tiredness / lethargy in last 2 weeks-2.0']].replace({-1:1, -3:1})
  1365. # Calculate the score
  1366. mh['RDS4'] = mh[['Frequency of depressed mood in last 2 weeks-2.0','Frequency of unenthusiasm / disinterest in last 2 weeks-2.0',
  1367. 'Frequency of tenseness / restlessness in last 2 weeks-2.0', 'Frequency of tiredness / lethargy in last 2 weeks-2.0']].sum(axis=1).astype(int)
  1368. print('RDS MIN', mh['RDS4'].min())
  1369. print('RDS MAX', mh['RDS4'].max())
  1370. # %% [markdown]
  1371. # # Select scores
  1372. # %%
  1373. mh_main = mh[['eid',
  1374. 'Anxiety/panic attacks',
  1375. 'NS12',
  1376. 'PCL6',
  1377. 'PHQ9',
  1378. 'PDS',
  1379. 'RDS4',
  1380. 'Depression',
  1381. 'Self-harm: Life not worth living', #Self-harm: Ever thought life not worth living" yes/no
  1382. 'Sui_attempt',
  1383. 'Self-harmed',
  1384. 'Non_suicidal_SH',
  1385. 'Unusual_exp',
  1386. 'Unusual_exp_recent',
  1387. 'Repeated disturbing thoughts of stressful experience in past month-0.0',
  1388. 'Felt very upset when reminded of stressful experience in past month-0.0',
  1389. 'Avoided activities or situations because of previous stressful experience in past month-0.0',
  1390. 'Ever thought that life not worth living-0.0', #'Frequency of "life not worth living" thoughts',
  1391. 'Ever contemplated self-harm-0.0',
  1392. 'Ever had prolonged feelings of sadness or depression-0.0',
  1393. 'Ever had prolonged loss of interest in normal activities-0.0',
  1394. 'Ever felt worried, tense, or anxious for most of a month or longer-0.0',
  1395. 'Ever worried more than most people would in similar situation-0.0',
  1396. 'Ever addicted to any substance or behaviour-0.0',
  1397. 'Ever believed in an un-real conspiracy against self-0.0',
  1398. 'Ever believed in un-real communications or signs-0.0',
  1399. 'Ever heard an un-real voice-0.0',
  1400. 'Ever seen an un-real vision-0.0',
  1401. 'Mood swings-2.0',
  1402. 'Miserableness-2.0',
  1403. 'Irritability-2.0',
  1404. 'Sensitivity / hurt feelings-2.0',
  1405. 'Fed-up feelings-2.0',
  1406. 'Nervous feelings-2.0',
  1407. 'Worrier / anxious feelings-2.0',
  1408. "Tense / 'highly strung'-2.0",
  1409. 'Worry too long after embarrassment-2.0',
  1410. "Suffer from 'nerves'-2.0",
  1411. 'Loneliness, isolation-2.0',
  1412. 'Guilty feelings-2.0',
  1413. 'Risk taking-2.0',
  1414. 'Frequency of depressed mood in last 2 weeks-2.0',
  1415. 'Frequency of unenthusiasm / disinterest in last 2 weeks-2.0',
  1416. 'Frequency of tenseness / restlessness in last 2 weeks-2.0',
  1417. 'Frequency of tiredness / lethargy in last 2 weeks-2.0',
  1418. 'Seen a psychiatrist for nerves, anxiety, tension or depression-2.0',
  1419. 'Seen doctor (GP) for nerves, anxiety, tension or depression-2.0',
  1420. 'Ever depressed for a whole week-2.0',
  1421. 'Ever unenthusiastic/disinterested for a whole week-2.0',
  1422. 'Ever highly irritable/argumentative for 2 days-2.0',
  1423. 'Ever manic/hyper for 2 days-2.0',
  1424. #"Diagnoses 'F'",
  1425. #"Diagnoses 'G'",
  1426. 'Neurological problem, NS injury, epilepsy',
  1427. 'Stress, insomnia, migraine, nervous/mental problems',
  1428. 'Ever had period of mania / excitability-0.0',
  1429. 'Ever had period extreme irritability-0.0',
  1430. 'Recent feelings of inadequacy-0.0',
  1431. 'Recent trouble concentrating on things-0.0',
  1432. 'Recent feelings of depression-0.0',
  1433. 'Recent poor appetite or overeating-0.0',
  1434. 'Recent thoughts of suicide or self-harm-0.0',
  1435. 'Recent lack of interest or pleasure in doing things-0.0',
  1436. 'Trouble falling or staying asleep, or sleeping too much-0.0',
  1437. 'Recent changes in speed/amount of moving or speaking-0.0',
  1438. 'Recent feelings of tiredness or low energy-0.0',
  1439. 'Depression_ever',
  1440. 'Depression_subthreshold',
  1441. 'Bipolar_1',
  1442. 'Bipolar_2',
  1443. 'Depression_single',
  1444. 'Depression_recurrent',
  1445. 'Depression_triggered_by_loss',
  1446. 'Depression_current',
  1447. 'Depression_current_severe',
  1448. #'Mania',
  1449. 'Recent easy annoyance or irritability-0.0',
  1450. 'Recent feelings or nervousness or anxiety-0.0',
  1451. 'Recent inability to stop or control worrying-0.0',
  1452. 'Recent feelings of foreboding-0.0',
  1453. 'Recent trouble relaxing-0.0',
  1454. 'Recent restlessness-0.0',
  1455. 'Recent worrying too much about different things-0.0',
  1456. 'GAD7',
  1457. 'GAD_ever',
  1458. 'GAD_current',
  1459. 'GAD_current_mild',
  1460. 'GAD_current_moderate',
  1461. 'GAD_current_severe',
  1462. 'PTSD',
  1463. 'Amount of alcohol drunk on a typical drinking day-0.0',
  1464. 'Frequency of drinking alcohol-0.0',
  1465. 'Frequency of consuming six or more units of alcohol-0.0',
  1466. 'AUDIT',
  1467. 'AUDIT_log',
  1468. 'AUDIT_C',
  1469. 'AUDIT_P',
  1470. 'AUDIT_C_log',
  1471. 'AUDIT_P_log',
  1472. 'Hazardous_Alcohol_Use',
  1473. 'Alcohol_Dependence',
  1474. 'General happiness-0.0',
  1475. 'General happiness with own health-0.0',
  1476. 'Belief that own life is meaningful-0.0',
  1477. 'Felt hated by family member as a child-0.0',
  1478. 'Physically abused by family as a child-0.0',
  1479. 'Felt loved as a child-0.0',
  1480. 'Sexually molested as a child-0.0',
  1481. 'Someone to take to doctor when needed as a child-0.0',
  1482. 'Ever sought or received professional help for mental distress-0.0',
  1483. 'Ever suffered mental distress preventing usual activities-0.0',
  1484. 'Belittlement by partner or ex-partner as an adult-0.0',
  1485. 'Been in a confiding relationship as an adult-0.0',
  1486. 'Physical violence by partner or ex-partner as an adult-0.0',
  1487. 'Sexual interference by partner or ex-partner without consent as an adult-0.0',
  1488. 'Able to pay rent/mortgage as an adult-0.0',
  1489. 'Been in serious accident believed to be life-threatening-0.0',
  1490. 'Been involved in combat or exposed to war-zone-0.0',
  1491. 'Diagnosed with life-threatening illness-0.0',
  1492. 'Victim of physically violent crime-0.0',
  1493. 'Witnessed sudden violent death-0.0',
  1494. 'Victim of sexual assault-0.0',
  1495. #'Addiction_ever',
  1496. 'Alcohol_depencence_ever',
  1497. 'Substance_addiction',
  1498. 'Current_addiction',
  1499. 'Cannabis ever',
  1500. 'Frequency of taking cannabis',
  1501. 'Cannabis daily',
  1502. 'Childhood_adverse_events',
  1503. 'Adult_adverse_events',
  1504. 'Catastrophic_trauma',
  1505. 'Wellbeing',
  1506. 'Any_distress',
  1507. 'Friendships satisfaction-2.0',
  1508. 'Financial situation satisfaction-2.0',
  1509. 'Happiness-2.0',
  1510. 'Family relationship satisfaction-2.0',
  1511. 'Health satisfaction-2.0']]
  1512. mh_main.to_csv('/Cog-Ment/CSVs/2024/mental_health/mental_health_no_diagnoses_all_scores.csv', index=False)
  1513. # %% [markdown]
  1514. # # ICD Diagnoses
  1515. # %%
  1516. # Work out ICD diagnoses
  1517. diag_cols = ['Diagnoses - main ICD10-0.0',
  1518. 'Diagnoses - main ICD10-0.1',
  1519. 'Diagnoses - main ICD10-0.2',
  1520. 'Diagnoses - main ICD10-0.3',
  1521. 'Diagnoses - main ICD10-0.4',
  1522. 'Diagnoses - main ICD10-0.5',
  1523. 'Diagnoses - main ICD10-0.6',
  1524. 'Diagnoses - main ICD10-0.7',
  1525. 'Diagnoses - main ICD10-0.8',
  1526. 'Diagnoses - main ICD10-0.9',
  1527. 'Diagnoses - main ICD10-0.10',
  1528. 'Diagnoses - main ICD10-0.11',
  1529. 'Diagnoses - main ICD10-0.12',
  1530. 'Diagnoses - main ICD10-0.13',
  1531. 'Diagnoses - main ICD10-0.14',
  1532. 'Diagnoses - main ICD10-0.15',
  1533. 'Diagnoses - main ICD10-0.16',
  1534. 'Diagnoses - main ICD10-0.17',
  1535. 'Diagnoses - main ICD10-0.18',
  1536. 'Diagnoses - main ICD10-0.19',
  1537. 'Diagnoses - main ICD10-0.20',
  1538. 'Diagnoses - main ICD10-0.21',
  1539. 'Diagnoses - main ICD10-0.22',
  1540. 'Diagnoses - main ICD10-0.23',
  1541. 'Diagnoses - main ICD10-0.24',
  1542. 'Diagnoses - main ICD10-0.25',
  1543. 'Diagnoses - main ICD10-0.26',
  1544. 'Diagnoses - main ICD10-0.27',
  1545. 'Diagnoses - main ICD10-0.28',
  1546. 'Diagnoses - main ICD10-0.29',
  1547. 'Diagnoses - main ICD10-0.30',
  1548. 'Diagnoses - main ICD10-0.31',
  1549. 'Diagnoses - main ICD10-0.32',
  1550. 'Diagnoses - main ICD10-0.33',
  1551. 'Diagnoses - main ICD10-0.34',
  1552. 'Diagnoses - main ICD10-0.35',
  1553. 'Diagnoses - main ICD10-0.36',
  1554. 'Diagnoses - main ICD10-0.37',
  1555. 'Diagnoses - main ICD10-0.38',
  1556. 'Diagnoses - main ICD10-0.39',
  1557. 'Diagnoses - main ICD10-0.40',
  1558. 'Diagnoses - main ICD10-0.41',
  1559. 'Diagnoses - main ICD10-0.42',
  1560. 'Diagnoses - main ICD10-0.43',
  1561. 'Diagnoses - main ICD10-0.44',
  1562. 'Diagnoses - main ICD10-0.45',
  1563. 'Diagnoses - main ICD10-0.46',
  1564. 'Diagnoses - main ICD10-0.47',
  1565. 'Diagnoses - main ICD10-0.48',
  1566. 'Diagnoses - main ICD10-0.49',
  1567. 'Diagnoses - main ICD10-0.50',
  1568. 'Diagnoses - main ICD10-0.51',
  1569. 'Diagnoses - main ICD10-0.52',
  1570. 'Diagnoses - main ICD10-0.53',
  1571. 'Diagnoses - main ICD10-0.54',
  1572. 'Diagnoses - main ICD10-0.55',
  1573. 'Diagnoses - main ICD10-0.56',
  1574. 'Diagnoses - main ICD10-0.57',
  1575. 'Diagnoses - main ICD10-0.58',
  1576. 'Diagnoses - main ICD10-0.59',
  1577. 'Diagnoses - main ICD10-0.60',
  1578. 'Diagnoses - main ICD10-0.61',
  1579. 'Diagnoses - main ICD10-0.62',
  1580. 'Diagnoses - main ICD10-0.63',
  1581. 'Diagnoses - main ICD10-0.64',
  1582. 'Diagnoses - main ICD10-0.65',
  1583. 'Diagnoses - main ICD10-0.66',
  1584. 'Diagnoses - main ICD10-0.67',
  1585. 'Diagnoses - main ICD10-0.68',
  1586. 'Diagnoses - main ICD10-0.69',
  1587. 'Diagnoses - main ICD10-0.70',
  1588. 'Diagnoses - main ICD10-0.71',
  1589. 'Diagnoses - main ICD10-0.72',
  1590. 'Diagnoses - main ICD10-0.73',
  1591. 'Diagnoses - main ICD10-0.74',
  1592. 'Diagnoses - main ICD10-0.75',
  1593. 'Diagnoses - main ICD10-0.76',
  1594. 'Diagnoses - main ICD10-0.77',
  1595. 'Diagnoses - main ICD10-0.78',
  1596. 'Diagnoses - main ICD10-0.79']
  1597. # F
  1598. diagnoses_main_icd["all_diag"] = diagnoses_main_icd[diag_cols].astype(str).apply(lambda x: x.str.cat(sep=","), axis=1)
  1599. diagnoses_main_icd["F0 Organic (incl. symptomatic, mental disorders)"] = diagnoses_main_icd["all_diag"].str.contains("F0").astype(int)
  1600. diagnoses_main_icd["F1 Mental and behavioural disorders due to psychoactive substance use"] = diagnoses_main_icd["all_diag"].str.contains("F1").astype(int)
  1601. diagnoses_main_icd["F2 Schizophrenia, schizotypal and delusional disorders"] = diagnoses_main_icd["all_diag"].str.contains("F2").astype(int)
  1602. diagnoses_main_icd["F3 Mood [affective] disorders"] = diagnoses_main_icd["all_diag"].str.contains("F3").astype(int)
  1603. diagnoses_main_icd["F4 Neurotic, stress-related and somatoform disorders"] = diagnoses_main_icd["all_diag"].str.contains("F4").astype(int)
  1604. diagnoses_main_icd["F5 Behavioural syndromes associated with physiological disturbances and physical factors"] = diagnoses_main_icd["all_diag"].str.contains("F5").astype(int)
  1605. diagnoses_main_icd["F6 Disorders of adult personality and behaviour"] = diagnoses_main_icd["all_diag"].str.contains("F6").astype(int)
  1606. diagnoses_main_icd["F7 Mental retardation"] = diagnoses_main_icd["all_diag"].str.contains("F7").astype(int)
  1607. diagnoses_main_icd["F8 Disorders of psychological development"] = diagnoses_main_icd["all_diag"].str.contains("F8").astype(int)
  1608. diagnoses_main_icd["F90-F98 Behavioural and emotional disorders with onset usually occurring in childhood and adolescence"] = diagnoses_main_icd["all_diag"].str.contains("F9[0-8]").astype(int)
  1609. diagnoses_main_icd["F99 Unspecified mental disorder"] = diagnoses_main_icd["all_diag"].str.contains("F99").astype(int)
  1610. # G
  1611. diagnoses_main_icd["G0 Inflammatory diseases of the central nervous system"] = diagnoses_main_icd["all_diag"].str.contains("G0").astype(int)
  1612. diagnoses_main_icd["G1 Systemic atrophies primarily affecting the central nervous system"] = diagnoses_main_icd["all_diag"].str.contains("G1").astype(int)
  1613. diagnoses_main_icd["G2 Extrapyramidal and movement disorders"] = diagnoses_main_icd["all_diag"].str.contains("G2").astype(int)
  1614. diagnoses_main_icd["G30-G32 Other degenerative diseases of the nervous system"] = diagnoses_main_icd["all_diag"].str.contains("G3[0-2]").astype(int)
  1615. diagnoses_main_icd["G35-G37 Demyelinating diseases of the central nervous system"] = diagnoses_main_icd["all_diag"].str.contains("G3[5-7]").astype(int)
  1616. diagnoses_main_icd["G4 Episodic and paroxysmal disorders"] = diagnoses_main_icd["all_diag"].str.contains("G4").astype(int)
  1617. diagnoses_main_icd["G5 Nerve, nerve root and plexus disorders"] = diagnoses_main_icd["all_diag"].str.contains("G5").astype(int)
  1618. diagnoses_main_icd["G6 Polyneuropathies and other disorders of the peripheral nervous system"] = diagnoses_main_icd["all_diag"].str.contains("G6").astype(int)
  1619. diagnoses_main_icd["G7 Diseases of myoneural junction and muscle"] = diagnoses_main_icd["all_diag"].str.contains("G7").astype(int)
  1620. diagnoses_main_icd["G8 Cerebral palsy and other paralytic syndromes"] = diagnoses_main_icd["all_diag"].str.contains("G8").astype(int)
  1621. diagnoses_main_icd["G9 Other disorders of the nervous system"] = diagnoses_main_icd["all_diag"].str.contains("G9").astype(int)
  1622. # Combine diagnoses
  1623. diagnoses_main_icd["Diagnoses 'F'"] = diagnoses_main_icd[['F0 Organic (incl. symptomatic, mental disorders)',
  1624. 'F1 Mental and behavioural disorders due to psychoactive substance use',
  1625. 'F2 Schizophrenia, schizotypal and delusional disorders',
  1626. 'F3 Mood [affective] disorders',
  1627. 'F4 Neurotic, stress-related and somatoform disorders',
  1628. 'F5 Behavioural syndromes associated with physiological disturbances and physical factors',
  1629. 'F6 Disorders of adult personality and behaviour',
  1630. 'F7 Mental retardation',
  1631. 'F8 Disorders of psychological development',
  1632. 'F90-F98 Behavioural and emotional disorders with onset usually occurring in childhood and adolescence',
  1633. 'F99 Unspecified mental disorder']].sum(axis=1).astype(int)
  1634. diagnoses_main_icd["Diagnoses 'G'"] = diagnoses_main_icd[["G0 Inflammatory diseases of the central nervous system",
  1635. "G1 Systemic atrophies primarily affecting the central nervous system",
  1636. "G2 Extrapyramidal and movement disorders",
  1637. "G30-G32 Other degenerative diseases of the nervous system",
  1638. "G35-G37 Demyelinating diseases of the central nervous system",
  1639. "G4 Episodic and paroxysmal disorders",
  1640. "G5 Nerve, nerve root and plexus disorders",
  1641. "G6 Polyneuropathies and other disorders of the peripheral nervous system",
  1642. "G7 Diseases of myoneural junction and muscle",
  1643. "G8 Cerebral palsy and other paralytic syndromes",
  1644. "G9 Other disorders of the nervous system"]].sum(axis=1).astype(int)
  1645. diagnoses_main_icd_FG = diagnoses_main_icd[['eid', "Diagnoses 'F'", "Diagnoses 'G'"]]
  1646. diagnoses_main_icd_FG.to_csv('/UK_BB/diagnoses/diagnoses_main_icd_FG.csv', index=False)
  1647. # %% [markdown]
  1648. # # Merge Diagnoses with Scores and rename
  1649. # %%
  1650. mh_full = mh_main.drop(columns=['AUDIT','AUDIT_C','AUDIT_P'])
  1651. mh_full = pd.merge(mh_full, diagnoses_main_icd_FG, on = 'eid')
  1652. mh_full.to_csv('/UK_BB/mental_health/mental_health_full.csv')
  1653. mh_full.shape
  1654. # %%
  1655. mh_full.columns.to_list()
  1656. # %%
  1657. # Rename columns
  1658. new_names = ['eid',
  1659. 'Diagnoses: Anxiety/panic attacks',
  1660. 'NS-12',
  1661. 'PCL-6',
  1662. 'PHQ-9',
  1663. 'PDS',
  1664. 'RDS-4',
  1665. 'Diagnoses: Depression',
  1666. 'Self-harm: Ever thought life not worth living',
  1667. 'Ever attempted suicide',
  1668. 'Ever self-harmed',
  1669. 'Ever self-harmed (non-suicidal)',
  1670. 'Unusual experience',
  1671. 'Recent unusual experience',
  1672. 'Repeated disturbing thoughts of stressful experience in past month',
  1673. 'Felt very upset when reminded of stressful experience in past month',
  1674. 'Avoided activities or situations because of previous stressful experience in past month',
  1675. "Frequency of 'life not worth living' thoughts",
  1676. 'Lifetime frequency of contemplating self-harm',
  1677. 'Ever had prolonged feelings of sadness or depression',
  1678. 'Ever had prolonged loss of interest in normal activities',
  1679. 'Ever felt worried, tense, or anxious for most of a month or longer',
  1680. 'Ever worried more than most people would in similar situation',
  1681. 'Ever addicted to any substance or behaviour',
  1682. 'Ever believed in an un-real conspiracy against self',
  1683. 'Ever believed in un-real communications or signs',
  1684. 'Ever heard an un-real voice',
  1685. 'Ever seen an un-real vision',
  1686. 'Mood swings',
  1687. 'Miserableness',
  1688. 'Irritability',
  1689. 'Sensitivity / hurt feelings',
  1690. 'Fed-up feelings',
  1691. 'Nervous feelings',
  1692. 'Worrier / anxious feelings',
  1693. "Tense / 'highly strung'",
  1694. 'Worry too long after embarrassment',
  1695. "Suffer from 'nerves'",
  1696. 'Loneliness, isolation',
  1697. 'Guilty feelings',
  1698. 'Risk taking',
  1699. 'Frequency of depressed mood in last 2 weeks',
  1700. 'Frequency of unenthusiasm / disinterest in last 2 weeks',
  1701. 'Frequency of tenseness / restlessness in last 2 weeks',
  1702. 'Frequency of tiredness / lethargy in last 2 weeks',
  1703. 'Seen a psychiatrist for nerves, anxiety, tension or depression',
  1704. 'Seen doctor (GP) for nerves, anxiety, tension or depression',
  1705. 'Ever depressed for a whole week',
  1706. 'Ever unenthusiastic/disinterested for a whole week',
  1707. 'Ever highly irritable/argumentative for 2 days',
  1708. 'Ever manic/hyper for 2 days',
  1709. 'Diagnoses: Neurological problem, NS injury, epilepsy',
  1710. 'Diagnoses: Stress, insomnia, migraine, nervous/mental problems',
  1711. 'Ever had period of mania / excitability',
  1712. 'Ever had period extreme irritability',
  1713. 'Recent feelings of inadequacy',
  1714. 'Recent trouble concentrating on things',
  1715. 'Recent feelings of depression',
  1716. 'Recent poor appetite or overeating',
  1717. 'Recent thoughts of suicide or self-harm',
  1718. 'Recent lack of interest or pleasure in doing things',
  1719. 'Trouble falling or staying asleep, or sleeping too much',
  1720. 'Recent changes in speed/amount of moving or speaking',
  1721. 'Recent feelings of tiredness or low energy',
  1722. 'Depression ever',
  1723. 'Subthreshold depression',
  1724. 'Bipolar I',
  1725. 'Bipolar II',
  1726. 'Depression single episode',
  1727. 'Recurrent depression',
  1728. 'Depression triggered by loss',
  1729. 'Current depression',
  1730. 'Current severe depression',
  1731. # Mania score
  1732. 'Recent easy annoyance or irritability',
  1733. 'Recent feelings or nervousness or anxiety',
  1734. 'Recent inability to stop or control worrying',
  1735. 'Recent feelings of foreboding',
  1736. 'Recent trouble relaxing',
  1737. 'Recent restlessness',
  1738. 'Recent worrying too much about different things',
  1739. 'GAD-7',
  1740. 'GAD ever',
  1741. 'Current GAD',
  1742. 'Current GAD mild',
  1743. 'Current GAD moderate',
  1744. 'Current GAD severe',
  1745. 'PTSD',
  1746. 'Amount of alcohol drunk on a typical drinking day',
  1747. 'Frequency of drinking alcohol',
  1748. 'Frequency of consuming six or more units of alcohol',
  1749. '(log)AUDIT',
  1750. '(log)AUDIT-C',
  1751. '(log)AUDIT-P',
  1752. 'Hazardous alcohol use (AUDIT≥8)',
  1753. 'Alcohol dependence (AUDIT≥15)',
  1754. 'General happiness',
  1755. 'General happiness with own health',
  1756. 'Belief that own life is meaningful',
  1757. 'Felt hated by family member as a child',
  1758. 'Physically abused by family as a child',
  1759. 'Felt loved as a child',
  1760. 'Sexually molested as a child',
  1761. 'Someone to take to doctor when needed as a child',
  1762. 'Ever sought or received professional help for mental distress',
  1763. 'Ever suffered mental distress preventing usual activities',
  1764. 'Belittlement by partner or ex-partner as an adult',
  1765. 'Been in a confiding relationship as an adult',
  1766. 'Physical violence by partner or ex-partner as an adult',
  1767. 'Sexual interference by partner or ex-partner without consent as an adult',
  1768. 'Able to pay rent/mortgage as an adult',
  1769. 'Been in serious accident believed to be life-threatening',
  1770. 'Been involved in combat or exposed to war-zone',
  1771. 'Diagnosed with life-threatening illness',
  1772. 'Victim of physically violent crime',
  1773. 'Witnessed sudden violent death',
  1774. 'Victim of sexual assault',
  1775. # Addiction ever
  1776. 'Physical alcohol dependence ever',
  1777. 'Substance addiction',
  1778. 'Current addiction',
  1779. 'Cannabis ever',
  1780. 'Lifertime frequency of taking cannabis',
  1781. 'Cannabis daily',
  1782. 'Childhood adverse events',
  1783. 'Adult adverse events',
  1784. 'Catastrophic trauma',
  1785. 'Wellbeing',
  1786. 'Any distress',
  1787. 'Friendships satisfaction',
  1788. 'Financial situation satisfaction',
  1789. 'Happiness',
  1790. 'Family relationship satisfaction',
  1791. 'Health satisfaction',
  1792. 'Mental and behavioural disorders',
  1793. 'Diseases of the nervous system'
  1794. ]
  1795. mh_rename = mh_full.copy()
  1796. mh_rename.columns = new_names
  1797. mh_rename.to_csv('/Cog-Ment/CSVs/2024/mental_health/mental_health_full_renamed.csv', index=False)

01_GetMHData.ipynb at commit 633419e, under MIT · at the source

Overview

  1. Department of Psychology, University of Otago Dunedin New Zealand
  2. Federal University of the São Francisco Valley Petrolina Brazil
  3. National Institute of Social and Affective Neuroscience Petrolina Brazil
  4. School of Computing, University of Otago Dunedin New Zealand
Journal: eLife, volume 14, article RP108109
Dates: published online 20 May 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.7554/elife.108109 · PMID 42160203 · PMCID PMC13189626 · OpenAlex W4414263040
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: structural MRI / diffusion (modality), human (organism), cognitive (subfield)
Methods: Connectivity, Smoothing, state filtering, decompositions, Machine learning, Statistics, Preprocessing, Evoked potentials, fMRI & imaging, Physiology & signal measures
Keywords: cognition, mental health, neuroimaging, MRI, machine learning, Human
MeSH: Cognition*, Magnetic Resonance Imaging*, Mental Health*, Biological Specimen Banks, Brain, Female, Humans, Machine Learning, Male, Neuroimaging, UK Biobank, United Kingdom (* major topic)
Journal subjects: Neuroscience
Topic: Functional Brain Connectivity Studies (Cognitive Neuroscience, Neuroscience), according to OpenAlex
Funding: Health Research Council of New Zealand (21/618, 24/838); Neurological Foundation of New Zealand (2350 PRG); Ministry of Business, Innovation and Employment (UOA2421, RTVU2403); University of Otago (The University of Otago Doctoral Scholarship)
Citations: cited by 2 papers (Europe PMC); 236 references in the paper

Abstract

Cognitive dysfunction often co-occurs with psychopathology. Advances in neuroimaging and machine learning have led to neural indicators that predict individual differences in cognition with reasonable performance. We examined whether these indicators explain the relationship between cognition and mental health in the UK Biobank (n>14,000). Using machine learning, we quantified the covariation between cognition and 133 mental health indices and derived neural indicators of cognition from 72 neuroimaging phenotypes across diffusion-weighted MRI (dwMRI), resting-state functional MRI (rsMRI), and structural MRI (sMRI). With commonality analyses, we investigated how much of the cognition–mental health covariation is captured by each indicator and neural indicators combined within and across MRI modalities. The predictive association between mental health and cognition was at r=0.3. Neuroimaging captured 2.1 to 25.8% of the cognition-mental health covariation. Combining phenotypes within modalities improved the explanation to 25.5% for dwMRI, 29.8% for rsMRI, and 31.6% for sMRI, and combining them across modalities enhanced the explanation to 48%. We present an integrated approach to derive multimodal MRI markers of cognition that can be transdiagnostically linked to psychopathology, demonstrating that the predictive ability of neural indicators extends beyond the prediction of cognition itself, enabling us to capture cognition-mental health covariation.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repository

Its files are read in the Code ↔ Paper reader above, with 18 matches between paragraphs and lines of code.

HAM-lab-Otago-University/UKBiobank

License: MIT
State: the link answers, verified on 28 September 2026
Evidence: files inventoried
Commit: 633419e8593d3d768c719f0e81d58dd6e345ce7c, 20 May 2026
Languages: Jupyter (27), R (3)
Size: 33 files, 30 scripts
Software Heritage: not archived
Found in: “Data availability”
Holds: README, license file, 30 notebooks
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Tools: pandas (11 files), NumPy (10 files), Matplotlib (6 files), SciPy (6 files), scikit-learn (5 files), seaborn (5 files), data.table (2 files), ggplot2 (2 files), lavaan (2 files), psych (2 files)
Availability: 1 check, the latest on 28 September 2026: the link answers
  • 28 September 2026: the link answers
14 files

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 14 scripts, each with its path and the digest of its content;
  • 18 matches between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

Datasets cited

Data availability

This study used data from the UK Biobank resource (Application No. 70132). These data cannot be publicly shared by the authors due to legal and ethical restrictions imposed by UK Biobank. Access to individual-level data is governed by UK Biobank's data access policies, which are designed to protect participant confidentiality. Researchers can access the data by submitting an application directly to UK Biobank (https://www.ukbiobank.ac.uk/enable-your-research/apply-for-access). Applications must include a research proposal outlining the scientific rationale and intended use of the data, and are reviewed as part of UK Biobank's access procedures. Access may be granted to approved researchers from academic, charity, government, and commercial organisations, subject to UK Biobank's terms and conditions. Due to these restrictions, we are not permitted to share raw or deidentified individual-level data. Redistribution of such data is contractually prohibited, and deidentification does not eliminate the risk of participant re-identification. This manuscript is a computational study and did not generate new primary data. Numerical data underlying the figures are provided as figure source data files. All analyses can be reproduced using the code provided by the authors. The modelling and analysis code is openly available on GitHub: https://github.com/HAM-lab-Otago-University/UKBiobank/ (copy archived at Buianova, 2026).

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 28 September 2026: the first record

Recorded: type, language, journal, volume, pages, dates, 4 authors, 6 keywords, 12 MeSH terms, 4 funders, 228 references.

Cite

This paper

Buianova, I., Silvestrin, M., Deng, J. D., & Pat, N. (2026). Multimodal MRI marker of cognition explains the association between cognition and mental health in the UK Biobank. eLife, 14, RP108109. https://doi.org/10.7554/elife.108109

BibTeX

@article{buianova2026multimodal,
author = {Buianova, Irina and Silvestrin, Mateus and Deng, Jeremiah D and Pat, Narun},
title = {{Multimodal MRI marker of cognition explains the association between cognition and mental health in the UK Biobank}},
journal = {eLife},
year = {2026},
month = may,
volume = {14},
pages = {RP108109},
publisher = {eLife Sciences Publications, Ltd},
issn = {2050-084X},
doi = {10.7554/elife.108109},
url = {https://doi.org/10.7554/elife.108109},
pmid = {42160203},
pmcid = {PMC13189626}
}

RIS

TY - JOUR
AU - Buianova, Irina
AU - Silvestrin, Mateus
AU - Deng, Jeremiah D
AU - Pat, Narun
TI - Multimodal MRI marker of cognition explains the association between cognition and mental health in the UK Biobank
T2 - eLife
J2 - Elife
PY - 2026
DA - 2026/05/20
VL - 14
SP - RP108109
SN - 2050-084X
PB - eLife Sciences Publications, Ltd
DO - 10.7554/elife.108109
UR - https://doi.org/10.7554/elife.108109
LA - en
ER -

CSL-JSON

{
"id": "10.7554/elife.108109",
"type": "article-journal",
"title": "Multimodal MRI marker of cognition explains the association between cognition and mental health in the UK Biobank",
"container-title": "eLife",
"author": [
{
"family": "Buianova",
"given": "Irina"
},
{
"family": "Silvestrin",
"given": "Mateus"
},
{
"family": "Deng",
"given": "Jeremiah D"
},
{
"family": "Pat",
"given": "Narun"
}
],
"container-title-short": "Elife",
"volume": "14",
"page": "RP108109",
"DOI": "10.7554/elife.108109",
"PMID": "42160203",
"PMCID": "PMC13189626",
"ISSN": "2050-084X",
"publisher": "eLife Sciences Publications, Ltd",
"URL": "https://doi.org/10.7554/elife.108109",
"language": "en",
"issued": {
"date-parts": [
[
2026,
5,
20
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41514-026-00456-9 [code]
Exploring the link between body physiology and cognition: the role of the brain and aging.
Journal: npj aging
In common: lavaan, psych, data.table, 7 other tools, cognitive, 34 references
[2] doi:10.1038/s44220-026-00680-y [code]
The neuroimaging correlates of depression established across six large-scale population datasets.
Journal: Nature. Mental health
In common: ggplot2, seaborn, scikit-learn, 4 other tools, ukbiobank.ac.uk/enable-your-research/apply-for-access, 9 references
[3] doi:10.1162/imag.a.1325 [code]
Decoding everyday levels of musical training from subcortical white-matter architecture.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: lavaan, psych, ggplot2, 5 other tools, structural MRI / diffusion, 8 references
[4] doi:10.1038/s41467-026-75661-x [code]
A neural signature of sleep deprivation in the human brain.
Journal: Nature communications
In common: seaborn, scikit-learn, pandas, 3 other tools, ukbiobank.ac.uk/enable-your-research/apply-for-access, cognitive, 7 references
[5] doi:10.1126/sciadv.aec2348 [code]
Congenital blindness reduces myelination in human visual cortex.
Journal: Science advances
In common: lavaan, data.table, ggplot2, 2 other tools, structural MRI / diffusion, 8 references
[6] doi:10.1162/imag.a.1308 [code]
Functional connectome signature of general psychopathology in middle-aged and older adults: Evidence from multi-cohort, multi-ethnic analyses.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: ggplot2, 10 references
[7] doi:10.1038/s41467-026-73668-y [code]
Convergent and divergent brain-cognition development in early adolescence.
Journal: Nature communications
In common: ggplot2, seaborn, scikit-learn, 4 other tools, 7 references
[8] doi:10.1038/s41467-026-73072-6 [code]
Mapping the spatiotemporal continuum of structural connectivity development across the human connectome in youth.
Journal: Nature communications
In common: psych, ggplot2, pandas, 1 other tool, structural MRI / diffusion, 9 references
[9] doi:10.1038/s42003-026-09956-6 [code]
Linking changes in sulcal morphometry to cognitive development from childhood to adolescence.
Journal: Communications biology
In common: psych, ggplot2, seaborn, 5 other tools, structural MRI / diffusion, 5 references
[10] doi:10.7554/elife.103097 [code]
Canonical neurodevelopmental trajectories of structural and functional manifolds.
Journal: eLife
In common: data.table, ggplot2, scikit-learn, 3 other tools, structural MRI / diffusion, 7 references

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.