TITLE: Workflow for beta-range forest plots, bootstrap ridgeline plots, and bootstrap violin plots
AUTHORS: Jonathan Fries, Sandra Oberleiter, Jakob Pietschnig

[DESCRIPTION]
Regression is a widely used statistical method in various research areas, such as educational psychology, and it is common to display regression coefficients in tables. Although tables contain dense information, they can be difficult to read and interpret when they are extensive. To address this issue, we present three innovative visualizations that enable researchers to present a large number of regression models in a single plot. We demonstrate how to transform simulated data and plot the results, which produce visually appealing representations of regression results that are both efficient and intuitive. These visualizations can be applied for screening models in the selection stage or reporting results in research papers. Our method is reproducible using the provided code and can be implemented using free and open-source software routines in R.

[GUIDELINES]
Get R:
The statistical programming environment can be downloaded free-of-charge at https://cran.r-project.org.




[STEPS]
SECTION: Packages
1. The following workflow requires the statistical programming environment R (at least version 4.2.2). Before running any command prompts, some packages need to be installed. To this end, we create a vector that contains the respective package names and run a for loop that only installs packages that are not already installed.

 

Next, we load the required packages.

 

SECTION: Custom functions
2. To demonstrate the new data visualization techniques, we simulate data. For this purpose, some custom functions are defined beforehand.

 

SECTION: Data simulation
3. Now, we begin the data simulation process.

SECTION: Data simulation
3.2. We create a dataframe that contains names and distribution parameters for the variables that we intend to simulate. Here, we chose to demonstrate our method using a fictional dataset of decathlon results. Decathlon is a combination athletics discipline. Over the course of two days, each athlete competes in ten track and field events (100 meters race, long jump, shot-put, high jump, 400 meters race, 110 meters hurdles, discus, pole-vault, javelin, and 1500 meters race).

 

SECTION: Data simulation
3.1. A random seed is defined first; this step ensures that the results are exactly replicable. If replicability is of no concern, this command may be removed.


 

SECTION: Data simulation
3.3. The simulated decathlon results are expected to be intercorrelated. Thus, we define a matrix of correlations between the variables that we intend to simulate and convert it to a covariance matrix.


 

SECTION: Data simulation
3.4. Using this covariance matrix, we now generate correlated decathlon results for 10,000 fictional athletes


 

SECTION: Data simulation
3.5. Some of the generated values are outside the range  of human physical capability. To address this, we truncate the results to stay within reasonable boundaries. A custom function is applied within a for loop.

 

SECTION: Data simulation
3.6. We now have one data point for each decathlon discipline for each of the 10,000 fictional athletes. However, we aim to simulate 4 additional data points for each athlete. We use a custom function that was defined above (section "Custom functions") within a for for loop to simulate additional observations. This results in 5 data points in each decathlon sub-discipline for each athlete.

 

SECTION: Data simulation
3.7. Simulation of athletics results is now completed. Next, some predictors are needed. We chose to use fictional data of seven hematological indices (ferritin, haptoglobin, hematocrit, hemoglobin, iron, red blood cell count, and transferrin) that have been demonstrated to be associated with sports performance. For each hematological index, we simulate normally distributed data that exhibit pre-defined correlations with some of the decathlon events.

 

SECTION: Data simulation
3.8. Data simulation is complete. To tidy up the data, we re-order the dataframe columns.


 

SECTION: Data simulation
3.9. To visualize the correlation structure of the dataframe, we create a (Pearson) correlation heatmap of all variables.


 

  

SECTION: Regression
4. Next, we intend to predict decathlon outcomes from hematological indices. We model these relationships using a single-predictor linear regression framework.
SECTION: Regression
4.1. The dataset needs to be converted to long format. The conversion is carried out using the melt command from the data.table package.


 

SECTION: Regression
4.2. Now, we run regressions in batch using data.table, resulting in 350 regression models stored in a separate dataframe.

 

SECTION: Data visualization
5. Before we can visualize the regression models, some data modifications are necessary. Using standard visualization approaches, it would be next to impossible to create an efficient plot for such a large number of models. Here, we achieve this by summarizing the regression results as follows.
SECTION: Data visualization
5.1. First, we create a variable that allocates all five models for each discipline into one category (e.g., "hundred_m_01", ..., "hundred_m_05" are put in the category "hundred_m". This category variable is named "domain".

 

SECTION: Data visualization
5.2. Next, we create a dataframe that contains the lower and upper limits of the point estimate range for each domain category, as well as outer limits of the confidence intervals. An empty (container) dataframe is created to which we add the desired parameters. Subsequently, the new dataframe is tidied up.

 

SECTION: Data visualization
5.3. The forest plot modifications we will produce in the following steps feature a coordinate system that is flipped clockwise. This requires the factor levels of some variables to be reversed to ensure they are correctly displayed in the final plot.


 

SECTION: Data visualization
5.4. Before plotting, some text settings (ggplot) are defined that we will use for all plots.


 

SECTION: Data visualization
5.5. All necessary data modifications are complete. We now create the beta-range forest plot.


 

  

SECTION: Data visualization
6. This data visualization relies on boxplot-like indicators for point estimate ranges as well as confidence interval ranges. An alternative approach to visualizing regression models is to plot the bootstrapped distributions of point estimates.
SECTION: Data visualization
6.1. Thus, bootstrapped data points are required for each regression model. We begin by setting a random seed. As above, this step may be skipped.


 

SECTION: Data visualization
6.2. Next, we define a helper function for computing bootstrap estimates (returns point estimates of linear regression models).

 

SECTION: Data visualization
6.3. Bootstrap estimates are computed using a for loop and added to empty container dataframe. CAUTION: this computation is fairly lengthy, thus protected by hashes. If you wish to forgo computation of the bootstrap estimates, skip this step and directly import the dataset of bootstrapped parameter estimates (found in "Materials").


 

SECTION: Data visualization
6.4. If you wish to skip the computation of bootstrapped parameter estimates, the dataset can be directly imported. The file "S2_file.xlsx" can be found in "Materials".


 

SECTION: Data visualization
6.5. Analogous to the step 5.1, we create a category variable named "domain".


 

SECTION: Data visualization
6.6. The variable "predictor" needs to be converted to a factor.


 

SECTION: Data visualization
6.7. Analogous to Step 5.3, factor levels need to be reversed for correct display in the plot.


 

SECTION: Data visualization
6.8. Now, all preparatory computations are complete and the data is ready for plotting. We create a bootstrap ridgeline plot for all 350 regression models.


 

  

SECTION: Data visualization
7. To address the issue of overlapping density plots, we developed an alternative representation of the distributions of bootstrapped beta coefficients by making use of the violin plot. To create a bootstrap violin plot, the bootstrap dataset from before can be used without modifications.