# Predicting Hospital Admissions to Reduce Crowding in the Emergency Departments
## 3 Method and Materials
### Model Fitting and Validation  
The models were trained on each of the five datasets described above using gradient boosting machine in R, using the \"gbm\", \"caret\", \"ROCR\" and \"pROC\" packages. Each of these datasets was divided into training sets and test sets, randomly sorting 70% of the observations to the former and the remaining 30% to the latter. The training set was used to build the model for the gradient boosting machine, analyze the variable importance in predicting the outcome, and test for overfitting. The test set was used to evaluate the predictive performance of the model trained with a confusion matrix from which to extract the performance parameters (accuracy, sensitivity, specificity, positive predictive value (PPV), and negative predictive value (NPV)) and create the receiver operating characteristic (ROC) curve, therefore obtaining the AUC for each of the models, with a 95% confidence interval obtained with the DeLong method [37].  
The gradient boosting models were developed with a Bernoulli distribution function since it was considered the best option to predict the binary response [38]. A total of 1000 trees were used to train all the models, with an interaction depth of 3 levels and a shrinkage equal to 0.01. To ensure that the trained models were not overfitted, a tuning process was performed for all of them using the exact same parameters and adding 2-fold cross-validation.  
Variable importance is an indicator of the information gain that a given variable provides in a split. The rank for variable importance was obtained for each of the models and used to create models including only the three most influential variables checking whether it was possible to obtain the same levels of predictive performance.  
Predictions for the accuracy testing were completed using 1000 trees as well and setting a threshold for prediction to 0.5; that is, if a prediction yielded a result with more than 50% probability of being an admission, it would be classified as an admission. Confusionmatrixes were obtained from the predicted results. Information about performance was also obtained from the receiver operating characteristic curve for each model, where the true positive rate was plotted against the false positive rate. Moreover, these curves allowed for the obtention of the area under the curve, which was provided with a 95% confidence interval following the method described by [PERSON] [37].  
With the same models used for the first part of the research, which targeted high-accuracy results, the second part of the study was approached. In this sense, the objective was to obtain high sensitivity levels (>0.975) while maintaining a specificity over 0.33. This was achieved by lowering the probability of admission required to classify an observation as such, and changing the range from 0.05 to 0.01 in order to predict as many admissions as possible.  
This procedure was conducted for each of the models until the required sensitivity level was obtained, and the specificity level was checked after reaching the critical point. These models presented a trade-off between the ability to detect 97.5% of all the observed admissions, and the ability to correctly predict as many outcomes as possible. As will be discussed below, targeting high sensitivity levels made the number of false positives increase substantially. These models would therefore not be adequate for implementation in the ED, for the staff would anticipate more admissions than really observed, and a lot of resources would be wasted in preparing for these false positives. However, these models can have a very high potential for implementation, not for hospital use but for patient use, to allow for the first contact between patient and ED, and regulate the number of patients self-referring to the ED for non-urgent causes. A more in-depth explanation has been developed in the discussion.