  Background: Mental illness can lead to adverse outcomes such as homelessness
and police interaction and understanding of the events leading up to these
adverse outcomes is important. Predictive models may help identify individuals
at risk of such adverse outcomes. Using a fixed observation window cohort with
logistic regression (LR) or machine learning (ML) models can result in lower
performance when compared with adaptive and parcellated windows.
  Method: An administrative healthcare dataset was used, comprising of 240,219
individuals in Calgary, Alberta, Canada who were diagnosed with addiction or
mental health (AMH) between April 1, 2013, and March 31, 2018. The cohort was
followed for 2 years to identify factors associated with homelessness and
police interactions. To understand the benefit of flexible windows to
predictive models, an alternative cohort was created. Then LR and ML models,
including random forests (RF), and extreme gradient boosting (XGBoost) were
compared in the two cohorts.
  Results: Among 237,602 individuals, 0.8% (1,800) experienced first
homelessness, while 0.32% (759) reported initial police interaction among
237,141 individuals. Male sex (AORs: H=1.51, P=2.52), substance disorder (AORs:
H=3.70, P=2.83), psychiatrist visits (AORs: H=1.44, P=1.49), and drug abuse
(AORs: H=2.67, P=1.83) were associated with initial homelessness (H) and police
interaction (P). XGBoost showed superior performance using the flexible method
(sensitivity =91%, AUC =90% for initial homelessness, and sensitivity =90%,
AUC=89% for initial police interaction)
  Conclusion: This study identified key features associated with initial
homelessness and police interaction and demonstrated that flexible windows can
improve predictive modeling.
