Skip to main content
. 2020 May 13;22(5):545. doi: 10.3390/e22050545
Algorithm 2. Variable selection pseudocode.
input: List of all explanatory variables X, distance function dist(Ci,Cj), correlation matrix (M), target variable (y)
output: List of the best explanatory variables (B)
1:     create empty cluster list C
2:     for each j = 1 to p do
3:       create a cluster for each variable Cj={Xj}
4:     end
5:     calculate distance matrix D as 1|M|
6:     repeat
7:       di,jmin = find smallest element di,j in D for all Ci,CjC
8:       if di,jmin>0.9 then
9:         break repeat
10:     end
11:     merge cluster Cj and cluster Ci
12:     update distance matrix D
13:   end
14:   create empty MSE_list
15:   for each j = 1 to p do
16:     MSE = estimate mean square error of j-th variable for prediction of y
17:     update MSE_list based on MSE
18:   end
19:   for each CiC do
20:     select variable based on the MSE_list and add to B
21:   end
22:   return B