## 2 Materials and Methods
(**Step 3a–e**) —Model building and testing on training data I: Imputation by mean/mode; up-sampling of outcome “violent behavior” \(\times\) 2; variable reduction via random forest; model building via ML algorithms —logistic regression, trees, random forest, gradient boosting, KNN (k-nearest neighbor), support vector machines (SVM) and naive Bayes; testing (selection) of best ML algorithm via ROC parameters. (**Step 4**)—Model building and testing on training data II: Nested resampling with imputation, up-sampling, variable reduction, and model building in inner loop and model testing on the outer loop. (**Step 5**)—Model building and testing on validation data I: Imputation with stored weights from Step 3a. (**Step 6**)—Model building and testing on validation data II: Best model identified in Step 3e applied on imputed and validation dataset and evaluated via ROC parameters. (**Step 7**)—Ranking of variables by indicative power. information on the broader biographical history of patients, although forensic records were comprehensive. Variables with more than 33% missing values were eliminated, leaving a set of 508 variables. The outcome variable \"aggressive behavior during current hospitalization\" was dichotomized into (1) \"aggressive behavior\" and (0) \"no aggressive behavior\". Acts of aggression were defined as either verbal or physical attacks aimed toward staff or other patients, as well as damage of property. After the exclusion of all patients with missing information regarding their aggressive behavior from further analysis, a total of 352 patients remained. Out of these patients, 113 (32.1%) were involved in an aggressive event, while 239 (67.9%) were not (see Table 1). \"No Aggression\" was defined as the positive class, \"Aggression\" as the negative class. After the completion of data preparation, the database was divided into one training and one validation subset (see Figure 1, Step 2). The training subset, including 70% of all cases (\(n=246\)), was used for variable reduction and model building/selection. To enable the flexible application of all ML algorithms, imputation of missing values was carried out and imputation weights saved for later were reused on the validation subset (see Figure 1, Step 3a). As the outcome variable was unevenly distributed (12.4:87.6%), a random upsampling at a rate of 2 was conducted, leading to a more balanced outcome (see Figure 1, Step 3b). A major objective of the present study was to identify the most important predictor variables from 507 possible variables. Additionally, a decrease in variables can counteract overfitting and maintain computing times in initial model building at an acceptable level. For this purpose, variable reduction to the 10 most important predictors was performed using randomForestSRC implemented in the MLR package (see Figure 1, Step 3c). As the database was relatively small for ML purposes and our focus lay on variable extraction and prediction, we applied discriminative model building with logistic regression, trees, random forest, gradient boosting, KNN (k-nearest neighbor), support vector machines (SVM), and as an easily applicable generative model building, naive Bayes (see Figure 1, Step 3d). No hyperparameters were optimized. The model performance of each model was calculated and assessed in terms of its balanced accuracy (the average of true positive and true negative rate, better suited for model evaluation and calculation of confidence intervals in imbalanced data) and goodness of fit (measured with the receiver operating characteristic, balanced curve area under the curve method, ROC balanced AUC). Specificity, sensitivity, positive predictive value (PPV), and negative predictive value (NPV) were also evaluated. As our training dataset was artificially balanced, the model with the highest AUC was chosen for final model validation with the test subset (see Figure 1, Step 3e). The set of identified variables was tested for multicollinearity to avoid dependencies between the variables.