<figure><img src="image_255.png" /></figure>

```r
fviz_cluster(km.resdat1_7, data = dat1Clust,
  ellipse.type = "convex",
  palette = "jco",
  ggtheme = theme_minimal(),
  show.clust.cent = TRUE,
  main = "Cluster plot - 7 clusters")
```
<figure><img src="image_256.png" /><figcaption>Cluster plot - 7 clusters</figcaption></figure>

```r
fviz_cluster(km.resdat1_8, data = dat1Clust,
  ellipse.type = "convex",
  palette = "jco",
  ggtheme = theme_minimal(),
  show.clust.cent = TRUE,
  main = "Cluster plot - 8 clusters")
```
<figure><img src="image_257.png" /><figcaption>fviz_cluster(km.resdat1_9, data = dat1Clust,
ellipse.type = "convex",
palette = "jco",
ggtheme = theme_minimal(),
show.clust.cent = TRUE,
main = "Cluster plot - 9 clusters")</figcaption></figure>
<figure><img src="image_258.png" /><figcaption>Cluster plot - 9 clusters</figcaption></figure>

```r
eviz_cluster(km.resdat1_10, data = dat1Clust,
  ellipse.type = "convex",
  palette = "jco",
  ggtheme = theme_minimal(),
  show.clust.cent = TRUE,
  main = "Cluster plot - 10 clusters")
```
<figure><img src="image_259.png" /></figure>

### 7.5.1.4 Individual Clusters

```
sort(km.resdat1_2$cluster)
```

<table><tr><td>##</td><td>G_01</td><td>G_02</td><td>G_03</td><td>G_04</td><td>G_05</td><td>G_06</td><td>G_07</td><td>G_08</td><td>G_09</td><td>G_10</td><td>G_11</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_12</td><td>G_13</td><td>G_14</td><td>G_15</td><td>G_16</td><td>G_17</td><td>G_18</td><td>G_19</td><td>G_20</td><td>G_21</td><td>G_22</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_23</td><td>G_24</td><td>G_25</td><td>G_26</td><td>G_27</td><td>G_28</td><td>G_29</td><td>G_30</td><td>G_31</td><td>G_32</td><td>G_33</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_34</td><td>G_35</td><td>G_36</td><td>G_37</td><td>G_38</td><td>G_39</td><td>G_40</td><td>G_41</td><td>G_42</td><td>G_43</td><td>G_44</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_45</td><td>G_46</td><td>G_47</td><td>G_48</td><td>G_49</td><td>G_50</td><td>G_51</td><td>G_52</td><td>G_53</td><td>G_54</td><td>G_55</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_56</td><td>G_57</td><td>G_58</td><td>G_59</td><td>G_60</td><td>G_61</td><td>G_62</td><td>G_63</td><td>G_64</td><td>G_65</td><td>G_66</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_67</td><td>G_68</td><td>G_69</td><td>G_70</td><td>G_71</td><td>G_72</td><td>G_73</td><td>G_74</td><td>G_75</td><td>G_76</td><td>G_77</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_78</td><td>G_79</td><td>G_80</td><td>G_81</td><td>G_82</td><td>G_83</td><td>G_84</td><td>G_85</td><td>G_86</td><td>G_87</td><td>G_88</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_89</td><td>G_90</td><td>G_91</td><td>G_92</td><td>G_93</td><td>G_94</td><td>G_95</td><td>G_96</td><td>NG_01</td><td>NG_02</td><td>NG_03</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_04</td><td>NG_05</td><td>NG_06</td><td>NG_07</td><td>NG_08</td><td>NG_09</td><td>NG_10</td><td>NG_11</td><td>NG_12</td><td>NG_13</td><td>NG_14</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_15</td><td>NG_16</td><td>NG_17</td><td>NG_18</td><td>NG_19</td><td>NG_20</td><td>NG_21</td><td>NG_22</td><td>NG_23</td><td>NG_24</td><td>NG_25</td></tr></table>
<table><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_26</td><td>NG_27</td><td>NG_28</td><td>NG_29</td><td>NG_30</td><td>NG_31</td><td>NG_32</td><td>NG_33</td><td>NG_34</td><td>NG_35</td><td>NG_36</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_37</td><td>NG_38</td><td>NG_39</td><td>NG_40</td><td>NG_41</td><td>NG_42</td><td>NG_43</td><td>NG_44</td><td>NG_45</td><td>NG_46</td><td>NG_47</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_48</td><td>NG_49</td><td>NG_50</td><td>NG_51</td><td>NG_52</td><td>NG_53</td><td>NG_54</td><td>NG_55</td><td>NG_56</td><td>NG_57</td><td>NG_58</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_59</td><td>NG_60</td><td>NG_61</td><td>NG_62</td><td>NG_63</td><td>NG_64</td><td>NG_65</td><td>NG_66</td><td>NG_67</td><td>NG_68</td><td>NG_69</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_70</td><td>NG_71</td><td>NG_72</td><td>NG_73</td><td>NG_74</td><td>NG_75</td><td>NG_76</td><td>NG_77</td><td>NG_78</td><td>NG_79</td><td>NG_80</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_81</td><td>NG_82</td><td>NG_83</td><td>NG_84</td><td>NG_85</td><td>NG_86</td><td>NG_87</td><td>NG_88</td><td>NG_89</td><td>NG_90</td><td>NG_91</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_92</td><td>NG_93</td><td>NG_94</td><td>NG_95</td><td>NG_96</td><td>NG_97</td><td>NG_98</td><td>NG_99</td><td>NG_100</td><td>NG_101</td><td>NG_102</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_103</td><td>NG_104</td><td>NG_105</td><td>NG_106</td><td>NG_107</td><td>NG_108</td><td>NG_109</td><td>NG_110</td><td>NG_111</td><td>NG_112</td><td>NG_113</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_114</td><td>G_97</td><td>G_98</td><td>G_99</td><td>G_100</td><td>G_101</td><td>G_102</td><td>G_103</td><td>G_104</td><td>G_105</td><td>G_106</td></tr><tr><td>##</td><td>1</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_107</td><td>G_108</td><td>G_109</td><td>G_110</td><td>G_111</td><td>G_112</td><td>G_113</td><td>G_114</td><td>G_115</td><td>G_116</td><td>G_117</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_118</td><td>G_119</td><td>G_120</td><td>G_121</td><td>G_122</td><td>G_123</td><td>G_124</td><td>G_125</td><td>G_126</td><td>G_127</td><td>G_128</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_129</td><td>G_130</td><td>G_131</td><td>G_132</td><td>G_133</td><td>G_134</td><td>G_135</td><td>G_136</td><td>G_137</td><td>G_138</td><td>G_139</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_140</td><td>G_141</td><td>G_142</td><td>G_143</td><td>G_144</td><td>G_145</td><td>G_146</td><td>G_147</td><td>G_148</td><td>G_149</td><td>G_150</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_151</td><td>G_152</td><td>G_153</td><td>G_154</td><td>G_155</td><td>G_156</td><td>G_157</td><td>G_158</td><td>G_159</td><td>G_160</td><td>G_161</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_162</td><td>G_163</td><td>G_164</td><td>G_165</td><td>G_166</td><td>G_167</td><td>G_168</td><td>G_169</td><td>G_170</td><td>G_171</td><td>G_172</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_173</td><td>G_174</td><td>G_175</td><td>G_176</td><td>G_177</td><td>G_178</td><td>G_179</td><td>G_180</td><td>NG_115</td><td>NG_116</td><td>NG_117</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_118</td><td>NG_119</td><td>NG_120</td><td>NG_121</td><td>NG_122</td><td>NG_123</td><td>NG_124</td><td>NG_125</td><td>NG_126</td><td>NG_127</td><td>NG_128</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_129</td><td>NG_130</td><td>NG_131</td><td>NG_132</td><td>NG_133</td><td>NG_134</td><td>NG_135</td><td>NG_136</td><td>NG_137</td><td>NG_138</td><td>NG_139</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_140</td><td>NG_141</td><td>NG_142</td><td>NG_143</td><td>NG_144</td><td>NG_145</td><td>NG_146</td><td>NG_147</td><td>NG_148</td><td>NG_149</td><td>NG_150</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_151</td><td>NG_152</td><td>NG_153</td><td>NG_154</td><td>NG_155</td><td>NG_156</td><td>NG_157</td><td>NG_158</td><td>NG_159</td><td>NG_160</td><td>NG_161</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_162</td><td>NG_163</td><td>NG_164</td><td>NG_165</td><td>NG_166</td><td>NG_167</td><td>NG_168</td><td>NG_169</td><td>NG_170</td><td>NG_171</td><td>NG_172</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_173</td><td>NG_174</td><td>NG_175</td><td>NG_176</td><td>NG_177</td><td>NG_178</td><td>NG_179</td><td>NG_180</td><td>NG_181</td><td>NG_182</td><td>NG_183</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_184</td><td>NG_185</td><td>NG_186</td><td>NG_187</td><td>NG_188</td><td>NG_189</td><td>NG_190</td><td>NG_191</td><td>NG_192</td><td>NG_193</td><td>NG_194</td></tr></table>
<table><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_195</td><td>NG_196</td><td>NG_197</td><td>NG_198</td><td>NG_199</td><td>NG_200</td><td>NG_201</td><td>NG_202</td><td>NG_203</td><td>NG_204</td><td>NG_205</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_206</td><td>NG_207</td><td>NG_208</td><td>NG_209</td><td>NG_210</td><td>NG_211</td><td>NG_212</td><td>NG_213</td><td>NG_214</td><td>NG_215</td><td>NG_216</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_217</td><td>NG_218</td><td>NG_219</td><td>NG_220</td><td>NG_221</td><td>NG_222</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td></td><td></td><td></td><td></td><td></td></tr></table>

sort(km.resdat1_3$cluster)

<table><tr><td>##</td><td>G_01</td><td>G_02</td><td>G_03</td><td>G_04</td><td>G_05</td><td>G_06</td><td>G_07</td><td>G_08</td><td>G_09</td><td>G_10</td><td>G_11</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_12</td><td>G_13</td><td>G_14</td><td>G_15</td><td>G_16</td><td>G_17</td><td>G_18</td><td>G_19</td><td>G_20</td><td>G_21</td><td>G_22</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_23</td><td>G_24</td><td>G_25</td><td>G_26</td><td>G_27</td><td>G_28</td><td>G_29</td><td>G_30</td><td>G_31</td><td>G_32</td><td>G_33</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_34</td><td>G_35</td><td>G_36</td><td>G_37</td><td>G_38</td><td>G_39</td><td>G_40</td><td>G_41</td><td>G_42</td><td>G_43</td><td>G_44</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_45</td><td>G_46</td><td>G_47</td><td>G_48</td><td>G_49</td><td>G_50</td><td>G_51</td><td>G_52</td><td>G_53</td><td>G_54</td><td>G_55</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_56</td><td>G_57</td><td>G_58</td><td>G_59</td><td>G_60</td><td>G_61</td><td>G_62</td><td>G_63</td><td>G_64</td><td>G_65</td><td>G_66</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_67</td><td>G_68</td><td>G_69</td><td>G_70</td><td>G_71</td><td>G_72</td><td>G_73</td><td>G_74</td><td>G_75</td><td>G_76</td><td>G_77</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_78</td><td>G_79</td><td>G_80</td><td>G_81</td><td>G_82</td><td>G_83</td><td>G_84</td><td>G_85</td><td>G_86</td><td>G_87</td><td>G_88</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_89</td><td>G_90</td><td>G_91</td><td>G_92</td><td>G_93</td><td>G_94</td><td>G_95</td><td>G_96</td><td>NG_01</td><td>NG_02</td><td>NG_03</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_04</td><td>NG_05</td><td>NG_06</td><td>NG_07</td><td>NG_08</td><td>NG_09</td><td>NG_10</td><td>NG_11</td><td>NG_12</td><td>NG_13</td><td>NG_14</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_15</td><td>NG_16</td><td>NG_17</td><td>NG_18</td><td>NG_19</td><td>NG_20</td><td>NG_21</td><td>NG_22</td><td>NG_23</td><td>NG_24</td><td>NG_25</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_26</td><td>NG_27</td><td>NG_28</td><td>NG_29</td><td>NG_30</td><td>NG_31</td><td>NG_32</td><td>NG_33</td><td>NG_34</td><td>NG_35</td><td>NG_36</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_37</td><td>NG_38</td><td>NG_39</td><td>NG_40</td><td>NG_41</td><td>NG_42</td><td>NG_43</td><td>NG_44</td><td>NG_45</td><td>NG_46</td><td>NG_47</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_48</td><td>NG_49</td><td>NG_50</td><td>NG_51</td><td>NG_52</td><td>NG_53</td><td>NG_54</td><td>NG_55</td><td>NG_56</td><td>NG_57</td><td>NG_58</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_59</td><td>NG_60</td><td>NG_61</td><td>NG_62</td><td>NG_63</td><td>NG_64</td><td>NG_65</td><td>NG_66</td><td>NG_67</td><td>NG_68</td><td>NG_69</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_70</td><td>NG_71</td><td>NG_72</td><td>NG_73</td><td>NG_74</td><td>NG_75</td><td>NG_76</td><td>NG_77</td><td>NG_78</td><td>NG_79</td><td>NG_80</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_81</td><td>NG_82</td><td>NG_83</td><td>NG_84</td><td>NG_85</td><td>NG_86</td><td>NG_87</td><td>NG_88</td><td>NG_89</td><td>NG_90</td><td>NG_91</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_92</td><td>NG_93</td><td>NG_94</td><td>NG_95</td><td>NG_96</td><td>NG_97</td><td>NG_98</td><td>NG_99</td><td>NG_100</td><td>NG_101</td><td>NG_102</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr></table>
7.5. KMEANS CLUSTERING

<table><thead><tr><th></th><th>NG_103</th><th>NG_104</th><th>NG_105</th><th>NG_106</th><th>NG_107</th><th>NG_108</th><th>NG_109</th><th>NG_110</th><th>NG_111</th><th>NG_112</th><th>NG_113</th></tr></thead><tbody><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_114</td><td>G_97</td><td>G_98</td><td>G_99</td><td>G_100</td><td>G_101</td><td>G_102</td><td>G_103</td><td>G_104</td><td>G_105</td><td>G_106</td></tr><tr><td>##</td><td>1</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_107</td><td>G_108</td><td>G_109</td><td>G_110</td><td>G_111</td><td>G_112</td><td>G_113</td><td>G_114</td><td>G_115</td><td>G_116</td><td>G_117</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_118</td><td>G_119</td><td>G_120</td><td>G_121</td><td>G_122</td><td>G_123</td><td>G_124</td><td>G_125</td><td>G_126</td><td>G_127</td><td>G_128</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_129</td><td>G_130</td><td>G_131</td><td>G_132</td><td>G_133</td><td>G_134</td><td>G_135</td><td>G_136</td><td>G_137</td><td>G_138</td><td>G_139</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_140</td><td>G_141</td><td>G_142</td><td>G_143</td><td>G_144</td><td>G_145</td><td>G_146</td><td>G_147</td><td>G_148</td><td>G_149</td><td>G_150</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_151</td><td>G_152</td><td>G_153</td><td>NG_115</td><td>NG_116</td><td>NG_117</td><td>NG_118</td><td>NG_119</td><td>NG_120</td><td>NG_121</td><td>NG_122</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_123</td><td>NG_124</td><td>NG_125</td><td>NG_126</td><td>NG_127</td><td>NG_128</td><td>NG_129</td><td>NG_130</td><td>NG_131</td><td>NG_132</td><td>NG_133</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_134</td><td>NG_135</td><td>NG_136</td><td>NG_137</td><td>NG_138</td><td>NG_139</td><td>NG_140</td><td>NG_141</td><td>NG_142</td><td>NG_143</td><td>NG_144</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_145</td><td>NG_146</td><td>NG_147</td><td>NG_148</td><td>NG_149</td><td>NG_150</td><td>NG_151</td><td>NG_152</td><td>NG_153</td><td>NG_154</td><td>NG_155</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_156</td><td>NG_157</td><td>NG_158</td><td>NG_159</td><td>NG_160</td><td>NG_161</td><td>NG_162</td><td>NG_163</td><td>NG_164</td><td>NG_165</td><td>NG_166</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_167</td><td>NG_168</td><td>NG_169</td><td>NG_170</td><td>NG_171</td><td>NG_172</td><td>NG_173</td><td>NG_174</td><td>NG_175</td><td>NG_176</td><td>NG_177</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_178</td><td>NG_179</td><td>NG_180</td><td>NG_181</td><td>NG_182</td><td>NG_183</td><td>NG_184</td><td>NG_185</td><td>NG_186</td><td>G_154</td><td>G_155</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>3</td><td>3</td></tr><tr><td>##</td><td>G_156</td><td>G_157</td><td>G_158</td><td>G_159</td><td>G_160</td><td>G_161</td><td>G_162</td><td>G_163</td><td>G_164</td><td>G_165</td><td>G_166</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>G_167</td><td>G_168</td><td>G_169</td><td>G_170</td><td>G_171</td><td>G_172</td><td>G_173</td><td>G_174</td><td>G_175</td><td>G_176</td><td>G_177</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>G_178</td><td>G_179</td><td>G_180</td><td>NG_187</td><td>NG_188</td><td>NG_189</td><td>NG_190</td><td>NG_191</td><td>NG_192</td><td>NG_193</td><td>NG_194</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_195</td><td>NG_196</td><td>NG_197</td><td>NG_198</td><td>NG_199</td><td>NG_200</td><td>NG_201</td><td>NG_202</td><td>NG_203</td><td>NG_204</td><td>NG_205</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_206</td><td>NG_207</td><td>NG_208</td><td>NG_209</td><td>NG_210</td><td>NG_211</td><td>NG_212</td><td>NG_213</td><td>NG_214</td><td>NG_215</td><td>NG_216</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_217</td><td>NG_218</td><td>NG_219</td><td>NG_220</td><td>NG_221</td><td>NG_222</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td></td><td></td><td></td><td></td><td></td></tr></tbody></table>

sort(km.resdat1_4$cluster)

<table><tbody><tr><td>##</td><td>G_01</td><td>G_02</td><td>G_03</td><td>G_04</td><td>G_05</td><td>G_06</td><td>G_07</td><td>G_08</td><td>G_09</td><td>G_10</td><td>G_11</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_12</td><td>G_13</td><td>G_14</td><td>G_15</td><td>G_16</td><td>G_17</td><td>G_18</td><td>G_19</td><td>G_20</td><td>G_21</td><td>G_22</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_23</td><td>G_24</td><td>G_25</td><td>G_26</td><td>G_27</td><td>G_28</td><td>G_29</td><td>G_30</td><td>G_31</td><td>G_32</td><td>G_33</td></tr></tbody></table>
<table><thead><tr><th>##</th><th>1</th><th>1</th><th>1</th><th>1</th><th>1</th><th>1</th><th>1</th><th>1</th><th>1</th><th>1</th><th>1</th></tr></thead><tbody><tr><td>## G_34</td><td>G_35</td><td>G_36</td><td>G_37</td><td>G_38</td><td>G_39</td><td>G_40</td><td>G_41</td><td>G_42</td><td>G_43</td><td>G_44</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## G_45</td><td>G_46</td><td>G_47</td><td>G_48</td><td>G_49</td><td>G_50</td><td>G_51</td><td>G_52</td><td>G_53</td><td>G_54</td><td>G_55</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## G_56</td><td>G_57</td><td>G_58</td><td>G_59</td><td>G_60</td><td>G_61</td><td>G_62</td><td>G_63</td><td>G_64</td><td>G_65</td><td>G_66</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## G_67</td><td>G_68</td><td>G_69</td><td>G_70</td><td>G_71</td><td>G_72</td><td>G_73</td><td>G_74</td><td>G_75</td><td>G_76</td><td>G_77</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## G_78</td><td>G_79</td><td>G_80</td><td>G_81</td><td>G_82</td><td>G_83</td><td>G_84</td><td>G_85</td><td>G_86</td><td>G_87</td><td>G_88</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## G_89</td><td>G_90</td><td>G_91</td><td>G_92</td><td>G_93</td><td>G_94</td><td>G_95</td><td>G_96</td><td>NG_01</td><td>NG_02</td><td>NG_03</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## NG_04</td><td>NG_05</td><td>NG_06</td><td>NG_07</td><td>NG_08</td><td>NG_09</td><td>NG_10</td><td>NG_11</td><td>NG_12</td><td>NG_13</td><td>NG_14</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## NG_15</td><td>NG_16</td><td>NG_17</td><td>NG_18</td><td>NG_19</td><td>NG_20</td><td>NG_21</td><td>NG_22</td><td>NG_23</td><td>NG_24</td><td>NG_25</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## NG_26</td><td>NG_27</td><td>NG_28</td><td>NG_29</td><td>NG_30</td><td>NG_31</td><td>NG_32</td><td>NG_33</td><td>NG_34</td><td>NG_35</td><td>NG_36</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## NG_37</td><td>NG_38</td><td>NG_39</td><td>NG_40</td><td>NG_41</td><td>NG_42</td><td>NG_43</td><td>NG_44</td><td>NG_45</td><td>NG_46</td><td>NG_47</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## NG_48</td><td>NG_49</td><td>NG_50</td><td>NG_51</td><td>NG_52</td><td>NG_53</td><td>NG_54</td><td>NG_55</td><td>NG_56</td><td>NG_57</td><td>NG_58</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## NG_59</td><td>NG_60</td><td>NG_61</td><td>NG_62</td><td>NG_63</td><td>NG_64</td><td>NG_65</td><td>NG_66</td><td>NG_67</td><td>NG_68</td><td>NG_69</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## NG_70</td><td>NG_71</td><td>NG_72</td><td>NG_73</td><td>NG_74</td><td>NG_75</td><td>NG_76</td><td>NG_77</td><td>NG_78</td><td>NG_79</td><td>NG_80</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## NG_81</td><td>NG_82</td><td>NG_83</td><td>NG_84</td><td>NG_85</td><td>NG_86</td><td>NG_87</td><td>NG_88</td><td>NG_89</td><td>NG_90</td><td>NG_91</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## NG_92</td><td>NG_93</td><td>NG_94</td><td>NG_95</td><td>NG_96</td><td>NG_97</td><td>NG_98</td><td>NG_99</td><td>NG_100</td><td>NG_101</td><td>NG_102</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## NG_103</td><td>NG_104</td><td>NG_105</td><td>NG_106</td><td>NG_107</td><td>NG_108</td><td>NG_109</td><td>NG_110</td><td>NG_111</td><td>NG_112</td><td>NG_113</td></tr><tr><td>## 1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>## NG_114</td><td>G_97</td><td>G_98</td><td>G_99</td><td>G_100</td><td>G_101</td><td>G_102</td><td>G_103</td><td>G_104</td><td>G_105</td><td>G_106</td></tr><tr><td>## 1</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>## G_107</td><td>G_108</td><td>G_109</td><td>G_110</td><td>G_111</td><td>G_112</td><td>G_113</td><td>G_114</td><td>G_115</td><td>G_116</td><td>G_117</td></tr><tr><td>## 2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>## G_118</td><td>G_119</td><td>G_120</td><td>G_121</td><td>G_122</td><td>G_123</td><td>G_151</td><td>G_152</td><td>G_153</td><td>NG_115</td><td>NG_116</td></tr><tr><td>## 2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>## NG_117</td><td>NG_118</td><td>NG_119</td><td>NG_120</td><td>NG_121</td><td>NG_122</td><td>NG_123</td><td>NG_124</td><td>NG_125</td><td>NG_126</td><td>NG_127</td></tr><tr><td>## 2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>## NG_128</td><td>NG_129</td><td>NG_130</td><td>NG_131</td><td>NG_132</td><td>NG_133</td><td>NG_134</td><td>NG_135</td><td>NG_136</td><td>NG_137</td><td>NG_138</td></tr><tr><td>## 2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>## NG_139</td><td>NG_140</td><td>NG_141</td><td>NG_142</td><td>NG_143</td><td>NG_144</td><td>NG_145</td><td>NG_146</td><td>NG_147</td><td>NG_148</td><td>NG_149</td></tr><tr><td>## 2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>## NG_150</td><td>G_124</td><td>G_125</td><td>G_126</td><td>G_127</td><td>G_128</td><td>G_129</td><td>G_130</td><td>G_131</td><td>G_132</td><td>G_133</td></tr></tbody></table>
<table><tr><td>##</td><td>2</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>G_134</td><td>G_135</td><td>G_136</td><td>G_137</td><td>G_138</td><td>G_139</td><td>G_140</td><td>G_141</td><td>G_142</td><td>G_143</td><td>G_144</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>G_145</td><td>G_146</td><td>G_147</td><td>G_148</td><td>G_149</td><td>G_150</td><td>NG_151</td><td>NG_152</td><td>NG_153</td><td>NG_154</td><td>NG_155</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_156</td><td>NG_157</td><td>NG_158</td><td>NG_159</td><td>NG_160</td><td>NG_161</td><td>NG_162</td><td>NG_163</td><td>NG_164</td><td>NG_165</td><td>NG_166</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_167</td><td>NG_168</td><td>NG_169</td><td>NG_170</td><td>NG_171</td><td>NG_172</td><td>NG_173</td><td>NG_174</td><td>NG_175</td><td>NG_176</td><td>NG_177</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_178</td><td>NG_179</td><td>NG_180</td><td>NG_181</td><td>NG_182</td><td>NG_183</td><td>NG_184</td><td>NG_185</td><td>NG_186</td><td>G_154</td><td>G_155</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>4</td><td>4</td></tr><tr><td>##</td><td>G_156</td><td>G_157</td><td>G_158</td><td>G_159</td><td>G_160</td><td>G_161</td><td>G_162</td><td>G_163</td><td>G_164</td><td>G_165</td><td>G_166</td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>##</td><td>G_167</td><td>G_168</td><td>G_169</td><td>G_170</td><td>G_171</td><td>G_172</td><td>G_173</td><td>G_174</td><td>G_175</td><td>G_176</td><td>G_177</td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>##</td><td>G_178</td><td>G_179</td><td>G_180</td><td>NG_187</td><td>NG_188</td><td>NG_189</td><td>NG_190</td><td>NG_191</td><td>NG_192</td><td>NG_193</td><td>NG_194</td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>##</td><td>NG_195</td><td>NG_196</td><td>NG_197</td><td>NG_198</td><td>NG_199</td><td>NG_200</td><td>NG_201</td><td>NG_202</td><td>NG_203</td><td>NG_204</td><td>NG_205</td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>##</td><td>NG_206</td><td>NG_207</td><td>NG_208</td><td>NG_209</td><td>NG_210</td><td>NG_211</td><td>NG_212</td><td>NG_213</td><td>NG_214</td><td>NG_215</td><td>NG_216</td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>##</td><td>NG_217</td><td>NG_218</td><td>NG_219</td><td>NG_220</td><td>NG_221</td><td>NG_222</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td></td><td></td><td></td><td></td><td></td></tr></table>

sort(km.resdat1_5$cluster)

<table><tr><td>##</td><td>G_01</td><td>G_02</td><td>G_04</td><td>G_05</td><td>G_06</td><td>G_07</td><td>G_09</td><td>G_10</td><td>G_12</td><td>G_13</td><td>G_41</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_42</td><td>G_43</td><td>G_44</td><td>G_45</td><td>G_46</td><td>G_47</td><td>G_48</td><td>G_67</td><td>G_68</td><td>G_69</td><td>G_70</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_71</td><td>G_72</td><td>G_73</td><td>G_74</td><td>G_75</td><td>G_76</td><td>G_77</td><td>G_78</td><td>G_79</td><td>G_80</td><td>G_81</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_82</td><td>G_83</td><td>G_84</td><td>G_85</td><td>G_86</td><td>G_87</td><td>G_88</td><td>G_89</td><td>G_90</td><td>G_91</td><td>G_92</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_93</td><td>G_94</td><td>G_95</td><td>G_96</td><td>NG_76</td><td>NG_77</td><td>NG_78</td><td>NG_79</td><td>NG_80</td><td>NG_81</td><td>NG_82</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_83</td><td>NG_84</td><td>NG_85</td><td>NG_86</td><td>NG_87</td><td>NG_88</td><td>NG_89</td><td>NG_90</td><td>NG_91</td><td>NG_92</td><td>NG_93</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_94</td><td>NG_95</td><td>NG_96</td><td>NG_97</td><td>NG_98</td><td>NG_99</td><td>NG_100</td><td>NG_101</td><td>NG_102</td><td>NG_103</td><td>NG_104</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>NG_105</td><td>NG_106</td><td>NG_107</td><td>NG_108</td><td>NG_109</td><td>NG_110</td><td>NG_111</td><td>NG_112</td><td>NG_113</td><td>NG_114</td><td>G_03</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>2</td></tr><tr><td>##</td><td>G_08</td><td>G_11</td><td>G_14</td><td>G_15</td><td>G_16</td><td>G_17</td><td>G_18</td><td>G_19</td><td>G_20</td><td>G_21</td><td>G_22</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_23</td><td>G_24</td><td>G_25</td><td>G_26</td><td>G_27</td><td>G_28</td><td>G_29</td><td>G_30</td><td>G_31</td><td>G_32</td><td>G_33</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr></table>
<table><tr><td>G_34</td><td>G_35</td><td>G_36</td><td>G_37</td><td>G_38</td><td>G_39</td><td>G_40</td><td>G_49</td><td>G_50</td><td>G_51</td><td>G_52</td></tr><tr><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>G_53</td><td>G_54</td><td>G_55</td><td>G_56</td><td>G_57</td><td>G_58</td><td>G_59</td><td>G_60</td><td>G_61</td><td>G_62</td><td>G_63</td></tr><tr><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>G_64</td><td>G_65</td><td>G_66</td><td>NG_01</td><td>NG_02</td><td>NG_03</td><td>NG_04</td><td>NG_05</td><td>NG_06</td><td>NG_07</td><td>NG_08</td></tr><tr><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>NG_09</td><td>NG_10</td><td>NG_11</td><td>NG_12</td><td>NG_13</td><td>NG_14</td><td>NG_15</td><td>NG_16</td><td>NG_17</td><td>NG_18</td><td>NG_19</td></tr><tr><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>NG_20</td><td>NG_21</td><td>NG_22</td><td>NG_23</td><td>NG_24</td><td>NG_25</td><td>NG_26</td><td>NG_27</td><td>NG_28</td><td>NG_29</td><td>NG_30</td></tr><tr><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>NG_31</td><td>NG_32</td><td>NG_33</td><td>NG_34</td><td>NG_35</td><td>NG_36</td><td>NG_37</td><td>NG_38</td><td>NG_39</td><td>NG_40</td><td>NG_41</td></tr><tr><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>NG_42</td><td>NG_43</td><td>NG_44</td><td>NG_45</td><td>NG_46</td><td>NG_47</td><td>NG_48</td><td>NG_49</td><td>NG_50</td><td>NG_51</td><td>NG_52</td></tr><tr><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>NG_53</td><td>NG_54</td><td>NG_55</td><td>NG_56</td><td>NG_57</td><td>NG_58</td><td>NG_59</td><td>NG_60</td><td>NG_61</td><td>NG_62</td><td>NG_63</td></tr><tr><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>NG_64</td><td>NG_65</td><td>NG_66</td><td>NG_67</td><td>NG_68</td><td>NG_69</td><td>NG_70</td><td>NG_71</td><td>NG_72</td><td>NG_73</td><td>NG_74</td></tr><tr><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>NG_75</td><td>G_97</td><td>G_98</td><td>G_99</td><td>G_100</td><td>G_101</td><td>G_102</td><td>G_103</td><td>G_104</td><td>G_105</td><td>G_106</td></tr><tr><td>2</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>G_107</td><td>G_108</td><td>G_109</td><td>G_110</td><td>G_111</td><td>G_112</td><td>G_113</td><td>G_114</td><td>G_115</td><td>G_116</td><td>G_117</td></tr><tr><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>G_118</td><td>G_119</td><td>G_120</td><td>G_121</td><td>G_122</td><td>G_123</td><td>G_151</td><td>G_152</td><td>G_153</td><td>NG_115</td><td>NG_116</td></tr><tr><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>NG_117</td><td>NG_118</td><td>NG_119</td><td>NG_120</td><td>NG_121</td><td>NG_122</td><td>NG_123</td><td>NG_124</td><td>NG_125</td><td>NG_126</td><td>NG_127</td></tr><tr><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>NG_128</td><td>NG_129</td><td>NG_130</td><td>NG_131</td><td>NG_132</td><td>NG_133</td><td>NG_134</td><td>NG_135</td><td>NG_136</td><td>NG_137</td><td>NG_138</td></tr><tr><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>NG_139</td><td>NG_140</td><td>NG_141</td><td>NG_142</td><td>NG_143</td><td>NG_144</td><td>NG_145</td><td>NG_146</td><td>NG_147</td><td>NG_148</td><td>NG_149</td></tr><tr><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>NG_150</td><td>G_124</td><td>G_125</td><td>G_126</td><td>G_127</td><td>G_128</td><td>G_129</td><td>G_130</td><td>G_131</td><td>G_132</td><td>G_133</td></tr><tr><td>3</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>G_134</td><td>G_135</td><td>G_136</td><td>G_137</td><td>G_138</td><td>G_139</td><td>G_140</td><td>G_141</td><td>G_142</td><td>G_143</td><td>G_144</td></tr><tr><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>G_145</td><td>G_146</td><td>G_147</td><td>G_148</td><td>G_149</td><td>G_150</td><td>NG_151</td><td>NG_152</td><td>NG_153</td><td>NG_154</td><td>NG_155</td></tr><tr><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>NG_156</td><td>NG_157</td><td>NG_158</td><td>NG_159</td><td>NG_160</td><td>NG_161</td><td>NG_162</td><td>NG_163</td><td>NG_164</td><td>NG_165</td><td>NG_166</td></tr><tr><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>NG_167</td><td>NG_168</td><td>NG_169</td><td>NG_170</td><td>NG_171</td><td>NG_172</td><td>NG_173</td><td>NG_174</td><td>NG_175</td><td>NG_176</td><td>NG_177</td></tr><tr><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>NG_178</td><td>NG_179</td><td>NG_180</td><td>NG_181</td><td>NG_182</td><td>NG_183</td><td>NG_184</td><td>NG_185</td><td>NG_186</td><td>G_154</td><td>G_155</td></tr><tr><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>5</td><td>5</td></tr><tr><td>G_156</td><td>G_157</td><td>G_158</td><td>G_159</td><td>G_160</td><td>G_161</td><td>G_162</td><td>G_163</td><td>G_164</td><td>G_165</td><td>G_166</td></tr><tr><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>G_167</td><td>G_168</td><td>G_169</td><td>G_170</td><td>G_171</td><td>G_172</td><td>G_173</td><td>G_174</td><td>G_175</td><td>G_176</td><td>G_177</td></tr><tr><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr></table>
<table><tr><td>##</td><td>G_178</td><td>G_179</td><td>G_180</td><td>NG_187</td><td>NG_188</td><td>NG_189</td><td>NG_190</td><td>NG_191</td><td>NG_192</td><td>NG_193</td><td>NG_194</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>NG_195</td><td>NG_196</td><td>NG_197</td><td>NG_198</td><td>NG_199</td><td>NG_200</td><td>NG_201</td><td>NG_202</td><td>NG_203</td><td>NG_204</td><td>NG_205</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>NG_206</td><td>NG_207</td><td>NG_208</td><td>NG_209</td><td>NG_210</td><td>NG_211</td><td>NG_212</td><td>NG_213</td><td>NG_214</td><td>NG_215</td><td>NG_216</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>NG_217</td><td>NG_218</td><td>NG_219</td><td>NG_220</td><td>NG_221</td><td>NG_222</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td></td><td></td><td></td><td></td><td></td></tr></table>

sort(km.resdat1_6$cluster)

<table><tr><td>##</td><td>G_01</td><td>G_02</td><td>G_04</td><td>G_05</td><td>G_06</td><td>G_07</td><td>G_09</td><td>G_10</td><td>G_12</td><td>G_13</td><td>G_41</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_42</td><td>G_43</td><td>G_44</td><td>G_45</td><td>G_46</td><td>G_47</td><td>G_48</td><td>G_67</td><td>G_68</td><td>G_69</td><td>G_70</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_71</td><td>G_73</td><td>G_76</td><td>G_77</td><td>G_78</td><td>G_79</td><td>G_80</td><td>G_81</td><td>G_91</td><td>G_92</td><td>G_93</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_96</td><td>G_03</td><td>G_08</td><td>G_11</td><td>G_14</td><td>G_15</td><td>G_16</td><td>G_17</td><td>G_18</td><td>G_19</td><td>G_20</td></tr><tr><td>##</td><td>1</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_21</td><td>G_22</td><td>G_23</td><td>G_24</td><td>G_25</td><td>G_26</td><td>G_27</td><td>G_28</td><td>G_29</td><td>G_30</td><td>G_31</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_32</td><td>G_33</td><td>G_34</td><td>G_35</td><td>G_36</td><td>G_37</td><td>G_38</td><td>G_39</td><td>G_40</td><td>G_49</td><td>G_50</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_51</td><td>G_52</td><td>G_53</td><td>G_54</td><td>G_55</td><td>G_56</td><td>G_57</td><td>G_58</td><td>G_59</td><td>G_60</td><td>G_61</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_62</td><td>G_63</td><td>G_64</td><td>G_65</td><td>G_66</td><td>NG_01</td><td>NG_02</td><td>NG_03</td><td>NG_04</td><td>NG_05</td><td>NG_06</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_07</td><td>NG_08</td><td>NG_09</td><td>NG_10</td><td>NG_11</td><td>NG_12</td><td>NG_13</td><td>NG_14</td><td>NG_15</td><td>NG_16</td><td>NG_17</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_18</td><td>NG_19</td><td>NG_20</td><td>NG_21</td><td>NG_22</td><td>NG_23</td><td>NG_24</td><td>NG_25</td><td>NG_26</td><td>NG_27</td><td>NG_28</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_29</td><td>NG_30</td><td>NG_31</td><td>NG_32</td><td>NG_33</td><td>NG_34</td><td>NG_35</td><td>NG_36</td><td>NG_37</td><td>NG_38</td><td>NG_39</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_40</td><td>NG_41</td><td>NG_42</td><td>NG_43</td><td>NG_44</td><td>NG_45</td><td>NG_46</td><td>NG_47</td><td>NG_48</td><td>NG_49</td><td>NG_50</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_51</td><td>NG_52</td><td>NG_53</td><td>NG_54</td><td>NG_55</td><td>NG_56</td><td>NG_57</td><td>NG_58</td><td>NG_59</td><td>NG_60</td><td>NG_61</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_62</td><td>NG_63</td><td>NG_64</td><td>NG_65</td><td>NG_66</td><td>NG_67</td><td>NG_68</td><td>NG_69</td><td>NG_70</td><td>NG_71</td><td>NG_72</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_73</td><td>NG_74</td><td>NG_75</td><td>G_72</td><td>G_74</td><td>G_75</td><td>G_82</td><td>G_83</td><td>G_84</td><td>G_85</td><td>G_86</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>G_87</td><td>G_88</td><td>G_89</td><td>G_90</td><td>G_94</td><td>G_95</td><td>NG_76</td><td>NG_77</td><td>NG_78</td><td>NG_79</td><td>NG_80</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_81</td><td>NG_82</td><td>NG_83</td><td>NG_84</td><td>NG_85</td><td>NG_86</td><td>NG_87</td><td>NG_88</td><td>NG_89</td><td>NG_90</td><td>NG_91</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_92</td><td>NG_93</td><td>NG_94</td><td>NG_95</td><td>NG_96</td><td>NG_97</td><td>NG_98</td><td>NG_99</td><td>NG_100</td><td>NG_101</td><td>NG_102</td></tr></table>
<table><thead><tr><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th></tr></thead><tbody><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_103</td><td>NG_104</td><td>NG_105</td><td>NG_106</td><td>NG_107</td><td>NG_108</td><td>NG_109</td><td>NG_110</td><td>NG_111</td><td>NG_112</td><td>NG_113</td><td>NG_113</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_114</td><td>G_97</td><td>G_98</td><td>G_99</td><td>G_100</td><td>G_101</td><td>G_102</td><td>G_103</td><td>G_104</td><td>G_105</td><td>G_106</td><td>G_106</td></tr><tr><td>##</td><td>3</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>##</td><td>G_107</td><td>G_108</td><td>G_109</td><td>G_110</td><td>G_111</td><td>G_112</td><td>G_113</td><td>G_114</td><td>G_115</td><td>G_116</td><td>G_117</td><td>G_117</td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>##</td><td>G_118</td><td>G_119</td><td>G_120</td><td>G_121</td><td>G_122</td><td>G_123</td><td>G_151</td><td>G_152</td><td>G_153</td><td>NG_115</td><td>NG_116</td><td>NG_116</td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>##</td><td>NG_117</td><td>NG_118</td><td>NG_119</td><td>NG_120</td><td>NG_121</td><td>NG_122</td><td>NG_123</td><td>NG_124</td><td>NG_125</td><td>NG_126</td><td>NG_127</td><td>NG_127</td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>##</td><td>NG_128</td><td>NG_129</td><td>NG_130</td><td>NG_131</td><td>NG_132</td><td>NG_133</td><td>NG_134</td><td>NG_135</td><td>NG_136</td><td>NG_137</td><td>NG_138</td><td>NG_138</td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>##</td><td>NG_139</td><td>NG_140</td><td>NG_141</td><td>NG_142</td><td>NG_143</td><td>NG_144</td><td>NG_145</td><td>NG_146</td><td>NG_147</td><td>NG_148</td><td>NG_149</td><td>NG_149</td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>##</td><td>NG_150</td><td>G_124</td><td>G_125</td><td>G_126</td><td>G_127</td><td>G_128</td><td>G_129</td><td>G_130</td><td>G_131</td><td>G_132</td><td>G_133</td><td>G_133</td></tr><tr><td>##</td><td>4</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>G_134</td><td>G_135</td><td>G_136</td><td>G_137</td><td>G_138</td><td>G_139</td><td>G_140</td><td>G_141</td><td>G_142</td><td>G_143</td><td>G_144</td><td>G_144</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>G_145</td><td>G_146</td><td>G_147</td><td>G_148</td><td>G_149</td><td>G_150</td><td>NG_151</td><td>NG_152</td><td>NG_153</td><td>NG_154</td><td>NG_155</td><td>NG_155</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>NG_156</td><td>NG_157</td><td>NG_158</td><td>NG_159</td><td>NG_160</td><td>NG_161</td><td>NG_162</td><td>NG_163</td><td>NG_164</td><td>NG_165</td><td>NG_166</td><td>NG_166</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>NG_167</td><td>NG_168</td><td>NG_169</td><td>NG_170</td><td>NG_171</td><td>NG_172</td><td>NG_173</td><td>NG_174</td><td>NG_175</td><td>NG_176</td><td>NG_177</td><td>NG_177</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>NG_178</td><td>NG_179</td><td>NG_180</td><td>NG_181</td><td>NG_182</td><td>NG_183</td><td>NG_184</td><td>NG_185</td><td>NG_186</td><td>G_154</td><td>G_155</td><td>G_155</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>6</td><td>6</td></tr><tr><td>##</td><td>G_156</td><td>G_157</td><td>G_158</td><td>G_159</td><td>G_160</td><td>G_161</td><td>G_162</td><td>G_163</td><td>G_164</td><td>G_165</td><td>G_166</td><td>G_166</td></tr><tr><td>##</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>##</td><td>G_167</td><td>G_168</td><td>G_169</td><td>G_170</td><td>G_171</td><td>G_172</td><td>G_173</td><td>G_174</td><td>G_175</td><td>G_176</td><td>G_177</td><td>G_177</td></tr><tr><td>##</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>##</td><td>G_178</td><td>G_179</td><td>G_180</td><td>NG_187</td><td>NG_188</td><td>NG_189</td><td>NG_190</td><td>NG_191</td><td>NG_192</td><td>NG_193</td><td>NG_194</td><td>NG_194</td></tr><tr><td>##</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>##</td><td>NG_195</td><td>NG_196</td><td>NG_197</td><td>NG_198</td><td>NG_199</td><td>NG_200</td><td>NG_201</td><td>NG_202</td><td>NG_203</td><td>NG_204</td><td>NG_205</td><td>NG_205</td></tr><tr><td>##</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>##</td><td>NG_206</td><td>NG_207</td><td>NG_208</td><td>NG_209</td><td>NG_210</td><td>NG_211</td><td>NG_212</td><td>NG_213</td><td>NG_214</td><td>NG_215</td><td>NG_216</td><td>NG_216</td></tr><tr><td>##</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>##</td><td>NG_217</td><td>NG_218</td><td>NG_219</td><td>NG_220</td><td>NG_221</td><td>NG_222</td><td>NG_223</td><td>NG_224</td><td>NG_225</td><td>NG_226</td><td>NG_227</td><td>NG_227</td></tr><tr><td>##</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr></tbody></table>

sort(km.resdat1_7$cluster)

<table><tbody><tr><td>##</td><td>G_01</td><td>G_02</td><td>G_04</td><td>G_05</td><td>G_06</td><td>G_07</td><td>G_09</td><td>G_10</td><td>G_12</td><td>G_13</td><td>G_41</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_42</td><td>G_43</td><td>G_44</td><td>G_45</td><td>G_46</td><td>G_47</td><td>G_48</td><td>G_67</td><td>G_68</td><td>G_69</td><td>G_70</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr></tbody></table>
7.5. KMEANS CLUSTERING

<table>
  <tbody>
    <tr>
      <td>G_71</td>
      <td>G_73</td>
      <td>G_76</td>
      <td>G_77</td>
      <td>G_78</td>
      <td>G_79</td>
      <td>G_80</td>
      <td>G_81</td>
      <td>G_91</td>
      <td>G_92</td>
      <td>G_93</td>
    </tr>
    <tr>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
      <td>1</td>
    </tr>
    <tr>
      <td>G_96</td>
      <td>G_03</td>
      <td>G_08</td>
      <td>G_11</td>
      <td>G_14</td>
      <td>G_15</td>
      <td>G_16</td>
      <td>G_17</td>
      <td>G_18</td>
      <td>G_19</td>
      <td>G_20</td>
    </tr>
    <tr>
      <td>1</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
    </tr>
    <tr>
      <td>NG_01</td>
      <td>NG_02</td>
      <td>NG_03</td>
      <td>NG_04</td>
      <td>NG_05</td>
      <td>NG_06</td>
      <td>NG_07</td>
      <td>NG_08</td>
      <td>NG_09</td>
      <td>NG_10</td>
      <td>NG_11</td>
    </tr>
    <tr>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
    </tr>
    <tr>
      <td>NG_12</td>
      <td>NG_13</td>
      <td>NG_14</td>
      <td>NG_15</td>
      <td>NG_16</td>
      <td>NG_17</td>
      <td>NG_18</td>
      <td>NG_19</td>
      <td>NG_20</td>
      <td>NG_21</td>
      <td>NG_22</td>
    </tr>
    <tr>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
    </tr>
    <tr>
      <td>NG_23</td>
      <td>NG_24</td>
      <td>NG_25</td>
      <td>NG_26</td>
      <td>NG_27</td>
      <td>NG_28</td>
      <td>NG_29</td>
      <td>NG_30</td>
      <td>NG_31</td>
      <td>NG_32</td>
      <td>NG_33</td>
    </tr>
    <tr>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>2</td>
    </tr>
    <tr>
      <td>NG_70</td>
      <td>NG_71</td>
      <td>NG_72</td>
      <td>G_21</td>
      <td>G_22</td>
      <td>G_23</td>
      <td>G_24</td>
      <td>G_25</td>
      <td>G_26</td>
      <td>G_27</td>
      <td>G_28</td>
    </tr>
    <tr>
      <td>2</td>
      <td>2</td>
      <td>2</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
    </tr>
    <tr>
      <td>G_29</td>
      <td>G_30</td>
      <td>G_31</td>
      <td>G_32</td>
      <td>G_33</td>
      <td>G_34</td>
      <td>G_35</td>
      <td>G_36</td>
      <td>G_37</td>
      <td>G_38</td>
      <td>G_39</td>
    </tr>
    <tr>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
    </tr>
    <tr>
      <td>G_40</td>
      <td>G_49</td>
      <td>G_50</td>
      <td>G_51</td>
      <td>G_52</td>
      <td>G_53</td>
      <td>G_54</td>
      <td>G_55</td>
      <td>G_56</td>
      <td>G_57</td>
      <td>G_58</td>
    </tr>
    <tr>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
    </tr>
    <tr>
      <td>G_59</td>
      <td>G_60</td>
      <td>G_61</td>
      <td>G_62</td>
      <td>G_63</td>
      <td>G_64</td>
      <td>G_65</td>
      <td>G_66</td>
      <td>NG_34</td>
      <td>NG_35</td>
      <td>NG_36</td>
    </tr>
    <tr>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
    </tr>
    <tr>
      <td>NG_37</td>
      <td>NG_38</td>
      <td>NG_39</td>
      <td>NG_40</td>
      <td>NG_41</td>
      <td>NG_42</td>
      <td>NG_43</td>
      <td>NG_44</td>
      <td>NG_45</td>
      <td>NG_46</td>
      <td>NG_47</td>
    </tr>
    <tr>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
    </tr>
    <tr>
      <td>NG_48</td>
      <td>NG_49</td>
      <td>NG_50</td>
      <td>NG_51</td>
      <td>NG_52</td>
      <td>NG_53</td>
      <td>NG_54</td>
      <td>NG_55</td>
      <td>NG_56</td>
      <td>NG_57</td>
      <td>NG_58</td>
    </tr>
    <tr>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
    </tr>
    <tr>
      <td>NG_59</td>
      <td>NG_60</td>
      <td>NG_61</td>
      <td>NG_62</td>
      <td>NG_63</td>
      <td>NG_64</td>
      <td>NG_65</td>
      <td>NG_66</td>
      <td>NG_67</td>
      <td>NG_68</td>
      <td>NG_69</td>
    </tr>
    <tr>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>3</td>
    </tr>
    <tr>
      <td>NG_73</td>
      <td>NG_74</td>
      <td>NG_75</td>
      <td>G_72</td>
      <td>G_74</td>
      <td>G_75</td>
      <td>G_82</td>
      <td>G_83</td>
      <td>G_84</td>
      <td>G_85</td>
      <td>G_86</td>
    </tr>
    <tr>
      <td>3</td>
      <td>3</td>
      <td>3</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
    </tr>
    <tr>
      <td>G_87</td>
      <td>G_88</td>
      <td>G_89</td>
      <td>G_90</td>
      <td>G_94</td>
      <td>G_95</td>
      <td>NG_76</td>
      <td>NG_77</td>
      <td>NG_78</td>
      <td>NG_79</td>
      <td>NG_80</td>
    </tr>
    <tr>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
    </tr>
    <tr>
      <td>NG_81</td>
      <td>NG_82</td>
      <td>NG_83</td>
      <td>NG_84</td>
      <td>NG_85</td>
      <td>NG_86</td>
      <td>NG_87</td>
      <td>NG_88</td>
      <td>NG_89</td>
      <td>NG_90</td>
      <td>NG_91</td>
    </tr>
    <tr>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
    </tr>
    <tr>
      <td>NG_92</td>
      <td>NG_93</td>
      <td>NG_94</td>
      <td>NG_95</td>
      <td>NG_96</td>
      <td>NG_97</td>
      <td>NG_98</td>
      <td>NG_99</td>
      <td>NG_100</td>
      <td>NG_101</td>
      <td>NG_102</td>
    </tr>
    <tr>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
    </tr>
    <tr>
      <td>NG_103</td>
      <td>NG_104</td>
      <td>NG_105</td>
      <td>NG_106</td>
      <td>NG_107</td>
      <td>NG_108</td>
      <td>NG_109</td>
      <td>NG_110</td>
      <td>NG_111</td>
      <td>NG_112</td>
      <td>NG_113</td>
    </tr>
    <tr>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
      <td>4</td>
    </tr>
    <tr>
      <td>NG_114</td>
      <td>G_97</td>
      <td>G_98</td>
      <td>G_99</td>
      <td>G_100</td>
      <td>G_101</td>
      <td>G_102</td>
      <td>G_103</td>
      <td>G_104</td>
      <td>G_105</td>
      <td>G_106</td>
    </tr>
    <tr>
      <td>4</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
    </tr>
    <tr>
      <td>G_107</td>
      <td>G_108</td>
      <td>G_109</td>
      <td>G_110</td>
      <td>G_111</td>
      <td>G_112</td>
      <td>G_113</td>
      <td>G_114</td>
      <td>G_115</td>
      <td>G_116</td>
      <td>G_117</td>
    </tr>
    <tr>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
    </tr>
    <tr>
      <td>G_118</td>
      <td>G_119</td>
      <td>G_120</td>
      <td>G_121</td>
      <td>G_122</td>
      <td>G_123</td>
      <td>G_151</td>
      <td>G_152</td>
      <td>G_153</td>
      <td>NG_115</td>
      <td>NG_116</td>
    </tr>
    <tr>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
    </tr>
    <tr>
      <td>NG_117</td>
      <td>NG_118</td>
      <td>NG_119</td>
      <td>NG_120</td>
      <td>NG_121</td>
      <td>NG_122</td>
      <td>NG_123</td>
      <td>NG_124</td>
      <td>NG_125</td>
      <td>NG_126</td>
      <td>NG_127</td>
    </tr>
    <tr>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
    </tr>
    <tr>
      <td>NG_128</td>
      <td>NG_129</td>
      <td>NG_130</td>
      <td>NG_131</td>
      <td>NG_132</td>
      <td>NG_133</td>
      <td>NG_134</td>
      <td>NG_135</td>
      <td>NG_136</td>
      <td>NG_137</td>
      <td>NG_138</td>
    </tr>
    <tr>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
    </tr>
    <tr>
      <td>NG_139</td>
      <td>NG_140</td>
      <td>NG_141</td>
      <td>NG_142</td>
      <td>NG_143</td>
      <td>NG_144</td>
      <td>NG_145</td>
      <td>NG_146</td>
      <td>NG_147</td>
      <td>NG_148</td>
      <td>NG_149</td>
    </tr>
    <tr>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
      <td>5</td>
    </tr>
  </tbody>
</table>
## NG_150 G_124 G_125 G_126 G_127 G_128 G_129 G_130 G_131 G_132 G_133
## 5 6 6 6 6 6 6 6 6 6 6
## G_134 G_135 G_136 G_137 G_138 G_139 G_140 G_141 G_142 G_143 G_144
## 6 6 6 6 6 6 6 6 6 6 6
## G_145 G_146 G_147 G_148 G_149 G_150 NG_151 NG_152 NG_153 NG_154 NG_155
## 6 6 6 6 6 6 6 6 6 6 6
## NG_156 NG_157 NG_158 NG_159 NG_160 NG_161 NG_162 NG_163 NG_164 NG_165 NG_166
## 6 6 6 6 6 6 6 6 6 6 6
## NG_167 NG_168 NG_169 NG_170 NG_171 NG_172 NG_173 NG_174 NG_175 NG_176 NG_177
## 6 6 6 6 6 6 6 6 6 6 6
## NG_178 NG_179 NG_180 NG_181 NG_182 NG_183 NG_184 NG_185 NG_186 G_154 G_155
## 6 6 6 6 6 6 6 6 6 6 7
## G_156 G_157 G_158 G_159 G_160 G_161 G_162 G_163 G_164 G_165 G_166
## 7 7 7 7 7 7 7 7 7 7 7
## G_167 G_168 G_169 G_170 G_171 G_172 G_173 G_174 G_175 G_176 G_177
## 7 7 7 7 7 7 7 7 7 7 7
## G_178 G_179 G_180 NG_187 NG_188 NG_189 NG_190 NG_191 NG_192 NG_193 NG_194
## 7 7 7 7 7 7 7 7 7 7 7
## NG_195 NG_196 NG_197 NG_198 NG_199 NG_200 NG_201 NG_202 NG_203 NG_204 NG_205
## 7 7 7 7 7 7 7 7 7 7 7
## NG_206 NG_207 NG_208 NG_209 NG_210 NG_211 NG_212 NG_213 NG_214 NG_215 NG_216
## 7 7 7 7 7 7 7 7 7 7 7
## NG_217 NG_218 NG_219 NG_220 NG_221 NG_222
## 7 7 7 7 7 7 7

sort(km.resdat1_8$cluster)

## G_01 G_02 G_04 G_05 G_06 G_07 G_09 G_10 G_12 G_13 G_41
## 1 1 1 1 1 1 1 1 1 1 1
## G_42 G_43 G_44 G_45 G_46 G_47 G_48 G_03 G_08 G_11 G_14
## 1 1 1 1 1 1 1 2 2 2 2
## G_15 G_16 G_17 G_18 G_19 G_20 NG_01 NG_02 NG_03 NG_04 NG_05
## 2 2 2 2 2 2 2 2 2 2 2
## NG_06 NG_07 NG_08 NG_09 NG_10 NG_11 NG_12 NG_13 NG_14 NG_15 NG_16
## 2 2 2 2 2 2 2 2 2 2 2
## NG_17 NG_18 NG_19 NG_20 NG_21 NG_22 NG_23 NG_24 NG_25 NG_26 NG_27
## 2 2 2 2 2 2 2 2 2 2 2
## NG_28 NG_29 NG_30 NG_31 NG_32 NG_33 NG_70 NG_71 NG_72 G_21 G_22
## 2 2 2 2 2 2 2 2 2 3 3
## G_23 G_24 G_25 G_26 G_27 G_28 G_29 G_30 G_31 G_32 G_33
## 3 3 3 3 3 3 3 3 3 3 3
## G_34 G_35 G_36 G_37 G_38 G_39 G_40 G_49 G_50 G_51 G_52
## 3 3 3 3 3 3 3 3 3 3 3
## G_53 G_54 G_55 G_56 G_57 G_58 G_59 G_60 G_61 G_62 G_63
## 3 3 3 3 3 3 3 3 3 3 3
## G_64 G_65 G_66 NG_34 NG_35 NG_36 NG_37 NG_38 NG_39 NG_40 NG_41
7.5. KMEANS CLUSTERING

<table><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_42</td><td>NG_43</td><td>NG_44</td><td>NG_45</td><td>NG_46</td><td>NG_47</td><td>NG_48</td><td>NG_49</td><td>NG_50</td><td>NG_51</td><td>NG_52</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_53</td><td>NG_54</td><td>NG_55</td><td>NG_56</td><td>NG_57</td><td>NG_58</td><td>NG_59</td><td>NG_60</td><td>NG_61</td><td>NG_62</td><td>NG_63</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_64</td><td>NG_65</td><td>NG_66</td><td>NG_67</td><td>NG_68</td><td>NG_69</td><td>NG_73</td><td>NG_74</td><td>NG_75</td><td>G_67</td><td>G_68</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>4</td><td>4</td></tr><tr><td>##</td><td>G_69</td><td>G_70</td><td>G_71</td><td>G_73</td><td>G_76</td><td>G_77</td><td>G_78</td><td>G_79</td><td>G_80</td><td>G_81</td><td>G_91</td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>##</td><td>G_92</td><td>G_93</td><td>G_96</td><td>G_72</td><td>G_74</td><td>G_75</td><td>G_82</td><td>G_83</td><td>G_84</td><td>G_85</td><td>G_86</td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>G_87</td><td>G_88</td><td>G_89</td><td>G_90</td><td>G_94</td><td>G_95</td><td>NG_76</td><td>NG_77</td><td>NG_78</td><td>NG_79</td><td>NG_80</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>NG_81</td><td>NG_82</td><td>NG_83</td><td>NG_84</td><td>NG_85</td><td>NG_86</td><td>NG_87</td><td>NG_88</td><td>NG_89</td><td>NG_90</td><td>NG_91</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>NG_92</td><td>NG_93</td><td>NG_94</td><td>NG_95</td><td>NG_96</td><td>NG_97</td><td>NG_98</td><td>NG_99</td><td>NG_100</td><td>NG_101</td><td>NG_102</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>NG_103</td><td>NG_104</td><td>NG_105</td><td>NG_106</td><td>NG_107</td><td>NG_108</td><td>NG_109</td><td>NG_110</td><td>NG_111</td><td>NG_112</td><td>NG_113</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>NG_114</td><td>G_97</td><td>G_98</td><td>G_99</td><td>G_100</td><td>G_101</td><td>G_102</td><td>G_103</td><td>G_104</td><td>G_105</td><td>G_106</td></tr><tr><td>##</td><td>5</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>##</td><td>G_107</td><td>G_108</td><td>G_109</td><td>G_110</td><td>G_111</td><td>G_112</td><td>G_113</td><td>G_114</td><td>G_115</td><td>G_116</td><td>G_117</td></tr><tr><td>##</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>##</td><td>G_118</td><td>G_119</td><td>G_120</td><td>G_121</td><td>G_122</td><td>G_123</td><td>G_151</td><td>G_152</td><td>G_153</td><td>NG_115</td><td>NG_116</td></tr><tr><td>##</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>##</td><td>NG_117</td><td>NG_118</td><td>NG_119</td><td>NG_120</td><td>NG_121</td><td>NG_122</td><td>NG_123</td><td>NG_124</td><td>NG_125</td><td>NG_126</td><td>NG_127</td></tr><tr><td>##</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>##</td><td>NG_128</td><td>NG_129</td><td>NG_130</td><td>NG_131</td><td>NG_132</td><td>NG_133</td><td>NG_134</td><td>NG_135</td><td>NG_136</td><td>NG_137</td><td>NG_138</td></tr><tr><td>##</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>##</td><td>NG_139</td><td>NG_140</td><td>NG_141</td><td>NG_142</td><td>NG_143</td><td>NG_144</td><td>NG_145</td><td>NG_146</td><td>NG_147</td><td>NG_148</td><td>NG_149</td></tr><tr><td>##</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>##</td><td>NG_150</td><td>G_124</td><td>G_125</td><td>G_126</td><td>G_127</td><td>G_128</td><td>G_129</td><td>G_130</td><td>G_131</td><td>G_132</td><td>G_133</td></tr><tr><td>##</td><td>6</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td></tr><tr><td>##</td><td>G_134</td><td>G_135</td><td>G_136</td><td>G_137</td><td>G_138</td><td>G_139</td><td>G_140</td><td>G_141</td><td>G_142</td><td>G_143</td><td>G_144</td></tr><tr><td>##</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td></tr><tr><td>##</td><td>G_145</td><td>G_146</td><td>G_147</td><td>G_148</td><td>G_149</td><td>G_150</td><td>NG_151</td><td>NG_152</td><td>NG_153</td><td>NG_154</td><td>NG_155</td></tr><tr><td>##</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td></tr><tr><td>##</td><td>NG_156</td><td>NG_157</td><td>NG_158</td><td>NG_159</td><td>NG_160</td><td>NG_161</td><td>NG_162</td><td>NG_163</td><td>NG_164</td><td>NG_165</td><td>NG_166</td></tr><tr><td>##</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td></tr><tr><td>##</td><td>NG_167</td><td>NG_168</td><td>NG_169</td><td>NG_170</td><td>NG_171</td><td>NG_172</td><td>NG_173</td><td>NG_174</td><td>NG_175</td><td>NG_176</td><td>NG_177</td></tr><tr><td>##</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td></tr><tr><td>##</td><td>NG_178</td><td>NG_179</td><td>NG_180</td><td>NG_181</td><td>NG_182</td><td>NG_183</td><td>NG_184</td><td>NG_185</td><td>NG_186</td><td>G_154</td><td>G_155</td></tr><tr><td>##</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>8</td><td>8</td></tr><tr><td>##</td><td>G_156</td><td>G_157</td><td>G_158</td><td>G_159</td><td>G_160</td><td>G_161</td><td>G_162</td><td>G_163</td><td>G_164</td><td>G_165</td><td>G_166</td></tr><tr><td>##</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td></tr><tr><td>##</td><td>G_167</td><td>G_168</td><td>G_169</td><td>G_170</td><td>G_171</td><td>G_172</td><td>G_173</td><td>G_174</td><td>G_175</td><td>G_176</td><td>G_177</td></tr></table>
<table><tr><td>##</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td></tr><tr><td>##</td><td>G_178</td><td>G_179</td><td>G_180</td><td>NG_187</td><td>NG_188</td><td>NG_189</td><td>NG_190</td><td>NG_191</td><td>NG_192</td><td>NG_193</td><td>NG_194</td></tr><tr><td>##</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td></tr><tr><td>##</td><td>NG_195</td><td>NG_196</td><td>NG_197</td><td>NG_198</td><td>NG_199</td><td>NG_200</td><td>NG_201</td><td>NG_202</td><td>NG_203</td><td>NG_204</td><td>NG_205</td></tr><tr><td>##</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td></tr><tr><td>##</td><td>NG_206</td><td>NG_207</td><td>NG_208</td><td>NG_209</td><td>NG_210</td><td>NG_211</td><td>NG_212</td><td>NG_213</td><td>NG_214</td><td>NG_215</td><td>NG_216</td></tr><tr><td>##</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td></tr><tr><td>##</td><td>NG_217</td><td>NG_218</td><td>NG_219</td><td>NG_220</td><td>NG_221</td><td>NG_222</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>##</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td></td><td></td><td></td><td></td><td></td></tr></table>

sort(km.resdat1_9$cluster)

<table><tr><td>##</td><td>G_01</td><td>G_02</td><td>G_04</td><td>G_05</td><td>G_06</td><td>G_07</td><td>G_09</td><td>G_10</td><td>G_12</td><td>G_13</td><td>G_41</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr><tr><td>##</td><td>G_42</td><td>G_43</td><td>G_44</td><td>G_45</td><td>G_46</td><td>G_47</td><td>G_48</td><td>G_03</td><td>G_08</td><td>G_11</td><td>G_14</td></tr><tr><td>##</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>G_15</td><td>G_16</td><td>G_17</td><td>G_18</td><td>G_19</td><td>G_20</td><td>NG_01</td><td>NG_02</td><td>NG_03</td><td>NG_04</td><td>NG_05</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_06</td><td>NG_07</td><td>NG_08</td><td>NG_09</td><td>NG_10</td><td>NG_11</td><td>NG_12</td><td>NG_13</td><td>NG_14</td><td>NG_15</td><td>NG_16</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_17</td><td>NG_18</td><td>NG_19</td><td>NG_20</td><td>NG_21</td><td>NG_22</td><td>NG_23</td><td>NG_24</td><td>NG_25</td><td>NG_26</td><td>NG_27</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>##</td><td>NG_28</td><td>NG_29</td><td>NG_30</td><td>NG_31</td><td>NG_32</td><td>NG_33</td><td>NG_70</td><td>NG_71</td><td>NG_72</td><td>G_21</td><td>G_24</td></tr><tr><td>##</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>3</td></tr><tr><td>##</td><td>G_25</td><td>G_26</td><td>G_27</td><td>G_28</td><td>G_29</td><td>G_30</td><td>G_31</td><td>G_33</td><td>G_34</td><td>G_35</td><td>G_36</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>G_37</td><td>G_38</td><td>G_39</td><td>G_40</td><td>G_51</td><td>G_52</td><td>G_53</td><td>G_54</td><td>G_64</td><td>G_65</td><td>G_66</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_34</td><td>NG_35</td><td>NG_36</td><td>NG_37</td><td>NG_38</td><td>NG_39</td><td>NG_40</td><td>NG_41</td><td>NG_42</td><td>NG_43</td><td>NG_44</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_45</td><td>NG_46</td><td>NG_47</td><td>NG_48</td><td>NG_49</td><td>NG_50</td><td>NG_51</td><td>NG_52</td><td>NG_53</td><td>NG_54</td><td>NG_55</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_56</td><td>NG_57</td><td>NG_58</td><td>NG_59</td><td>NG_60</td><td>NG_61</td><td>NG_62</td><td>NG_63</td><td>NG_64</td><td>NG_65</td><td>NG_66</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>##</td><td>NG_67</td><td>NG_68</td><td>NG_69</td><td>NG_73</td><td>NG_74</td><td>NG_75</td><td>G_22</td><td>G_23</td><td>G_32</td><td>G_49</td><td>G_50</td></tr><tr><td>##</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>##</td><td>G_55</td><td>G_56</td><td>G_57</td><td>G_58</td><td>G_59</td><td>G_60</td><td>G_61</td><td>G_62</td><td>G_63</td><td>G_67</td><td>G_68</td></tr><tr><td>##</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>5</td><td>5</td></tr><tr><td>##</td><td>G_69</td><td>G_70</td><td>G_71</td><td>G_73</td><td>G_76</td><td>G_77</td><td>G_78</td><td>G_79</td><td>G_80</td><td>G_81</td><td>G_91</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>##</td><td>G_92</td><td>G_93</td><td>G_96</td><td>G_72</td><td>G_74</td><td>G_75</td><td>G_82</td><td>G_83</td><td>G_84</td><td>G_85</td><td>G_86</td></tr><tr><td>##</td><td>5</td><td>5</td><td>5</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>##</td><td>G_87</td><td>G_88</td><td>G_89</td><td>G_90</td><td>G_94</td><td>G_95</td><td>NG_76</td><td>NG_77</td><td>NG_78</td><td>NG_79</td><td>NG_80</td></tr><tr><td>##</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>##</td><td>NG_81</td><td>NG_82</td><td>NG_83</td><td>NG_84</td><td>NG_85</td><td>NG_86</td><td>NG_87</td><td>NG_88</td><td>NG_89</td><td>NG_90</td><td>NG_91</td></tr><tr><td>##</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr></table>
7.5. KMEANS CLUSTERING

2799

<table><tr><td>NG_92</td><td>NG_93</td><td>NG_94</td><td>NG_95</td><td>NG_96</td><td>NG_97</td><td>NG_98</td><td>NG_99</td><td>NG_100</td><td>NG_101</td><td>NG_102</td></tr><tr><td>NG_103</td><td>NG_104</td><td>NG_105</td><td>NG_106</td><td>NG_107</td><td>NG_108</td><td>NG_109</td><td>NG_110</td><td>NG_111</td><td>NG_112</td><td>NG_113</td></tr><tr><td>NG_114</td><td>G_97</td><td>G_98</td><td>G_99</td><td>G_100</td><td>G_101</td><td>G_102</td><td>G_103</td><td>G_104</td><td>G_105</td><td>G_106</td></tr><tr><td>G_107</td><td>G_108</td><td>G_109</td><td>G_110</td><td>G_111</td><td>G_112</td><td>G_113</td><td>G_114</td><td>G_115</td><td>G_116</td><td>G_117</td></tr><tr><td>G_118</td><td>G_119</td><td>G_120</td><td>G_121</td><td>G_122</td><td>G_123</td><td>G_151</td><td>G_152</td><td>G_153</td><td>NG_115</td><td>NG_116</td></tr><tr><td>NG_117</td><td>NG_118</td><td>NG_119</td><td>NG_120</td><td>NG_121</td><td>NG_122</td><td>NG_123</td><td>NG_124</td><td>NG_125</td><td>NG_126</td><td>NG_127</td></tr><tr><td>NG_128</td><td>NG_129</td><td>NG_130</td><td>NG_131</td><td>NG_132</td><td>NG_133</td><td>NG_134</td><td>NG_135</td><td>NG_136</td><td>NG_137</td><td>NG_138</td></tr><tr><td>NG_139</td><td>NG_140</td><td>NG_141</td><td>NG_142</td><td>NG_143</td><td>NG_144</td><td>NG_145</td><td>NG_146</td><td>NG_147</td><td>NG_148</td><td>NG_149</td></tr><tr><td>NG_150</td><td>G_124</td><td>G_125</td><td>G_126</td><td>G_127</td><td>G_128</td><td>G_129</td><td>G_130</td><td>G_131</td><td>G_132</td><td>G_133</td></tr><tr><td>G_134</td><td>G_135</td><td>G_136</td><td>G_137</td><td>G_138</td><td>G_139</td><td>G_140</td><td>G_141</td><td>G_142</td><td>G_143</td><td>G_144</td></tr><tr><td>G_145</td><td>G_146</td><td>G_147</td><td>G_148</td><td>G_149</td><td>G_150</td><td>NG_151</td><td>NG_152</td><td>NG_153</td><td>NG_154</td><td>NG_155</td></tr><tr><td>NG_156</td><td>NG_157</td><td>NG_158</td><td>NG_159</td><td>NG_160</td><td>NG_161</td><td>NG_162</td><td>NG_163</td><td>NG_164</td><td>NG_165</td><td>NG_166</td></tr><tr><td>NG_167</td><td>NG_168</td><td>NG_169</td><td>NG_170</td><td>NG_171</td><td>NG_172</td><td>NG_173</td><td>NG_174</td><td>NG_175</td><td>NG_176</td><td>NG_177</td></tr><tr><td>NG_178</td><td>NG_179</td><td>NG_180</td><td>NG_181</td><td>NG_182</td><td>NG_183</td><td>NG_184</td><td>NG_185</td><td>NG_186</td><td>G_154</td><td>G_155</td></tr><tr><td>G_156</td><td>G_157</td><td>G_158</td><td>G_159</td><td>G_160</td><td>G_161</td><td>G_162</td><td>G_163</td><td>G_164</td><td>G_165</td><td>G_166</td></tr><tr><td>G_167</td><td>G_168</td><td>G_169</td><td>G_170</td><td>G_171</td><td>G_172</td><td>G_173</td><td>G_174</td><td>G_175</td><td>G_176</td><td>G_177</td></tr><tr><td>G_178</td><td>G_179</td><td>G_180</td><td>NG_187</td><td>NG_188</td><td>NG_189</td><td>NG_190</td><td>NG_191</td><td>NG_192</td><td>NG_193</td><td>NG_194</td></tr><tr><td>NG_195</td><td>NG_196</td><td>NG_197</td><td>NG_198</td><td>NG_199</td><td>NG_200</td><td>NG_201</td><td>NG_202</td><td>NG_203</td><td>NG_204</td><td>NG_205</td></tr><tr><td>NG_206</td><td>NG_207</td><td>NG_208</td><td>NG_209</td><td>NG_210</td><td>NG_211</td><td>NG_212</td><td>NG_213</td><td>NG_214</td><td>NG_215</td><td>NG_216</td></tr><tr><td>NG_217</td><td>NG_218</td><td>NG_219</td><td>NG_220</td><td>NG_221</td><td>NG_222</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>NG_221</td><td>NG_222</td><td>NG_223</td><td>NG_224</td><td>NG_225</td><td>NG_226</td><td>NG_227</td><td>NG_228</td><td>NG_229</td><td>NG_230</td><td>NG_231</td></tr></table>

sort(km.resdat1_10$cluster)

<table><tr><td>G_01</td><td>G_02</td><td>G_04</td><td>G_05</td><td>G_06</td><td>G_07</td><td>G_09</td><td>G_10</td><td>G_12</td><td>G_13</td><td>G_41</td></tr><tr><td>G_1</td><td>G_1</td><td>G_1</td><td>G_1</td><td>G_1</td><td>G_1</td><td>G_1</td><td>G_1</td><td>G_1</td><td>G_1</td><td>G_1</td></tr><tr><td>G_42</td><td>G_43</td><td>G_44</td><td>G_45</td><td>G_46</td><td>G_47</td><td>G_48</td><td>G_03</td><td>G_08</td><td>G_11</td><td>G_14</td></tr></table>
<table><thead><tr><th>##</th><th>1</th><th>1</th><th>1</th><th>1</th><th>1</th><th>1</th><th>1</th><th>2</th><th>2</th><th>2</th><th>2</th></tr></thead><tbody><tr><td>## G_15</td><td>G_16</td><td>G_17</td><td>G_18</td><td>G_19</td><td>G_20</td><td>NG_01</td><td>NG_02</td><td>NG_03</td><td>NG_04</td><td>NG_05</td></tr><tr><td>## 2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>## NG_06</td><td>NG_07</td><td>NG_08</td><td>NG_09</td><td>NG_10</td><td>NG_11</td><td>NG_12</td><td>NG_13</td><td>NG_14</td><td>NG_15</td><td>NG_16</td></tr><tr><td>## 2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>## NG_17</td><td>NG_18</td><td>NG_19</td><td>NG_20</td><td>NG_21</td><td>NG_22</td><td>NG_23</td><td>NG_24</td><td>NG_25</td><td>NG_26</td><td>NG_27</td></tr><tr><td>## 2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr><tr><td>## NG_28</td><td>NG_29</td><td>NG_30</td><td>NG_31</td><td>NG_32</td><td>NG_33</td><td>NG_70</td><td>NG_71</td><td>NG_72</td><td>G_21</td><td>G_24</td></tr><tr><td>## 2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>3</td><td>3</td></tr><tr><td>## G_25</td><td>G_26</td><td>G_27</td><td>G_28</td><td>G_29</td><td>G_30</td><td>G_31</td><td>G_33</td><td>G_34</td><td>G_35</td><td>G_36</td></tr><tr><td>## 3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>## G_37</td><td>G_38</td><td>G_39</td><td>G_40</td><td>G_51</td><td>G_52</td><td>G_53</td><td>G_54</td><td>G_64</td><td>G_65</td><td>G_66</td></tr><tr><td>## 3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>## NG_34</td><td>NG_35</td><td>NG_36</td><td>NG_37</td><td>NG_38</td><td>NG_39</td><td>NG_40</td><td>NG_41</td><td>NG_42</td><td>NG_43</td><td>NG_44</td></tr><tr><td>## 3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>## NG_45</td><td>NG_46</td><td>NG_47</td><td>NG_48</td><td>NG_49</td><td>NG_50</td><td>NG_51</td><td>NG_52</td><td>NG_53</td><td>NG_54</td><td>NG_55</td></tr><tr><td>## 3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>## NG_56</td><td>NG_57</td><td>NG_58</td><td>NG_59</td><td>NG_60</td><td>NG_61</td><td>NG_62</td><td>NG_63</td><td>NG_64</td><td>NG_65</td><td>NG_66</td></tr><tr><td>## 3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr><tr><td>## NG_67</td><td>NG_68</td><td>NG_69</td><td>NG_73</td><td>NG_74</td><td>NG_75</td><td>G_22</td><td>G_23</td><td>G_32</td><td>G_49</td><td>G_50</td></tr><tr><td>## 3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td></tr><tr><td>## G_55</td><td>G_56</td><td>G_57</td><td>G_58</td><td>G_59</td><td>G_60</td><td>G_61</td><td>G_62</td><td>G_63</td><td>G_67</td><td>G_68</td></tr><tr><td>## 4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>4</td><td>5</td><td>5</td></tr><tr><td>## G_69</td><td>G_70</td><td>G_71</td><td>G_73</td><td>G_76</td><td>G_77</td><td>G_78</td><td>G_79</td><td>G_80</td><td>G_81</td><td>G_91</td></tr><tr><td>## 5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td><td>5</td></tr><tr><td>## G_92</td><td>G_93</td><td>G_96</td><td>G_72</td><td>G_74</td><td>G_75</td><td>G_82</td><td>G_83</td><td>G_84</td><td>G_85</td><td>G_86</td></tr><tr><td>## 5</td><td>5</td><td>5</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>## G_87</td><td>G_88</td><td>G_89</td><td>G_90</td><td>G_94</td><td>G_95</td><td>NG_76</td><td>NG_77</td><td>NG_78</td><td>NG_79</td><td>NG_80</td></tr><tr><td>## 6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>## NG_81</td><td>NG_82</td><td>NG_83</td><td>NG_84</td><td>NG_85</td><td>NG_86</td><td>NG_87</td><td>NG_88</td><td>NG_89</td><td>NG_90</td><td>NG_91</td></tr><tr><td>## 6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>## NG_92</td><td>NG_93</td><td>NG_94</td><td>NG_95</td><td>NG_96</td><td>NG_97</td><td>NG_98</td><td>NG_99</td><td>NG_100</td><td>NG_101</td><td>NG_102</td></tr><tr><td>## 6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>## NG_103</td><td>NG_104</td><td>NG_105</td><td>NG_106</td><td>NG_107</td><td>NG_108</td><td>NG_109</td><td>NG_110</td><td>NG_111</td><td>NG_112</td><td>NG_113</td></tr><tr><td>## 6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td><td>6</td></tr><tr><td>## NG_114</td><td>G_97</td><td>G_98</td><td>G_99</td><td>G_100</td><td>G_101</td><td>G_102</td><td>G_103</td><td>G_104</td><td>G_105</td><td>G_106</td></tr><tr><td>## 6</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td></tr><tr><td>## G_107</td><td>G_108</td><td>G_109</td><td>G_110</td><td>G_111</td><td>G_112</td><td>G_113</td><td>G_114</td><td>G_115</td><td>G_116</td><td>G_117</td></tr><tr><td>## 7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td></tr><tr><td>## G_118</td><td>G_119</td><td>G_120</td><td>G_121</td><td>G_122</td><td>G_123</td><td>G_151</td><td>G_152</td><td>G_153</td><td>NG_115</td><td>NG_116</td></tr><tr><td>## 7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td></tr><tr><td>## NG_117</td><td>NG_118</td><td>NG_119</td><td>NG_120</td><td>NG_121</td><td>NG_122</td><td>NG_123</td><td>NG_124</td><td>NG_125</td><td>NG_126</td><td>NG_127</td></tr><tr><td>## 7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td></tr><tr><td>## NG_128</td><td>NG_129</td><td>NG_130</td><td>NG_131</td><td>NG_132</td><td>NG_133</td><td>NG_134</td><td>NG_135</td><td>NG_136</td><td>NG_137</td><td>NG_138</td></tr><tr><td>## 7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td></tr><tr><td>## NG_139</td><td>NG_140</td><td>NG_141</td><td>NG_142</td><td>NG_143</td><td>NG_144</td><td>NG_145</td><td>NG_146</td><td>NG_147</td><td>NG_148</td><td>NG_149</td></tr></tbody></table>
<table><tr><td>##</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td></tr><tr><td>##</td><td>NG_150</td><td>G_124</td><td>G_125</td><td>G_126</td><td>G_127</td><td>G_128</td><td>G_129</td><td>G_130</td><td>G_131</td><td>G_132</td><td>G_133</td></tr><tr><td>##</td><td>7</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td></tr><tr><td>##</td><td>G_134</td><td>G_135</td><td>G_136</td><td>G_137</td><td>G_138</td><td>G_139</td><td>G_140</td><td>G_141</td><td>G_142</td><td>G_143</td><td>G_144</td></tr><tr><td>##</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td></tr><tr><td>##</td><td>G_145</td><td>G_146</td><td>G_147</td><td>G_148</td><td>G_149</td><td>G_150</td><td>NG_151</td><td>NG_152</td><td>NG_153</td><td>NG_154</td><td>NG_155</td></tr><tr><td>##</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td></tr><tr><td>##</td><td>NG_156</td><td>NG_157</td><td>NG_158</td><td>NG_159</td><td>NG_160</td><td>NG_161</td><td>NG_162</td><td>NG_163</td><td>NG_164</td><td>NG_165</td><td>NG_166</td></tr><tr><td>##</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td></tr><tr><td>##</td><td>NG_167</td><td>NG_168</td><td>NG_169</td><td>NG_170</td><td>NG_171</td><td>NG_172</td><td>NG_173</td><td>NG_174</td><td>NG_175</td><td>NG_176</td><td>NG_177</td></tr><tr><td>##</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td></tr><tr><td>##</td><td>NG_178</td><td>NG_179</td><td>NG_180</td><td>NG_181</td><td>NG_182</td><td>NG_183</td><td>NG_184</td><td>NG_185</td><td>NG_186</td><td>G_154</td><td>G_155</td></tr><tr><td>##</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>8</td><td>9</td><td>9</td></tr><tr><td>##</td><td>G_156</td><td>G_165</td><td>G_172</td><td>G_173</td><td>G_174</td><td>G_175</td><td>G_176</td><td>G_177</td><td>NG_187</td><td>NG_188</td><td>NG_189</td></tr><tr><td>##</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td></tr><tr><td>##</td><td>NG_190</td><td>NG_191</td><td>NG_192</td><td>NG_195</td><td>NG_196</td><td>NG_197</td><td>NG_198</td><td>NG_199</td><td>NG_200</td><td>NG_201</td><td>NG_202</td></tr><tr><td>##</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td></tr><tr><td>##</td><td>NG_203</td><td>NG_204</td><td>NG_205</td><td>NG_206</td><td>NG_207</td><td>NG_208</td><td>NG_209</td><td>NG_210</td><td>NG_215</td><td>NG_216</td><td>NG_218</td></tr><tr><td>##</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td></tr><tr><td>##</td><td>NG_219</td><td>NG_220</td><td>NG_221</td><td>NG_222</td><td>G_157</td><td>G_158</td><td>G_159</td><td>G_160</td><td>G_161</td><td>G_162</td><td>G_163</td></tr><tr><td>##</td><td>9</td><td>9</td><td>9</td><td>9</td><td>9</td><td>10</td><td>10</td><td>10</td><td>10</td><td>10</td><td>10</td></tr><tr><td>##</td><td>G_164</td><td>G_166</td><td>G_167</td><td>G_168</td><td>G_169</td><td>G_170</td><td>G_171</td><td>G_178</td><td>G_179</td><td>G_180</td><td>NG_193</td></tr><tr><td>##</td><td>10</td><td>10</td><td>10</td><td>10</td><td>10</td><td>10</td><td>10</td><td>10</td><td>10</td><td>10</td><td>10</td></tr><tr><td>##</td><td>NG_194</td><td>NG_211</td><td>NG_212</td><td>NG_213</td><td>NG_214</td><td>NG_217</td><td></td><td></td><td></td><td></td><td></td></tr><tr><td>##</td><td>10</td><td>10</td><td>10</td><td>10</td><td>10</td><td>10</td><td></td><td></td><td></td><td></td><td></td></tr></table>

### 7.5.2 Conclusion

Cluster analysis is useful in many cases as it provides insights into how the various predictors interact with each other to allow for clusters to emerge. Given that these are independent of the actual groupings of your dependent variable (context), one can use them to interpret the results in a more in-depth way and allow you to be critical about the original grouping. Do not forget that the two guttural and non-guttural are composed each of three contexts (guttural = uvula, pharyngealised and pharyngeal; non-guttural = plain coronal, velar and glottal). Each of the contexts is produced in an /i: a: u:/ contexts. Hence, cluster analysis, which was restricted to a maximum of 10 clusters, picked this up.

## 7.6 Multidimensional scaling

In this section, we explore multidimensional scaling. This is another unsupervised learning algorithm. As with cluster analysis, we start by running the MDS algorithm and use Kmeans clustering to allow visualisation of the two-dimensional data. Usually, up to 5 dimensions explain a large percentage of the
variance in the data; in our case, we only go for 2 dimensions to evaluate how
the two groups are close (or not) to each other). As with cluster analysis, we
could compute number of clusters; something we are not doing here.

7.6.1 Computing MDS

We perform a MDS Clustering with 2 Clusters. We use a Euclidean distance
matrix. See here for details on the available dissimilarity methods.

```
dat1MDS <- dfPharPCA

set.seed(123)

mds.resdat1 <- dat1MDS[-1] %>%
  dist(method = 'euclidean') %>%
  cmdscale() %>%
  as_tibble()

colnames(mds.resdat1) <- c("Dim.1", "Dim.2")

mds.resdat1 %>% head(10)

## # A tibble: 10 x 2
## Dim.1 Dim.2
## <db1> <db1>
## 1 -45.4 10.1
## 2 -24.6 1.90
## 3 -52.0 6.85
## 4 -36.1 19.9
## 5 -25.2 11.3
## 6 -40.5 10.1
## 7 -40.8 12.0
## 8 -38.0 3.41
## 9 -30.2 10.3
## 10 -19.5 5.61
```

7.6.2 Kmeans clustering

```
## K-means clustering
clust <- kmeans(mds.resdat1, 2)$cluster %>%
  as.factor()

mds.resdat1 <- mds.resdat1 %>%
  mutate(groups = clust)

mds.resdat1$context <- dat1MDS$context
```
### 7.6.3 Plot

```r
## Plot and color by groups
ggscatter(mds.resdat1, x = "Dim.1", y = "Dim.2", col = "context",
          label = NULL,
          color = "context",
          palette = c("red", "blue"),
          size = 2,
          ellipse = TRUE,
          ellipse.type = "convex",
          repel = FALSE,
          shape = "context",
          point = FALSE,
          mean.point = TRUE)
```

<figure><img src="image_260.png" /></figure>

## 7.7 session info

```r
sessionInfo()

## R version 4.5.2 (2025-10-31 ucrt)
## Platform: x86_64-w64-mingw32/x64
## Running under: Windows 11 x64 (build 26200)
##
## Matrix products: default
## LAPACK version 3.12.1
```
##

## locale:

## [1] LC_COLLATE=English_United Kingdom.utf8

## [2] LC_CTYPE=English_United Kingdom.utf8

## [3] LC_MONETARY=English_United Kingdom.utf8

## [4] LC_NUMERIC=C

## [5] LC_TIME=English_United Kingdom.utf8

##

## time zone: Europe/Paris

## tzcode source: internal

##

## attached base packages:

## [1] stats graphics grDevices utils datasets methods base

##

## other attached packages:

## [1] zoo_1.8-14 ggrepel_0.9.6

## [3] ggpubr_0.6.2 GGally_2.4.0

## [5] cowplot_1.2.0 cluster_2.1.8.1

## [7] recipes_1.3.1 scatterplot3d_0.3-44

## [9] webshot_0.5.5 FactoInvestigate_1.9

## [11] factoextra_1.0.7 FactoMineR_2.12

## [13] quanteda.textstats_0.97.2 wordcloud_2.6

## [15] RColorBrewer_1.1-3 ggraph_2.2.2

## [17] textplot_0.2.2 udpipe_0.8.14

## [19] quanteda.textplots_0.96.1 stopwords_2.3

## [21] SnowballC_0.7.1 tm_0.7-16

## [23] NLP_0.3-2 readtext_0.92.1

## [25] quanteda_4.3.1 gutenbergr_0.3.0

## [27] textdata_0.4.5 proustr_0.4.0

## [29] janeaustenr_1.0.0 rvest_1.0.5

## [31] tidytext_0.4.3 lattice_0.22-7

## [33] paletteer_1.6.0 ggstatsplot_0.13.3

## [35] ggstats_0.11.0 itsadug_2.4.1

## [37] plotfunctions_1.4 mgcv_1.9-4

## [39] nlme_3.1-168 lme4_1.1-37

## [41] Matrix_1.7-4 faux_1.2.3

## [43] car_3.1-3 carData_3.0-5

## [45] parameters_0.28.3 datawizard_1.3.0

## [47] effectsize_1.0.1 pwr_1.3-0

## [49] htmltools_0.5.8.1 sjPlot_2.9.0

## [51] DHARMa_0.4.7 ordinal_2023.12-4.1

## [53] psycho_0.6.1 PresenceAbsence_1.1.11

## [55] ggsignif_0.6.4 emmeans_2.0.0

## [57] corrplot_0.95 Hmisc_5.2-4

## [59] knitr_1.50 broom_1.0.10

## [61] cardx_0.3.0 gtsummary_2.4.0
<table><tr><td>[63]</td><td>ggdist_3.3.3</td><td>summarytools_1.1.4</td></tr><tr><td>[65]</td><td>phonR_1.0-7</td><td>languageR_1.6</td></tr><tr><td>[67]</td><td>lubridate_1.9.4</td><td>forcats_1.0.1</td></tr><tr><td>[69]</td><td>stringr_1.6.0</td><td>dplyr_1.1.4</td></tr><tr><td>[71]</td><td>purrr_1.2.0</td><td>readr_2.1.6</td></tr><tr><td>[73]</td><td>tidyr_1.3.1</td><td>tibble_3.3.0</td></tr><tr><td>[75]</td><td>ggplot2_4.0.1</td><td>tidyverse_2.0.0</td></tr></table>

<table><tr><td colspan="2">## loaded via a namespace (and not attached):</td></tr><tr><td>[1]</td><td>vroom_1.6.6</td><td>gap.datasets_0.0.6 sjmisc_2.8.11</td></tr><tr><td>[4]</td><td>nnet_7.3-20</td><td>DT_0.34.0 TH.data_1.1-5</td></tr><tr><td>[7]</td><td>vctrs_0.6.5</td><td>digest_0.6.39 bayestestR_0.17.0</td></tr><tr><td>[10]</td><td>correlation_0.8.8</td><td>parallelly_1.45.1 magick_2.9.0</td></tr><tr><td>[13]</td><td>MASS_7.3-65</td><td>reshape2_1.4.5 withr_3.0.2</td></tr><tr><td>[16]</td><td>xfun_0.54</td><td>survival_3.8-3 memoise_2.0.1</td></tr><tr><td>[19]</td><td>commonmark_2.0.0</td><td>ggsci_4.1.0 Formula_1.2-5</td></tr><tr><td>[22]</td><td>ellipse_0.5.0</td><td>rematch2_2.1.2 httr_1.4.7</td></tr><tr><td>[25]</td><td>rstatix_0.7.3</td><td>globals_0.18.0 ps_1.9.1</td></tr><tr><td>[28]</td><td>rstudioapi_0.17.1</td><td>generics_0.1.4 processx_3.8.6</td></tr><tr><td>[31]</td><td>base64enc_0.1-3</td><td>curl_7.0.0 polyclip_1.10-7</td></tr><tr><td>[34]</td><td>ggeffects_2.3.1</td><td>quadprog_1.5-8 xtable_1.8-4</td></tr><tr><td>[37]</td><td>evaluate_1.0.5</td><td>hms_1.1.4 bookdown_0.45</td></tr><tr><td>[40]</td><td>colorspace_2.1-2</td><td>labelled_2.16.0 magrittr_2.0.4</td></tr><tr><td>[43]</td><td>snakecase_0.11.1</td><td>viridis_0.6.5 future.apply_1.20.0</td></tr><tr><td>[46]</td><td>matrixStats_1.5.0</td><td>class_7.3-23 gap_1.6</td></tr><tr><td>[49]</td><td>pillar_1.11.1</td><td>performance_0.15.2 sna_2.8</td></tr><tr><td>[52]</td><td>compiler_4.5.2</td><td>stringi_1.8.7 gower_1.0.2</td></tr><tr><td>[55]</td><td>dendextend_1.19.1</td><td>tokenizers_0.3.0 minqa_1.2.8</td></tr><tr><td>[58]</td><td>plyr_1.8.9</td><td>crayon_1.5.3 abind_1.4-8</td></tr><tr><td>[61]</td><td>haven_2.5.5</td><td>sp_2.2-0 graphlayouts_1.2.2</td></tr><tr><td>[64]</td><td>bit_4.6.0</td><td>rapportools_1.2 sandwich_3.1-1</td></tr><tr><td>[67]</td><td>fastmatch_1.1-6</td><td>codetools_0.2-20 multcomp_1.4-29</td></tr><tr><td>[70]</td><td>bslib_0.9.0</td><td>slam_0.1-55 ucminf_1.2.2</td></tr><tr><td>[73]</td><td>splines_4.5.2</td><td> markdown_2.0 Rcpp_1.1.0</td></tr><tr><td>[76]</td><td>streamR_0.4.5</td><td>prismatic_1.1.2 attempt_0.3.1</td></tr><tr><td>[79]</td><td>leaps_3.2</td><td>utf8_1.2.6 fs_1.6.6</td></tr><tr><td>[82]</td><td>listenv_0.10.0</td><td>checkmate_2.3.3 Rdpack_2.6.4</td></tr><tr><td>[85]</td><td>estimability_1.5.1</td><td>pdftools_3.6.0 callr_3.7.6</td></tr><tr><td>[88]</td><td>nsyllable_1.0.1</td><td>tzdb_0.5.0 tweenr_2.0.3</td></tr><tr><td>[91]</td><td>pkgconfig_2.0.3</td><td>network_1.19.0 tools_4.5.2</td></tr><tr><td>[94]</td><td>cachem_1.1.0</td><td>rbibutils_2.4 viridisLite_0.4.2</td></tr><tr><td>[97]</td><td>numDeriv_2016.8-1.1</td><td>fastmap_1.2.0 rmarkdown_2.30</td></tr><tr><td>[100]</td><td>scales_1.4.0</td><td>grid_4.5.2 gt_1.1.0</td></tr><tr><td>[103]</td><td>cards_0.7.0</td><td>sass_0.4.10 patchwork_1.3.2</td></tr><tr><td>[106]</td><td>coda_0.19-4.1</td><td>insight_1.4.3 selectr_0.5-0</td></tr><tr><td>[109]</td><td>rpart_4.1.24</td><td>farver_2.1.2 reformulas_0.4.2</td></tr></table>
<table>
  <tr>
    <td>[112]</td>
    <td>tidygraph_1.3.1</td>
    <td>yaml_2.3.10</td>
    <td>readMDTable_0.3.2</td>
  </tr>
  <tr>
    <td>[115]</td>
    <td>foreign_0.8-90</td>
    <td>cli_3.6.5</td>
    <td>lifecycle_1.0.4</td>
  </tr>
  <tr>
    <td>[118]</td>
    <td>askpass_1.2.1</td>
    <td>mvtnorm_1.3-3</td>
    <td>lava_1.8.2</td>
  </tr>
  <tr>
    <td>[121]</td>
    <td>backports_1.5.0</td>
    <td>timechange_0.3.0</td>
    <td>gtable_0.3.6</td>
  </tr>
  <tr>
    <td>[124]</td>
    <td>rjson_0.2.23</td>
    <td>parallel_4.5.2</td>
    <td>jsonlite_2.0.0</td>
  </tr>
  <tr>
    <td>[127]</td>
    <td>bitops_1.0-9</td>
    <td>multcompView_0.1-10</td>
    <td>bit64_4.6.0-1</td>
  </tr>
  <tr>
    <td>[130]</td>
    <td>litedown_0.8</td>
    <td>RcppParallel_5.1.11-1</td>
    <td>jquerylib_0.1.4</td>
  </tr>
  <tr>
    <td>[133]</td>
    <td>zeallot_0.2.0</td>
    <td>distributional_0.5.0</td>
    <td>timeDate_4051.111</td>
  </tr>
  <tr>
    <td>[136]</td>
    <td>ndjson_0.9.1</td>
    <td>pander_0.6.6</td>
    <td>sjlabelled_1.2.0</td>
  </tr>
  <tr>
    <td>[139]</td>
    <td>tinytex_0.58</td>
    <td>glue_1.8.0</td>
    <td>tktk_4.5.2</td>
  </tr>
  <tr>
    <td>[142]</td>
    <td>broom helpers_1.22.0</td>
    <td>RCurl_1.98-1.17</td>
    <td>qpdf_1.4.1</td>
  </tr>
  <tr>
    <td>[145]</td>
    <td>gridExtra_2.3</td>
    <td>boot_1.3-32</td>
    <td>flashClust_1.01-2</td>
  </tr>
  <tr>
    <td>[148]</td>
    <td>igraph_2.2.1</td>
    <td>R6_2.6.1</td>
    <td>broom.mixed_0.2.9.6</td>
  </tr>
  <tr>
    <td>[151]</td>
    <td>labeling_0.4.3</td>
    <td>ipred_0.9-15</td>
    <td>nloptr_2.2.1</td>
  </tr>
  <tr>
    <td>[154]</td>
    <td>statnet common_4.12.0</td>
    <td>rstantools_2.5.0</td>
    <td>tidyselect_1.2.1</td>
  </tr>
  <tr>
    <td>[157]</td>
    <td>htmlTable_2.4.3</td>
    <td>ggforce_0.5.0</td>
    <td>xml2_1.5.0</td>
  </tr>
  <tr>
    <td>[160]</td>
    <td>future_1.68.0</td>
    <td>statsExpressions_1.7.1</td>
    <td>S7_0.2.1</td>
  </tr>
  <tr>
    <td>[163]</td>
    <td>furrr_0.3.1</td>
    <td>pryr_0.1.6</td>
    <td>splancs_2.01-45</td>
  </tr>
  <tr>
    <td>[166]</td>
    <td>data.table_1.17.8</td>
    <td>htmlwidgets_1.6.4</td>
    <td>rlang_1.1.6</td>
  </tr>
  <tr>
    <td>[169]</td>
    <td>hardhat_1.4.2</td>
    <td>prodlim_2025.04.28</td>
    <td></td>
  </tr>
</table>
# Chapter 8

## Decision trees and Random Forests

This chapter provides details of how to grow Random Forests for phonetic data. This is not exclusive to phonetic data and can be used for any other type of data.

We will start by looking at the basics of predictive modelling. We will look at some issues with logistic regression related to collinearity and multicollinearity. In chapter 2, we looked at various notions obtained from Signal Detection Theory in section 2.6.4. We will use these to evaluate the performance of our models. We introduce decision trees to understand how they work, before attempting to replicate how Random Forests work. We then grow our first Random Forests using the party and the ranger packages and try to capture as much information as possible from it. At the end, we look at the approach advocated by tidymodels.

### 8.1 What is predictive modelling

The majority of research in phonetics and linguistics looks at traditional statistical techniques to evaluate group differences, using either frequentist or Bayesian frameworks. What is important in these frameworks is to assess whether a particular outcome can be explained by the potential differences that exist in a predictor. For example, we may want to examine if the differences observed in F2 frequency at the vowel midpoint can be explained by place of articulation, or age or gender. For this we use a linear regression (with or without mixed effects modelling) with the following formula: `lm(F2 ~ place + age + gender)`.

This approach can potentially explain the differences associated with the predictors, i.e., we evaluate their influence on the outcome. But let's ask the following
dfPharV2

<table><caption>## # A tibble: 402 x 25</caption><thead><tr><th colspan="2">contextN</th><th>context</th><th>CPP</th><th>Energy</th><th>H1A1c</th><th>H1A2c</th><th>H1A3c</th><th>H1H2c</th><th>H2H4c</th><th>H2KH5Kc</th></tr><tr><th>&lt;chr&gt;</th><th>&lt;chr&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th></tr></thead><tbody><tr><td>1</td><td>G_01</td><td>Guttural</td><td>23.5</td><td>22.8</td><td>15.2</td><td>16.0</td><td>-3.30</td><td>-1.18</td><td>2.65</td><td>23.2</td></tr><tr><td>2</td><td>G_02</td><td>Guttural</td><td>25.7</td><td>22.8</td><td>13.2</td><td>11.6</td><td>-5.92</td><td>-0.739</td><td>1.65</td><td>16.5</td></tr><tr><td>3</td><td>G_03</td><td>Guttural</td><td>19.6</td><td>9.16</td><td>16.5</td><td>18.5</td><td>0.604</td><td>-0.928</td><td>4.50</td><td>18.5</td></tr><tr><td>4</td><td>G_04</td><td>Guttural</td><td>23.6</td><td>17.2</td><td>16.0</td><td>20.1</td><td>-7.63</td><td>0.782</td><td>2.42</td><td>28.2</td></tr><tr><td>5</td><td>G_05</td><td>Guttural</td><td>26.0</td><td>15.6</td><td>14.5</td><td>14.6</td><td>-6.73</td><td>0.0442</td><td>3.13</td><td>27.6</td></tr><tr><td>6</td><td>G_06</td><td>Guttural</td><td>24.5</td><td>14.4</td><td>16.6</td><td>16.6</td><td>-5.46</td><td>1.34</td><td>4.51</td><td>21.6</td></tr><tr><td>7</td><td>G_07</td><td>Guttural</td><td>23.1</td><td>18.6</td><td>15.0</td><td>15.8</td><td>-5.94</td><td>-0.211</td><td>2.11</td><td>26.3</td></tr><tr><td>8</td><td>G_08</td><td>Guttural</td><td>22.2</td><td>9.04</td><td>17.1</td><td>18.4</td><td>2.10</td><td>-0.742</td><td>3.41</td><td>19.1</td></tr><tr><td>9</td><td>G_09</td><td>Guttural</td><td>28.4</td><td>25.5</td><td>12.5</td><td>15.1</td><td>-3.33</td><td>-1.59</td><td>3.80</td><td>25.6</td></tr><tr><td>10</td><td>G_10</td><td>Guttural</td><td>28.2</td><td>15.8</td><td>14.7</td><td>16.3</td><td>-0.0528</td><td>0.108</td><td>3.50</td><td>22.5</td></tr></tbody></table>

## # i 392 more rows

## # i 15 more variables: H42Kc <dbl>, HNR05 <dbl>, HNR15 <dbl>, HNR25 <dbl>,
## # HNR35 <dbl>, SHR <dbl>, soe <dbl>, Z1mnZ0 <dbl>, Z2mnZ1 <dbl>,
## # Z3mnZ2 <dbl>, Z4mnZ3 <dbl>, F0Bark <dbl>, A1mnA2 <dbl>, A1mnA3 <dbl>,
## # A2mnA3 <dbl>

dfPharV2 <- dfPharV2 %>%

select(-contextN) %>%

mutate(context = factor(context, levels = c("Non-Guttural", "Guttural")))

# 8.4 GLM as a classification tool

## 8.4.1 Model specification

Let's run a first GLM (Generalised Linear Model). A GLM uses a special family "binomial" as it assumes the outcome has a binomial distribution. In general, results from a Logistic Regression are close to what we get from SDT.

We will use the same dataset that comes from phonetic research. This dataset is from my current work on the phonetic basis of the guttural natural class in Levantine Arabic. Acoustic analyses were conducted on multiple portions of the VCV sequence, and we report here the averaged results on the first half of V2. Acoustic metrics were obtained via VoiceSauce: various acoustic metrics of supralaryngeal (bark difference) and laryngeal (voice quality via amplitude harmonic differences, noise, energy) were obtained. A total of 23 different acoustic metrics were obtained from 10 participants. Here, we use the data from the first two participants for demonstration purposes (one male and one female). The grouping factor of interest is context with two levels: guttural vs non-guttural. Gutturals include uvular, pharyngealised and pharyngeal consonants; non-gutturals include coronal plain, velar and glottal consonants.
The aim of the study was to evaluate whether the combination of the acoustic
metrics provides support for a difference between the two classes of gutturals vs
non-gutturals.

We run a GLM with context as our outcome, and Z2-Z1 as our predictor.
We want to evaluate whether the two classes can be separated when using the
acoustic metric Z2-Z1. Context has two levels, and this will be considered as a
binomial distribution.

```
mdl.glm.Z2mnZ1 <- dfPharV2 %>
  glm(context ~ Z2mnZ1, data = ., family = binomial)
summary(mdl.glm.Z2mnZ1)
```

```
##
## Call:
##   glm(formula = context ~ Z2mnZ1, family = binomial, data = .)
##
## Coefficients:
##              Estimate Std. Error z value Pr(>\|z\|)
## (Intercept)  0.50112    0.23036    2.175 0.029605 *
## Z2mnZ1      -0.12281    0.03621   -3.391 0.000696 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
##       Null deviance: 552.89 on 401 degrees of freedom
## Residual deviance: 541.01 on 400 degrees of freedom
## AIC: 545.01
##
## Number of Fisher Scoring iterations: 4

tidy(mdl.glm.Z2mnZ1) %>
  select(term, estimate) %>
  mutate(estimate = round(estimate, 3))
```

```
## # A tibble: 2 x 2
##   term          estimate
## <chr>         <dbl>
## 1 (Intercept)   0.501
## 2 Z2mnZ1       -0.123

## to only get the coefficients
mycoef2 <- tidy(mdl.glm.Z2mnZ1) %>% pull(estimate)
```
## 8.4.2 Plogis

The result above shows that when moving from the non-guttural (intercept), a unit increase (i.e., guttural) yields a statistically significant decrease in the log odds associated with Z2-Z1. We can evaluate this further from a classification point of view, using plogis.

```
## non-guttural
plogis(mycoef2[1])
```

```
## [1] 0.622722
#guttural
plogis(mycoef2[1] + mycoef2[2])
```

```
## [1] 0.5934644
```

The plogis function provides the probability of being in the guttural class. The intercept (non-guttural) is 0.5, and the guttural class is 0.41. This means that the model predicts that a unit increase in Z2-Z1 yields a decrease of 9% in the probability of being in the guttural class. This is a small effect, but it is statistically significant. The model also provides the log odds associated with the predictor. The log odds are the natural logarithm of the odds ratio, which is the ratio of the probability of being in one class over the other. The log odds are not easy to interpret, but they can be used to evaluate the effect of the predictor on the outcome. The log odds for Z2-Z1 is -0.1, which means that a unit increase in Z2-Z1 yields a decrease of 10% in the odds of being in the guttural class. This is a small effect, but it is statistically significant.

This shows that Z2-Z1 is able to explain the difference in the guttural class with an accuracy of 59%. Let's continue with this model further.

## 8.4.3 Model predictions

As above, we obtain predictions from the model. Because we are using a numeric predictor, we need to assign a threshold for the predict function. The threshold can be thought of as telling the predict function to assign any predictions lower than 50% to one group, and any higher to another.

```
pred.glm.Z2mnZ1 <- predict(mdl.glm.Z2mnZ1, type = "response")>0.5
```

```
tbl.glm.Z2mnZ1 <- table(pred.glm.Z2mnZ1, dfPharV2$context)
rownames(tbl.glm.Z2mnZ1) <- c("Non-Guttural", "Guttural")
tbl.glm.Z2mnZ1
```

```
##
## pred.glm.Z2mnZ1 Non-Guttural Guttural
## Non-Guttural      167          75
## Guttural          55           105
```
## from PresenceAbsence
PresenceAbsence::pcc tbl.glm.Z2mnZ1)

## PCC PCC.sd

## 1 0.6766169 0.0233592

PresenceAbsence::specificity tbl.glm.Z2mnZ1)

## specificity specificity.sd

## 1 0.5833333 0.03684905

PresenceAbsence::sensitivity tbl.glm.Z2mnZ1)

## sensitivity sensitivity.sd

## 1 0.7522523 0.02903959

roc.glm.Z2mnZ1 <- pROC::roc(dfPharV2$context, as.numeric(pred.glm.Z2mnZ1))

## Setting levels: control = Non-Guttural, case = Guttural

## Setting direction: controls < cases

roc.glm.Z2mnZ1

##

## Call:

## roc.default(response = dfPharV2$context, predictor = as.numeric(pred.glm.Z2mnZ1))

##

## Data: as.numeric(pred.glm.Z2mnZ1) in 222 controls (dfPharV2$context Non-Guttural) <

## Area under the curve: 0.6678

pROC::plot.roc(roc.glm.Z2mnZ1, legacy.axes = TRUE)
8.5. ISSUES WITH GLM (AND REGRESSION ANALYSES IN GENERAL)2813

<figure><img src="image_261.png" /></figure>

The model above was able to explain the difference between the two classes
with an accuracy of 67.7%. It has a slightly low specificity (0.583) to detect
gutturals, but a sightly high sensitivity (0.752) to reject the non-gutturals.
Looking at the confusion matrix, we observe that both groups were relatively
accurately identified, but we have relatively large errors (or confusions). The
AUC is at 0.6678 which is not too high.

Let's continue with GLM to evaluate it further. We start by running a correla-
tion test to evaluate issues with GLM.

8.5 Issues with GLM (and regression analyses in general)

8.5.1 Correlation tests

Below, we look at two predictors that are correlated with each other: Z3-Z2 (F3-F2 in Bark) and A2*-A3* (normalised amplitude differences between harmonics closest to F2 and F3). The results of the correlation test shows the two predictors to negatively correlate with each other at a rate of -0.87.

cor.test(dfPharV2$Z3mnZ2, dfPharV2$A2mnA3)

##

## Pearson's product-moment correlation

##

## data: dfPharV2$Z3mnZ2 and dfPharV2$A2mnA3
```r
## t = -35.864, df = 400, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.8947506 -0.8480066
## sample estimates:
## cor
## -0.8733751
```

```
dfPharV2 %>
  ggplot(aes(x = context, y = Z3mnZ2)) +
  geom_boxplot() +
  themeBW()
```

<figure><img src="image_262.png" /></figure>

```
dfPharV2 %>
  ggplot(aes(x = context, y = A2mnA3)) +
  geom_boxplot() +
  themeBW()
```
8.5. ISSUES WITH GLM (AND REGRESSION ANALYSES IN GENERAL)2815

<figure><img src="image_263.png" /></figure>

As we see from the plot, Z3-Z2 is higher in the guttural, whereas A2*-A3* is lower.

8.5.3 GLM on correlated data

8.5.3.1 Model specifications and issues

Let's run a logistic regression as a classification tool to predict the context as a
function of each predictor separately and then combined.

dfPharV2 %>% glm(context ~ Z3mnZ2, data = ., family = binomial) %>% summary()

##

## Call:

## glm(formula = context ~ Z3mnZ2, family = binomial, data = .)

##

## Coefficients:

##              Estimate Std. Error z value Pr(>\|z\|)

## (Intercept) -0.99451  0.23061 -4.313 1.61e-05 ***

## Z3mnZ2      0.17440  0.04553  3.831 0.000128 ***

## ---

## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

##

## (Dispersion parameter for binomial family taken to be 1)

##

## Null deviance: 552.89 on 401 degrees of freedom

## Residual deviance: 537.74 on 400 degrees of freedom
## AIC: 541.74

## Number of Fisher Scoring iterations: 4

dfPharV2 %>% glm(context ~ A2mnA3, data = ., family = binomial) %>% summary()

## Call:

## glm(formula = context ~ A2mnA3, family = binomial, data = .)

## Coefficients:

## Estimate Std. Error z value Pr(>z|)

## (Intercept) -0.98961 0.16632 -5.950 2.68e-09 ***

## A2mnA3 -0.06973 0.01122 -6.215 5.12e-10 ***

## Signif. codes: 0 '**' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

## (Dispersion parameter for binomial family taken to be 1)

## Null deviance: 552.89 on 401 degrees of freedom

## Residual deviance: 508.51 on 400 degrees of freedom

## AIC: 512.51

## Number of Fisher Scoring iterations: 4

dfPharV2 %>% glm(context ~ Z3mnZ2 + A2mnA3, data = ., family = binomial) %>% summary()

## Call:

## glm(formula = context ~ Z3mnZ2 + A2mnA3, family = binomial, data = .)

## Coefficients:

## Estimate Std. Error z value Pr(>z|)

## (Intercept) -0.10996 0.27830 -0.395 0.692754

## Z3mnZ2 -0.39266 0.10201 -3.849 0.000118 ***

## A2mnA3 -0.14930 0.02418 -6.175 6.61e-10 ***

## Signif. codes: 0 '**' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

## (Dispersion parameter for binomial family taken to be 1)

## Null deviance: 552.89 on 401 degrees of freedom

## Residual deviance: 492.50 on 399 degrees of freedom

## AIC: 498.5

## Number of Fisher Scoring iterations: 4
8.5. ISSUES WITH GLM (AND REGRESSION ANALYSES IN GENERAL)2817

```
dfPharV2 %>% glm(context ~ Z3mnZ2 * A2mnA3, data = ., family = binomial) %>% summary()

##
## Call:
## glm(formula = context ~ Z3mnZ2 * A2mnA3, family = binomial, data = .)
##
## Coefficients:
##                 Estimate   Std. Error z value Pr(>\|z\|)
## (Intercept)    0.398028   0.337189    1.180   0.23783
## Z3mnZ2         -0.583131   0.131602   -4.431  9.38e-06 ***
## A2mnA3         -0.091045   0.031870   -2.857  0.00428 **
## Z3mnZ2:A2mnA3  -0.014581   0.005553   -2.626  0.00865 **
## ---
## Signif. codes: 0 '**' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
##         Null deviance: 552.89 on 401 degrees of freedom
##         Residual deviance: 485.41 on 398 degrees of freedom
##         AIC: 493.41
##
## Number of Fisher Scoring iterations: 4
```

When looking at the three models above, it is clear that the log odd value for Z3-Z2 is positive, whereas it is negative for A2*-A3*. When adding the two predictors together, there is clear **suppression**: the coefficients for both predictors are now negative. The relatively high correlation between the predictors affected the coefficients and changed the direction of the slope; collinearity is harmful for any regression analysis. When we use an interaction term, the coefficients are all negative, leading to confusions in interpreting the results.

### 8.5.3.2 Checking collinearity

To check for collinearity, we can use the *vif* function from the *car* package. The *vif* stands for the “Variance Inflation Factor (VIF)”. This is a measure of how much the variance of a regression coefficient is increased due to collinearity. A VIF value below 5 indicates that there is low level of collinearity; between 5 and 10, that there a moderate level of collinearity and above 10 indicates potential collinearity issues.

```
dfPharV2 %>% glm(context ~ Z3mnZ2 + A2mnA3, data = ., family = binomial) %>% vif()
```

#### 8.5.3.2.1 Simple model

```
## Z3mnZ2 A2mnA3
```
### 4.319093 4.319093

The values here are close to 5, which indicates a moderate level of collinearity. This is appropriate, but it is not ideal either.

```r
dfPharV2 %>% glm(context ~ Z3mnZ2 * A2mnA3, data = ., family = binomial) %>%
vif()
```

#### 8.5.3.2.2 Interaction model

### there are higher-order terms (interactions) in this model

### consider setting type = 'predictor'; see ?vif

```r
## Z3mnZ2 A2mnA3 Z3mnZ2:A2mnA3
## 7.151205 7.551354 11.244070
```

When using interaction, the vif values no increase to more than 5 for the individual predictors, and to 11 for the interaction

We use the function `check_collinearity()`

```r
dfPharV2 %>% glm(context ~ Z3mnZ2 * A2mnA3, data = ., family = binomial) %>%
check_collinearity()
```

### Model has interaction terms. VIFs might be inflated.

### Try to center the variables used for the interaction, or check

### multicollinearity among predictors of a model without interaction terms.

### # Check for Multicollinearity

###

### Moderate Correlation

###

Term VIF VIF 95% CI adj. VIF Tolerance Tolerance 95% CI

### Z3mnZ2 7.15 [6.00, 8.57] 2.67 0.14 [0.12, 0.17]

### A2mnA3 7.55 [6.33, 9.06] 2.75 0.13 [0.11, 0.16]

###

### High Correlation

###

Term VIF VIF 95% CI adj. VIF Tolerance Tolerance 95% CI

### Z3mnZ2:A2mnA3 11.24 [9.37, 13.53] 3.35 0.09 [0.07, 0.11]

```r
dfPharV2 %>% glm(context ~ Z3mnZ2 * A2mnA3, data = ., family = binomial) %>%
check_collinearity() %>% plot()
```

### Model has interaction terms. VIFs might be inflated.

### Try to center the variables used for the interaction, or check

### multicollinearity among predictors of a model without interaction terms.
## 8.5. ISSUES WITH GLM (AND REGRESSION ANALYSES IN GENERAL)2819

### Collinearity

High collinearity (VIF) may inflate parameter uncertainty

<figure><img src="image_264.png" /></figure>

### 8.5.3.3 Full dataset

We run the logistic regression on the full dataset to evaluate the levels of collinearity

```
dfPharV2 %> % glm(context ~ ., data = ., family = binomial) %> %
vif()
```

#### 8.5.3.3.1 vif()

<table><thead><tr><th></th><th>CPP</th><th>Energy</th><th>H1A1c</th><th>H1A2c</th><th>H1A3c</th></tr></thead><tbody><tr><td>##</td><td>-1.649494e+00</td><td>-4.103070e-01</td><td>-9.864240e+07</td><td>-1.644946e+08</td><td>3.187778e+06</td></tr><tr><td>##</td><td>H1H2c</td><td>H2H4c</td><td>H2KH5Kc</td><td>H42Kc</td><td>HNR05</td></tr><tr><td>##</td><td>-7.522932e+00</td><td>2.419903e+00</td><td>-4.875852e-01</td><td>1.560665e+00</td><td>1.656399e+00</td></tr><tr><td>##</td><td>HNR15</td><td>HNR25</td><td>HNR35</td><td>SHR</td><td>soe</td></tr><tr><td>##</td><td>1.209439e+01</td><td>7.461060e+01</td><td>8.997714e+01</td><td>2.356345e-01</td><td>5.427072e+00</td></tr><tr><td>##</td><td>Z1mnZ0</td><td>Z2mnZ1</td><td>Z3mnZ2</td><td>Z4mnZ3</td><td>F0Bark</td></tr><tr><td>##</td><td>1.888544e+01</td><td>7.075141e+01</td><td>4.090711e+01</td><td>2.692793e-01</td><td>1.800706e+01</td></tr><tr><td>##</td><td>A1mnA2</td><td>A1mnA3</td><td>A2mnA3</td><td></td><td></td></tr><tr><td>##</td><td>-2.448521e+15</td><td>9.230905e+14</td><td>1.892505e+15</td><td></td><td></td></tr></tbody></table>

```
dfPharV2 %> % glm(context ~ ., data = ., family = binomial) %> %
check_collinearity()
```
### 8.5.3.3.2 check_collinearity()

The variance-covariance matrix is not positive definite. Returning the

nearest positive definite matrix now.

This ensures that eigenvalues are all positive real numbers, and

thereby, for instance, it is possible to calculate standard errors for

all relevant parameters.

Warning in stats::qlogis(r): NaNs produced

### # Check for Multicollinearity

###

### Low Correlation

###

<table><thead><tr><th>Term</th><th>VIF</th><th>VIF 95% CI</th><th>adj.</th><th>VIF</th><th>Tolerance</th><th>Tolerance 95% CI</th></tr></thead><tbody><tr><td>CPP</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>Energy</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>H1A1c</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>H1A2c</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>H1A3c</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>H1H2c</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>H2H4c</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>H2KH5Kc</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>H42Kc</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>HNR05</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>HNR15</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>HNR25</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>HNR35</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>SHR</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>soe</td><td>1.00</td><td></td><td></td><td>1.00</td><td>1.00</td><td></td></tr><tr><td>Z1mnZ0</td><td>1.00</td><td></td><td></td><td>1.00</td><td>1.00</td><td></td></tr><tr><td>Z2mnZ1</td><td>1.00</td><td></td><td></td><td>1.00</td><td>1.00</td><td></td></tr><tr><td>Z3mnZ2</td><td>1.00</td><td>1.00, Inf]</td><td></td><td>1.00</td><td>1.00</td><td>[0.00, 1.00]</td></tr><tr><td>Z4mnZ3</td><td>1.00</td><td></td><td></td><td>1.00</td><td>1.00</td><td></td></tr><tr><td>FOBark</td><td>1.00</td><td></td><td></td><td>1.00</td><td>1.00</td><td></td></tr></tbody></table>

###

### High Correlation

###

<table><thead><tr><th>Term</th><th>VIF</th><th>VIF 95% CI</th><th>adj.</th><th>VIF</th><th>Tolerance</th><th>Tolerance 95% CI</th></tr></thead><tbody><tr><td>A1mnA2</td><td>2.22e+07</td><td>[1.85e+07, 2.67e+07]</td><td>4714.04</td><td>4.50e-08</td><td></td><td>[0.00, 0.00]</td></tr><tr><td>A1mnA3</td><td>2.22e+07</td><td>[1.85e+07, 2.67e+07]</td><td>4714.04</td><td>4.50e-08</td><td></td><td>[0.00, 0.00]</td></tr><tr><td>A2mnA3</td><td>2.22e+07</td><td>[1.85e+07, 2.67e+07]</td><td>4714.05</td><td>4.50e-08</td><td></td><td>[0.00, 0.00]</td></tr></tbody></table>

dfPharV2 %>% glm(context ~ ., data = ., family = binomial) %>% check_collinearity() %>% plot

The variance-covariance matrix is not positive definite. Returning the

nearest positive definite matrix now.
## 8.5. ISSUES WITH GLM (AND REGRESSION ANALYSES IN GENERAL)2821

## This ensures that eigenvalues are all positive real numbers, and

## thereby, for instance, it is possible to calculate standard errors for

## all relevant parameters.

## Warning in stats::qlogis(r): NaNs produced

## Warning: Removed 5 rows containing missing values or values outside the scale range

## (`geom_segment()`).

### Collinearity

High collinearity (VIF) may inflate parameter uncertainty

<figure><img src="image_265.png" /></figure>

### 8.5.4 Conclusion

The more complex your regression model becomes, the higher level of collinearity one can see. This is a known issue in regression analyses, and without applying appropriate approaches, e.g., verifying the collinearity in the data; choosing non-correlated predictors, etc., the models become inflated and the confidence in the results becomes reduced.

There are various solutions to this issue, such as removing collinear predictors, using PCA to obtain orthogonal dimension (i.e., non-correlated dimensions), etc.. Another solution is to use decision trees and Random Forest. Both are very well known to deal with collinearity and to make sense of multivariate predictors.
## 8.6 Decision Trees

Decision trees are a statistical tool that uses the combination of predictors to identify patterns in the data and provides classification accuracy for the model.

The decision tree used is based on conditional inference trees that looks at each predictor and splits the data into multiple nodes (branches) through recursive partitioning in a tree-structured regression model. Each node is also split into leaves (difference between levels of outcome).

Decision trees via ctree does the following:

1. Test global null hypothesis of independence between predictors and outcome.

2. Select the predictor with the strongest association with the outcome measured based on a multiplicity adjusted p-values with Bonferroni correction

3. Implement a binary split in the selected input variable.

4. Recursively repeat steps 1), 2), and 3).

Let's see this in an example using the same dataset. To understand what the decision tree is doing, we will dissect it, by creating one tree with one predictor and move to the next.

### 8.6.1 Individual trees

#### 8.6.1.1 Tree 1

```r
### from the package party
set.seed(42)
```

```r
tree1 <- dfPharV2 %>
```

```r
ctree(
```

context ~ Z2mnZ1,

data = .)

```r
print(tree1)
```

```r
##
```

```r
## Conditional inference tree with 4 terminal nodes
```

```r
##
```

```r
## Response: context
```

```r
## Input: Z2mnZ1
```

```r
## Number of observations: 402
```

```r
##
```

```r
## 1) Z2mnZ1 <= 9.551456; criterion = 0.999, statistic = 11.678
```

```r
## 2) Z2mnZ1 <= 6.779068; criterion = 1, statistic = 12.368
```

```r
## 3) Z2mnZ1 <= 4.004879; criterion = 1, statistic = 56.773
```

```r
## 4)* weights = 157
```

```r
## 3) Z2mnZ1 > 4.004879
```

```r
## 5)* weights = 106
```
## 2) Z2mnZ1 > 6.779068
## 6)* weights = 64
## 1) Z2mnZ1 > 9.551456
## 7)* weights = 75

plot(tree1, main = "Conditional Inference Tree")

<figure><img src="image_266.png" /><figcaption>Conditional Inference Tree</figcaption></figure>

How to interpret this figure? Let's look at mean values and a plot for this variable. This is the difference between F2 and F1 using the bark scale. Because gutturals are produced within the pharynx (regardless of where), the predictions is that a high F1 and a low F2 will be the acoustic correlates related to this constriction location. The closeness between these formants yields a lower Z2-Z1. Hence, the prediction is as follow: the smaller the difference, the more pharyngeal-like constriction these consonants have (all else being equal!). Let's compute the mean/median and plot the difference between the two contexts.

dfPharV2 %>
group_by(context) %>
summarise(mean = mean(Z2mnZ1),
           median = median(Z2mnZ1),
           count = n())

## # A tibble: 2 x 4
## context mean median count
## <fct> <db1> <db1> <int>
## 1 Non-Guttural 6.30 5.02 222
## 2 Guttural 5.31 3.84 180
```
dfPharV2 %>

 ggplot(aes(x = context, y = Z2mnZ1)) +
   geom_boxplot()
```

<figure><img src="image_267.png" /></figure>

The table above reports the mean and median of Z2-Z1 for both levels of context and the plots show the difference between the two. We have a total of 180 cases in the guttural, and 222 in the non-guttural. When considering the conditional inference tree output, various splits were obtained. The first is any value higher than 9.55 being assigned to the non-guttural class (around 98% of 75 cases) Then, with anything lower than 9.55, a second split was obtained. A threshold of 6.78: higher assigned to guttural (around 98% of 64 cases), lower, were split again with a threshold of 4 Bark. A third split was obtained: values lower of equal to 4 Bark are assigned to the guttural (around 70% of 157 cases) and values higher than 4 Barks assigned to the non-guttural (around 90% of 106 cases).

Dissecting the tree like this allows interpretation of the output. In this example, this is quite a complex case and ctree allowed to fine tune the different patterns seen with Now let's look at the full dataset to make sense of the combination of predictors to the difference.
8.6.2 Model 1

```r
set.seed(42)
fit <- dfPharV2 %>%
  ctree(
    context ~ .,
    data = .)
print(fit)
```

```
##
## Conditional inference tree with 8 terminal nodes
##
## Response: context
## Inputs: CPP, Energy, H1A1c, H1A2c, H1A3c, H1H2c, H2H4c, H2KH5Kc, H42Kc, HNR05, HNR15, HNR25,
## Number of observations: 402
##
## 1) A2mnA3 <= -13.78; criterion = 1, statistic = 42.329
## 2) Z4mnZ3 <= 1.592125; criterion = 1, statistic = 40.991
## 3) H2H4c <= -8.396333; criterion = 0.993, statistic = 13.141
## 4) * weights = 8
## 3) H2H4c > -8.396333
## 5) * weights = 100
## 2) Z4mnZ3 > 1.592125
## 6) Energy <= 2.8295; criterion = 0.999, statistic = 16.923
## 7) * weights = 25
## 6) Energy > 2.8295
## 8) * weights = 10
## 1) A2mnA3 > -13.78
## 9) H1H2c <= 10.27167; criterion = 0.953, statistic = 9.458
## 10) SHR <= 0.1566667; criterion = 1, statistic = 18.337
## 11) * weights = 99
## 10) SHR > 0.1566667
## 12) H1H2c <= 0.7411667; criterion = 0.972, statistic = 10.449
## 13) * weights = 103
## 12) H1H2c > 0.7411667
## 14) * weights = 30
## 9) H1H2c > 10.27167
## 15) * weights = 27
plot(fit, main = "Conditional Inference Tree")
```
<figure><img src="image_268.png" /></figure>

How to interpret this complex decision tree?

Let's obtain the median value for each predictor grouped by context. Discuss some of the patterns.

```
dfPharV2 %>
group_by(context) %>
summarize_all(list(mean = mean))
```

### A tibble: 2 x 24

<table><thead><tr><th>context</th><th>CPP_mean</th><th>Energy_mean</th><th>H1A1c_mean</th><th>H1A2c_mean</th><th>H1A3c_mean</th><th>H1H2c_mean</th></tr></thead><tbody><tr><td>&lt;fct&gt;</td><td>&lt;db1&gt;</td><td>&lt;db1&gt;</td><td>&lt;db1&gt;</td><td>&lt;db1&gt;</td><td>&lt;db1&gt;</td><td>&lt;db1&gt;</td></tr><tr><td>1 Non-Guttural</td><td>26.4</td><td>5.28</td><td>16.5</td><td>12.5</td><td>4.62</td><td>3.85</td></tr><tr><td>2 Guttural</td><td>26.3</td><td>7.04</td><td>16.6</td><td>15.6</td><td>1.04</td><td>4.49</td></tr></tbody></table>

We started with `context` as our outcome, and all 23 acoustic measures as predictors. A total of 8 terminal nodes were identified with multiple binary splits in their leaves, allowing separation of the two categories. Looking specifically at the output, we observe a few things.

The first node was based on `A2*-A3*`, detecting a difference between non-gutturals and gutturals. For the first binary split, a threshold of -13.78 Bark was used (mean non guttural = -7.86; mean guttural = -14.58), then for values lower of equal to this threshold, a second split was performed using `Z4-Z3` (mean
non guttural = 1.67; mean guttural = 1.43) with any value smaller and equal to 1.59, then another binary split using H2*-H4*, etc....

Once done, the `ctree` provides multiple binary splits into guttural or non-guttural.

Any possible issues/interesting patterns you can identify? Look at the interactions between predictors.

### 8.6.2.2 Predictions from the full model

Let's obtain some predictions from the model and evaluate how successful it is in dealing with the data.

```r
set.seed(42)
pred.ctree <- predict(fit)
tbl.ctree <- table(pred.ctree, dfPharV2$context)
tbl.ctree
```

```r
##
## pred.ctree      Non-Guttural      Guttural
##   Non-Guttural      194             41
##   Guttural         28             139
```

```
PresenceAbsence::pcc(tbl.ctree)
```

```r
##      PCC      PCC.sd
## 1 0.8283582 0.01882992
```

```
PresenceAbsence::specificity(tbl.ctree)
```

```r
## specificity specificity.sd
## 1 0.7722222 0.03134731
```

```
PresenceAbsence::sensitivity(tbl.ctree)
```

```r
## sensitivity sensitivity.sd
## 1 0.8738739 0.02233216
```

```
roc.ctree <- pROC::roc(dfPharV2$context, as.numeric(pred.ctree))
```

```r
## Setting levels: control = Non-Guttural, case = Guttural
```

```r
## Setting direction: controls < cases
roc.ctree
```

```r
##
## Call:
## roc.default(response = dfPharV2$context, predictor = as.numeric(pred.ctree))
```

```r
##
## Data: as.numeric(pred.ctree) in 222 controls (dfPharV2$context Non-Guttural) < 180 cases (dfPharV2$context Guttural)
```
## Area under the curve: 0.823

pROC::plot.roc(roc.ctree, legacy.axes = TRUE)

<figure><img src="image_269.png" /></figure>

This full model has a classification accuracy of 82.8%. This is not bad!! It has a relatively moderate specificity at 0.772 (at detecting the gutturals) but a high sensitivity at 0.874 (at detecting the non-gutturals). The ROC curve shows the relationship between the two with an AUC of 0.823. This is a good model, but it is not perfect. The confusion matrix shows that the model was able to detect 80% of the gutturals, but 20% were misclassified as non-gutturals. The opposite is true for the non-gutturals: 80% were detected, but 20% were misclassified as gutturals. The AUC is at 0.823, which is not too bad. ### Random selection

One important issue is that the trees we grew above are biased. They are based on the full dataset, which means they are very likely to overfit the data. We did not add any random selection and we only grew one tree each time. If you think about it, is it possible that we obtained such results simply by chance?

What if we add some randomness in the process of creating a conditional inference tree?

We change a small option in `ctree` to allow for random selection of variables, to mimic what Random Forests will do. We use `controls` to specify `mtry = 5`, which is the rounded square root of number of predictors.
8.6.2.3 Model 2

```r
set.seed(42)
fit1 <- dfPharV2 %>
ctree(
  context ~ .,
  data = .,
  controls = ctree_control(mtry = 5))

plot(fit1, main = "Conditional Inference Tree")
```

<figure><img src="image_270.png" /></figure>

```
pred.ctree1 <- predict(fit1)
tbl.ctree1 <- table(pred.ctree1, dfPharV2$context)
tbl.ctree1
```

```
##
## pred.ctree1 Non-Guttural Guttural
## Non-Guttural      205      79
## Guttural          17      101
```

```
PresenceAbsence::pcc tbl.ctree1
```

```
## PCC PCC.sd
## 1 0.761194 0.0212911
```
```
PresenceAbsence::specificity tbl.ctree1
```

```
## specificity specificity.sd
```
## 1 0.561111 0.03709157
PresenceAbsence::sensitivity(tbl.ctree1)

## sensitivity sensitivity.sd
## 1 0.9234234 0.01788761
roc.ctree1 <- pROC::roc(dfPharV2$context, as.numeric(pred.ctree1))

## Setting levels: control = Non-Guttural, case = Guttural
## Setting direction: controls < cases
roc.ctree1

##
## Call:
## roc.default(response = dfPharV2$context, predictor = as.numeric(pred.ctree1))
##
## Data: as.numeric(pred.ctree1) in 222 controls (dfPharV2$context Non-Guttural) < 180
## Area under the curve: 0.7423
pROC::plot.roc(roc.ctree1, legacy.axes = TRUE)

<figure><img src="image_271.png" /></figure>

Can you compare results between you and discuss what is going on?

When adding one random selection process to our `ctree`, we allow it to obtain more robust predictions. We could even go further and grow multiple small trees with a portion of datapoints (e.g., 100 rows, 200 rows). When doing these multiple random selections, you are growing multiple trees that are decorrelated
from each other. These become independent trees and one can combine the
results of these trees to come with clear predictions.

This is how Random Forests work. You would start from a dataset, then grow
multiple trees, vary number of observations used (nrow), and number of predic-
tors used (mtry), adjust branches, and depth of nodes and at the end, combine
the results in a forest. You can also run permutation tests to evaluate contribu-
tions of each predictor to the outcome. This is the beauty of Random Forests.
They do all of these steps automatically at once for you!

8.7 Random Forests

As their name indicate, a Random Forest is a forest of trees implemented through bagging ensemble algorithms. Each tree has multiple branches (nodes), and will provide predictions based on recursive partitioning of the data. Then using the predictions from the multiple grown trees, Random Forests will create *averaged* predictions and come up with prediction accuracy, etc.

There are multiple packages that one can use to grow Random Forests:

1. `randomForest`: The original implementation of Random Forests.

2. `party` and `partykit`: using conditional inference trees as base learners

3. `ranger`: a reimplementation of Random Forests; faster and more flexible than original implementation

The first implementation of Random Forests is widely used in research. One of the issues in this first implementation is that it favoured specific types of predictors (e.g., categorical predictors, predictors with multiple cut-offs, etc.). Random Forests grown via Conditional Inference Trees as implemented in `party` guard against this bias, but they are computationally demanding. Random Forests grown via permutation tests as implemented in `ranger` speed up the computations and can mimic the unbiased selection process.

8.7.1 Party

Random Forests grown via conditional inference trees, are different from the
original implementation. They offer an unbiased selection process that guards
against overfitting of the data. There are various points we need to consider in
growing the forest, including number of trees and predictors to use each time.
Let us run our first Random Forest via conditional inference trees. To make
sure the code runs as fast as it can, we use a very low number of trees: only 100
It is well known that the more trees you grow, the more confidence you have in
the results, as model estimation will be more stable. In this example, I would
easily go with 500 trees..
### 8.7.1.1 Model specification

To grow the forest, we use the function `cforest`. We use all of the dataset for the moment. We need to specify a few options within controls:

1. `ntree = 100 = number of trees to grow. Default = 500.`

2. `mtry = roundovernight(23)`): number of predictors to use each time. Default is 5, but specifying it is advised to account for the structure of the data

By default, `cforest_unbiased` has two additional important options that are used for an unbiased selection process. **WARNING**: you should not change these unless you know what you are doing. Also, by default, the data are split into a training and a testing set. The training is equal to 2/3s of the data; the testing is 1/3.

1. `replace = FALSE = Use subsampling with or without replacement. Default is FALSE, i.e., use subsets of the data without replacing these.`

2. `fraction = 0.632 = Use 63.2% of the data in each split.`

```r
set.seed(42)
mdl.cforest <- dfPharV2 %>
cforest(context ~ ., data = .,
         controls = cforest_unbiased(ntree = 100,
                                     mtry = roundovernight(23)))
```

### 8.7.1.2 Predictions

To obtain predictions from the model, we use the `predict` function and add `OOB = TRUE`. This uses the out-of-bag sample (i.e., 1/3 of the data).

```r
set.seed(42)
pred.cforest <- predict(mdl.cforest, OOB = TRUE)
tbl.cforest <- table(pred.cforest, dfPharV2$context)
tbl.cforest
```

```
##
## pred.cforest      Non-Guttural      Guttural
## Non-Guttural       204               43
## Guttural           18                137
```

```
PresenceAbsence::pcc(tbl.cforest)
```

```
## PCC          PCC.sd
## 1 0.8482587 0.01791612
```

```
PresenceAbsence::specificity(tbl.cforest)
```

```
## specificity specificity.sd
```
## 1 0.761111 0.03187099

PresenceAbsence::sensitivity

## sensitivity sensitivity.sd
## 1 0.9189189 0.01836125

roc.cforest <- pROC::roc(dfPharV2$context, as.numeric(pred.cforest))

## Setting levels: control = Non-Guttural, case = Guttural

## Setting direction: controls < cases
roc.cforest

##
## Call:
## roc.default(response = dfPharV2$context, predictor = as.numeric(pred.cforest))

##
## Data: as.numeric(pred.cforest) in 222 controls (dfPharV2$context Non-Guttural) < 180 cases (df
## Area under the curve: 0.84

pROC::plot.roc(roc.cforest, legacy.axes = TRUE)

<figure><img src="image_272.png" /></figure>

Compared with the 82.8% classification accuracy we obtained using ctree using
our full dataset above (model 1), here we obtain 84.8%; a 2% increase in clas-
sification accuracy. The specificity is slightly lower at 0.761 (at detecting the
gutturals), but the sensitivity is higher at 0.919 (at detecting the non-gutturals).
The ROC curve shows the relationship between the two with an AUC of 0.84.
We could test whether there is statistically significant difference between our `ctree` and `cforest` models. Using the ROC curves, the `roc.test` conducts a non-parametric Z test of significance on the correlated ROC curves. The results show a statistically significant improvement using the `cforest` model. This is normal because we are growing 100 different trees, with random selection of both predictors and samples and provide an averaged prediction.

```r
pROC::roc.test(roc.ctree, roc.cforest)
##
## DeLong's test for two correlated ROC curves
##
## data:  roc.ctree and roc.cforest
## Z = -0.7417, p-value = 0.4583
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
## -0.06180273  0.02786879
## sample estimates:
## AUC of roc1 AUC of roc2
## 0.823048    0.840015
pROC::roc.test(roc.ctree1, roc.cforest)
```

```r
##
## DeLong's test for two correlated ROC curves
##
## data:  roc.ctree1 and roc.cforest
## Z = -4.2372, p-value = 2.264e-05
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
## -0.14296247 -0.05253302
## sample estimates:
## AUC of roc1 AUC of roc2
## 0.7422673  0.8400150
```

### 8.7.1.3 Variable Importance Scores

One important feature in `ctree` was to show which predictor was used first is splitting the data, which was then followed by the other predictors. We use a similar functionality with `cforest` to obtain variable importance scores to pinpoint `strong` and `weak` predictors.

There are two ways to obtain this:

1. Simple permutation tests (conditional = FALSE)

2. Conditional permutation tests (conditional = TRUE)

The former is generally comparable across packages and provides a normal permutation test; the latter runs a permutation test on a grid defined by the correla-
tion matrix and corrects for possible collinearity. This is similar to a regression analysis, but looks at both main effects and interactions.

You could use the normal `varimp` as implemented in `party`. This uses mean decrease in accuracy scores. We will use variable importance scores via an AUC based permutation tests as this uses both accuracy and errors in the model, using `varImpAUC` from the `varImp` package.

**DANGER ZONE:** using conditional permutation test requires a lot of RAMs, unless you have access to a cluster, and/or a lot of RAMs, do not attempt running it. We will run the non-conditional version here for demonstration.

```r
set.seed(42)
VarImp.cforest <- varImp::varImpAUC(mdl.cforest, conditional = FALSE)
lattice::barchart(sort(VarImp.cforest))
```

<figure><img src="image_273.png" /><figcaption>sort(VarImp.cforest)</figcaption></figure>

### 8.7.1.3.1 Non-conditional permutation tests

The Variable Importance Scores via non-conditional permutation tests showed that A2*-A3* (i.e., energy in mid-high frequencies around F2 and F3) is the most important variable at explaining the difference between gutturals and non-gutturals, followed by Z4-Z3 (pharyngeal constriction), H1*-A3* (energy in mid-high frequency component), Z2-Z1 (degree of compactness), Z3-Z2 (spectral divergence), H1*-A2 (energy in mid frequency component) and Z1-Z0 (degree of openness). All other predictors contribute to the contrast but to varying degrees (from H1*-H2* to H1*-A1*). The last 5 predictors are the least important and the CPP has a 0 mean decrease in accuracy and can even be ignored.
**8.7.1.3.2 Conditional permutation tests** On this relatively small dataset, the conditional permutation tests were relatively fast. Be careful with larger datasets.

```R
set.seed(42)
VarImp.cforest <- varImp::varImpAUC(mdl.cforest, conditional = TRUE)
lattice::barchart(sort(VarImp.cforest))
```

<figure><img src="image_274.png" /></figure>

### 8.7.1.4 Conclusion

The party package is powerful at growing Random Forests via conditional Inference trees, but is computationally prohibitive when increasing number of trees and using conditional permutation tests of variable importance scores. We look next at the package ranger due to its speed in computation and flexibility.

## 8.7.2 Ranger

### 8.7.2.1 Declare parallel computing

We start by declaring parallel computing on your devices. This is essential to run these complex computations. The code below is designed to only use 1 core from your machine (and it is not too complex), but if you try to increase the complexity of your computations, you will need parallel computing.

```R
set.seed(42)
```

```R
#Declare parallel computing
```
```
ncores <- availableCores()
cat(paste0("Number of cores available for model calculations set to ", ncores, "."))
```

```r
## Number of cores available for model calculations set to 12.
registerDoFuture()
makeClusterPSOCK(ncores)
```

```r
## Socket cluster with 12 nodes on host 'localhost' (R version 4.5.2 (2025-10-31 ucrt), platform
plan(multisession)
ncores
```

```r
## system
```

```r
##   12
```

```r
## below we register our random number generator. This will mostly be used within the tidymodels
## below to suppress any warnings from doFuture
options(doFuture.rng.onMisuse = "ignore")
```

The `ranger` package proposes a reimplementation of the original Random Forests algorithms, written in C++ and allows for parallel computing. It offers more flexibility in terms of model specification.

### 8.7.2.2 Model specification

In the model below specification below, there are already a few options we are familiar with, with additional ones described below:

1. `num.tree` = Number of trees to grow. We use the default value

2. `mtry` = Number of predictors to use. Default = `floorqtick Variables)`.
   For compatibility with `party`, we use `roundqtick(23)`

3. `replace = FALSE` = Use subsampling with or without replacement. Default `replace = TRUE`, i.e., is with replacement.

4. `sample.fraction = 0.632` = Use 63.2% of the data in each split. Default is full dataset, i.e., `sample.fraction = 1`

5. `importance = "permutation"` = Compute variable importance scores via permutation tests

6. `scale.permutation.importance = FALSE` = whether to scale variable importance scores to be out of 100%. Default is `TRUE`. This is likely to introduce biases in variable importance estimation.

7. `splitrule = "extratrees"` = rule used for splitting trees.

8. `num.threads` = allow for parallel computing. Here we only specify 1 thread, but can use all thread on your computer (or cluster).

We use options 2-7 to make sure we have an unbiased selection process with `ranger`. You can try on your own running the model below by using the defaults to see how the rate of classification increases more, but with the caveat that it has a biased selection process.
```R
set.seed(42)
mdl.ranger2 <- gutt train %>%
  ranger(context = ., data = ., num.trees = 500, mtry = roundqtqt(23)),
  replace = FALSE, sample.fraction = 0.632,
  importance = "permutation", scale.permutation.importance = FALSE,
  splitrule = "extratrees", num.threads = ncores, write.forest = TRUE)
mdl.ranger2

## Ranger result
##
## Call:
##   ranger(context = ., data = ., num.trees = 500, mtry = roundqtqt(23)), replace = FALSE,
##
## Type: Classification
## Number of trees: 500
## Sample size: 268
## Number of independent variables: 23
## Mtry: 5
## Target node size: 1
## Variable importance mode: permutation
## Splitrule: extratrees
## Number of random splits: 1
## OOB prediction error: 10.82 %
```

With the training set, we have an OOB error rate of 10.82%; i.e., an accuracy rate of 89.18%.

### 8.7.2.3.3 Predictions
For the predictions, we use the testing set as a validation set. This is to be considered as a true reflection of the model. This is unseen data not used in the training set.

```R
set.seed(42)
pred.ranger2 <- predict(mdl.ranger2, data = gutt.test)
tbl.ranger2 <- table(pred.ranger2$predictions, gutt.test$context)
tbl.ranger2
```

```R
##
## Non-Guttural Guttural
## Non-Guttural 68 7
## Guttural 5 54
```

```
PresenceAbsence::pcc(tbl.ranger2)
```

```R
## PCC PCC.sd
## 1 0.9104478 0.02475939
```
```
PresenceAbsence::specificity(tbl.ranger2)
```
## specificity specificity.sd

## 1 0.8852459 0.04114721

PresenceAbsence::sensitivity

## sensitivity sensitivity.sd

## 1 0.9315068 0.02976805

roc.ranger <- pROC::roc(gutt.test$context, as.numeric(pred.ranger2$predictions))

## Setting levels: control = Non-Guttural, case = Guttural

## Setting direction: controls < cases

roc.ranger

##

## Call:

## roc.default(response = gutt.test$context, predictor = as.numeric(pred.ranger2$predictions))

##

## Data: as.numeric(pred.ranger2$predictions) in 73 controls (gutt.test$context Non-Guttural)

## Area under the curve: 0.9084

pROC::plot.roc(roc.ranger, legacy.axes = TRUE)

<figure><img src="image_275.png" /></figure>

The classification rate based on the testing set is 91.1%. This is comparable to the one we obtained with cforest. The changes in the settings allow for similarities in the predictions obtained from both party and ranger.
### 8.7.2.3.4 Variable Importance Scores

#### 8.7.2.3.4.1 Default
For the variable importance scores, we obtain them from either the training set or the full model above.

```
set.seed(42)
```

```
lattice::barchart(sort(mdl.ranger2$variable.importance), main = "Variable Importance scores - training set")
```

**Variable Importance scores - training set**

<figure><img src="image_276.png" /></figure>

sort(mdl.ranger2$variable.importance)

```
lattice::barchart(sort(mdl.ranger2$variable.importance), main = "Variable Importance scores - full model")
```
Variable Importance scores – full set

<figure><img src="image_277.png" /></figure>

There are similarities between cforest and ranger, with minor differences. Z2-Z1 is the best predictor at explaining the differences between gutturals and non-gutturals with ranger followed by Z3-Z2 and then A2*-A3*, (reverse with cforest!). The order of the additional predictors is slightly different between the two models. This is expected as the cforest model only used 100 trees, whereas the ranger model used 500 trees.

A clear difference between the packages party and ranger is that the former allows for conditional permutation tests for variable importance scores; this is absent from ranger. However, there is a debate in the literature on whether correlated data are harmful within Random Forests. It is clear that how Random Forests work, i.e., the randomness in the selection process in number of data points, predictors, splitting rules, etc. allow the trees to be decorrelated from each other. Hence, the conditional permutation tests may not be required. But what they offer is to condition variable importance scores on each other (based on correlation tests) to mimic what a multiple regression analysis does (but without suffering from suppression!). Strong predictors will show major contribution, while weak ones will be squashed giving them extremely low (or even negative) scores. Within ranger, it is possible to evaluate this by estimating p values associated with each variable importance. We use the altman method. See documentation for more details.

**DANGER ZONE:** This requires heavy computations. Use with all cores on your machine or in the cluster. Recommendations are to use a minimum of 500 permutations or more, i.e., `num.permutations = 500`; ideally 1000 or more
permutations are needed to get an accurate picture...

```R
set.seed(42)
VarImp.pval <- importance_pvalues(mdl.ranger2, method = "altmann",
                                   num.permutations = 2000,
                                   formula = context ~ ., data = gutt.train,
                                   num.threads = ncores)
VarImp.pvaldf <- VarImp.pval %>
as.data.frame() %>
rownames_to_column(var = "correlate") %>
arrange desc/importance)
VarImp.pvaldf
```

### 8.7.2.3.4.2 With p values

```
## correlate importance pvalue
## 1 Z2mnZ1 0.064323232 0.0004997501
## 2 Z4mnZ3 0.049898990 0.0004997501
## 3 Z3mnZ2 0.043313131 0.0004997501
## 4 A2mnA3 0.038585859 0.0004997501
## 5 Z1mnZ0 0.033777778 0.0004997501
## 6 A1mnA3 0.030747475 0.0004997501
## 7 H1A3c 0.029151515 0.0004997501
## 8 H1A2c 0.021535354 0.0004997501
## 9 H2KH5Kc 0.021232323 0.0009995002
## 10 Energy 0.016929293 0.0009995002
## 11 H1H2c 0.015535354 0.0004997501
## 12 HNR15 0.015232323 0.0004997501
## 13 SHR 0.014525253 0.0019990005
## 14 H1A1c 0.013838384 0.0019990005
## 15 H42Kc 0.013595960 0.0014992504
## 16 HNR35 0.013494949 0.0004997501
## 17 HNR25 0.013212121 0.0014992504
## 18 H2H4c 0.013191919 0.0004997501
## 19 F0Bark 0.012323232 0.0024987506
## 20 A1mnA2 0.011232323 0.0019990005
## 21 soe 0.008888889 0.0084957521
## 22 HNR05 0.008707071 0.0064967516
## 23 CPP 0.005373737 0.0364817591
```

Of course, the output above shows variable p values. The lowest is at 0.0004997501 for all predictors; one at 0.0364817591 for CPP. Recall that CPP received the lowest variable importance score within `ranger` and `cforest`.

In the next part, we look at the `tidymodels` and introduce their philosophy.
### 8.7.3 Random forests with Tidymodels

The `tidymodels` are a bundle of packages used to streamline and simplify the use of machine learning. The `tidymodels` are not restricted to Random Forests, and you can even use them to run simple linear models, logistic regressions, PCA, Random Forests, Deep Learning, etc.

The `tidymodels`' philosophy is to separate data processing on the training and testing sets, and use of a workflow. Below, is an full example of how one can run Random Forests with via `ranger` using the `tidymodels`.

#### 8.7.3.1 Training and testing sets

We start by creating a training and a testing set using the function `initial_split`. Using `strata = context` allows the model to split the data taking into account its structure and splits the data according to proportions of each group.

```r
set.seed(42)
train_test_split <-
  initial_split(
    data = dfPharV2,
    strata = "context",
    prop = 0.667)
train_test_split

## <Training/Testing/Total>
## <268/134/402>
train_tbl <- train_test_split %>% training()
test_tbl <- train_test_split %>% testing()
```

#### 8.7.3.2 Set for cross-validation

We can (if we want to), create a 10-folds cross-validation on the training set. This allows to fine tune the training by obtaining the forest with the highest accuracy. This is a clear difference with `ranger`. While it is not impossible to hard code that, `tidymodels` simplify it for us!!

```r
set.seed(42)
train_cv <- vfold_cv(train_tbl, v = 10, strata = "context")
```

#### 8.7.3.3 Model Specification

Within the model specification, we need to specify multiple options:

1. A *recipe*: This is the recipe and is related to any data processing one wants to apply on the data.
2. An engine: We need to specify the engine to use. Here we want to run a Random Forest.

3. A tuning: Here we can tune our engine

4. A workflow: here we specify the various steps of the workflow

**8.7.3.3.1 Recipe** When defining the recipe, you need to think of the type of “transformations” you will apply to your data.

1. Z-scoring is the first thing that comes to mind. When you z-score the data, you are allowing all strong and weak predictors to be considered equally by the model. This is important as some of our predictors have very large differences related to the levels of context and have different measurement scales. We could have applied it above, but we need to make sure to apply it separately on both training and testing sets (otherwise, our model suffers from data leakage)

2. If you have any missing data, you can use central imputations to fill in missing data (random forests do not like missing data, though they can work with them).

3. You can apply PCA on all your predictors to remove collinearity before running random forests. This is a great option to consider, but adds more complexity to your model. 4. Finally, if you have categorical predictors, you can transform them into dummy variables using `step dummy()`: 1s and 2s for binary; or use one-hot-encoding `step dummy(predicate, one_hot = TRUE)`

See documentations of tidymodels for what you can apply!!

```r
set.seed(42)
recipe <-
  train_tbl %>%
  recipe(context = .) %>%
  step_center(allPredictors(), -all_outcomes()) %>%
  step_scale(allPredictors(), -all_outcomes())

recipePrep <- recipe %>%
  prep()

trainData_baked <- bake recipePrep, new_data = train_tbl) ## convert to the train data to the new
trainData_prep <- recipe %>%
  prep()

trainData_baked <- bake(trainData_prep, new_data = train_tbl) ## convert to the train data to the new
trainData_baked
```

### A tibble: 268 x 24

## CPP Energy H1A1c H1A2c H1A3c H1H2c H2H4c H2KH5Kc H42Kc HNR05
```r
## <db1> <db1> <db1> <db1> <db1> <db1> <db1> <db1> <db1> <db1>
## 1 -1.31 3.75 -0.317 0.248 -1.02 -0.927 -0.237 0.0286 0.0460 -1.63
## 2 -0.269 3.77 -0.699 -0.367 -1.48 -0.855 -0.440 -0.600 0.614 -0.582
## 3 -3.16 0.681 -0.0470 0.598 -0.352 -0.886 0.138 -0.408 0.707 -2.21
## 4 -1.28 2.49 -0.154 0.816 -1.77 -0.609 -0.284 0.491 0.420 -1.35
## 5 -0.124 2.13 -0.437 0.0475 -1.62 -0.728 -0.140 0.435 0.604 -0.773
## 6 -0.833 1.87 -0.0359 0.322 -1.40 -0.518 0.140 -0.119 0.567 -1.61
## 7 1.01 4.37 -0.829 0.124 -1.03 -0.993 -0.00285 0.249 -0.145 -0.788
## 8 0.234 1.80 -0.729 0.266 -0.456 -0.888 -0.600 0.0338 0.779 -0.379
## 9 -1.30 0.693 -0.169 0.560 0.702 -0.868 0.0419 -0.00233 0.759 -1.37
## 10 -1.06 2.63 -0.266 0.147 1.78 -0.682 -0.336 -1.40 1.06 -0.972
## # i 258 more rows
## # i 14 more variables: HNR15 <db1>, HNR25 <db1>, HNR35 <db1>, SHR <db1>,
## #   soe <db1>, Z1mnZ0 <db1>, Z2mnZ1 <db1>, Z3mnZ2 <db1>, Z4mnZ3 <db1>,
## #   F0Bark <db1>, A1mnA2 <db1>, A1mnA3 <db1>, A2mnA3 <db1>, context <fct>
```

Once we have prepared the recipe, we can bake it to see the changes applied to it.

### 8.7.3.3.2 Setting the engine
We set the engine here as a `rand_forest`. We specify a classification mode. Then, we set an engine with engine specific parameters.

```r
set.seed(42)
engine_tidym <- rand_forest(
  mode = "classification",
  engine = "ranger",
  mtry %>% tune(),
  trees %>% tune(),
  min_n = 1
) %>%
  set_engine("ranger", importance = "permutation", sample.fraction = 0.632,
    replace = FALSE, write.forest = T, splitrule = "extratrees",
    scale.permutation.importance = FALSE) # we add engine specific settings
```

### 8.7.3.3.3 Settings for tuning
If we want to tune the model, then uncom-ment the lines below. It is important to use an mtry that hovers around the roundqt(Variables)). If you use all available variables, then your forest is bis-ased as it is able to see all predictors. For number of trees, low numbers are not great, as you can easily underfit the data and not produce meaningful results. Large numbers are fine and Random Forests do not overfit (in theory).

The full dataset has around 2000 observations, and 23 predictors (well even more, but let's ignore it for the moment). I tuned mtry to be between 4 and 6, and trees to be between 1000 and 5000 in a 30 step increment. In total, with a 10-folds cross validation, I grew 30 random forests on each fold for a total of 300 Random Forests on the training set!!! This of course will take a loooooong time
to compute on your computer if using one thread. So use parallel computing or a cluster. When running in the cluster with 20 cores, each with 11GB RAMs, and it took around 260.442 seconds to run with 220GB RAMS! Of course, with smaller RAMs and number of cores, the code will still run but will take longer.

```R
set.seed(42)
gridy_tidym <- grid_random(
  mtry() %>% range_set(c(4, 6)),
  trees() %>% range_set(c(1000, 2000)),
  size = 30
)
```

#### 8.7.3.3.4 Workflow
Now we define the workflow adding the recipe and the model.

```R
set.seed(42)
wkfl_tidym <- workflow() %>%
  add_recipe(recipe) %>%
  add_model(engine_tidym)
```

#### 8.7.3.3.5 Tuning and running model
Here we run the model starting with the workflow, the cross-validation sample, the tuning parameters and asking for specific metrics.

The model below will do the following: 1. Use a 10-folds cross validation on the training test 2. Tune the hyper-parameters to reach the model with the best predictions 3. Within each fold, we grow 30 random forests; we have a total of 300 Random Forests, and we use an ROC-AUC based search for the best performing model

Of course, you could use a larger size to grow more trees, with this will take longer to run!

The model will run for about 2-3 minutes with an 8 cores machine and 32GB of RAMs. For demonstration purposes, the tuning of number of trees is restricted to between 1000 and 2000 trees. This can of course be increased to 5000 trees (or more) depending on the size of the dataset

```R
set.seed(42)
system.time(grid_tidym <-
  tune_grid(wkfl_tidym,
    resamples = train_cv,
    grid = gridy_tidym,
    metrics = metric_set(accuracy, roc_auc, sens, spec, f, precision, recall),
    control = control_grid.save_pred = TRUE, parallel_over = NULL))
)
```

## user system elapsed
## 0.98 0.28 63.32

print(grid_tidym)

## Tuning results

## 10-fold cross-validation using stratification

## A tibble: 10 x 5

## splits id .metrics .notes .predictions
## <list> <chr> <list> <list> <list>
## 1 <split [241/27]> Fold01 <tibble [210 x 6]> <tibble [0 x 4]> <tibble>
## 2 <split [241/27]> Fold02 <tibble [210 x 6]> <tibble [0 x 4]> <tibble>
## 3 <split [241/27]> Fold03 <tibble [210 x 6]> <tibble [0 x 4]> <tibble>
## 4 <split [241/27]> Fold04 <tibble [210 x 6]> <tibble [0 x 4]> <tibble>
## 5 <split [241/27]> Fold05 <tibble [210 x 6]> <tibble [0 x 4]> <tibble>
## 6 <split [241/27]> Fold06 <tibble [210 x 6]> <tibble [0 x 4]> <tibble>
## 7 <split [241/27]> Fold07 <tibble [210 x 6]> <tibble [0 x 4]> <tibble>
## 8 <split [241/27]> Fold08 <tibble [210 x 6]> <tibble [0 x 4]> <tibble>
## 9 <split [242/26]> Fold09 <tibble [210 x 6]> <tibble [0 x 4]> <tibble>
## 10 <split [242/26]> Fold10 <tibble [210 x 6]> <tibble [0 x 4]> <tibble>

### 8.7.3.3.6 Finalise model
We obtain the best performing model from cross-validation, then finalise the workflow by predicting the results on the testing set and obtain the results of the best performing model

set.seed(42)

collect_METRICS(grid_tidym)

## A tibble: 210 x 8

## mtry trees .metric .estimator mean n std_err .config
## <int> <int> <chr> <chr> <dbl> <int> <dbl> <chr>
## 1 4 1002 accuracy binary 0.880 10 0.0244 pre0_mod01_post0
## 2 4 1002 f_meas binary 0.898 10 0.0203 pre0_mod01_post0
## 3 4 1002 precision binary 0.855 10 0.0250 pre0_mod01_post0
## 4 4 1002 recall binary 0.951 10 0.0238 pre0_mod01_post0
## 5 4 1002 roc_auc binary 0.962 10 0.0108 pre0_mod01_post0
## 6 4 1002 sens binary 0.951 10 0.0238 pre0_mod01_post0
## 7 4 1002 spec binary 0.792 10 0.0417 pre0_mod01_post0
## 8 4 1196 accuracy binary 0.880 10 0.0255 pre0_mod02_post0
## 9 4 1196 f_meas binary 0.898 10 0.0202 pre0_mod02_post0
## 10 4 1196 precision binary 0.862 10 0.0285 pre0_mod02_post0
## i 200 more rows

grid_tidym_best <- select_best(grid_tidym, metric = "roc_auc")
grid_tidym_best

## A tibble: 1 x 3

## mtry trees .config

<int> <int> <chr>
## 1 6 1354 pre0_mod26_post0
wkfl_tidym_best <- finalize(wkfl_tidym, grid_tidym_best)
wkfl_tidym_final <- last_fit(wkfl_tidym_best, split = train_test_split)

### 8.7.3.4 Results

For the results, we can obtain various metrics on the training and testing sets.

#### 8.7.3.4.1 Cross-validation on training set

percent/show_best(grid_tidym, metric = "accuracy", n = 1)$mean)

#### 8.7.3.4.1.1 Accuracy

## [1] "89%"

## Cross-validated training performance
show_best(grid_tidym, metric = "roc_auc", n = 1)$mean

#### 8.7.3.4.1.2 ROC-AUC

## [1] 0.9678968

show_best(grid_tidym, metric = "sens", n = 1)$mean

#### 8.7.3.4.1.3 Sensitivity

## [1] 0.9509524

show_best(grid_tidym, metric = "spec", n = 1)$mean

#### 8.7.3.4.1.4 Specificity

## [1] 0.8166667

## Cross-validated training performance
show_best(grid_tidym, metric = "f_meas", n = 1)$mean

#### 8.7.3.4.1.5 F-measure

## [1] 0.9061602
```
## Cross-validated training performance
show_best(grid_tidym, metric = "precision", n = 1)$mean
```

### 8.7.3.4.1.6 Precision

```
## [1] 0.869493
```

```
## Cross-validated training performance
show_best(grid_tidym, metric = "recall", n = 1)$mean
```

### 8.7.3.4.1.7 Recall

```
## [1] 0.9509524
```

## 8.7.3.4.2 Predictions testing set

```
wkfl_tidym_final$.metrics
```

### 8.7.3.4.2.1 Overall

```
## [[1]]
## # A tibble: 3 x 4
##   .metric .estimator .estimate .config
##   <chr>    <chr>        <dbl> <chr>
## 1 accuracy  binary       0.910 pre0_mod0_post0
## 2 roc_auc  binary       0.975 pre0_mod0_post0
## 3 brier_class binary   0.0887 pre0_mod0_post0
```

```
#accuracy
percent(wkfl_tidym_final$.metrics[[1]]$.estimate[[1]]
```

### 8.7.3.4.2.2 Accuracy

```
## [1] "91%"
```

```
#roc-auc
wkfl_tidym_final$.metrics[[1]]$.estimate[[2]]
```

### 8.7.3.4.2.3 ROC-AUC

```
## [1] 0.9754505
```
wkfl_tidym_final$.predictions[[1]] %>
conf Mat(context, .pred_class) %>
pluck(1) %>
as_tibble() %>
group_by(Truth) %> % ## group by Truth to compute percentages
mutate(prop =percent(prop.table(n))) %> % ## calculate percentages row-wise
ggplot(aes(Prediction, Truth, alpha = prop)) +
geom_tile/show.legend = FALSE) +
geom_text(aes label = prop), colour = "white", alpha = 1, size = 8)

<figure><img src="image_278.png" /></figure>

8.7.3.4.3 Confusion Matrix training set

8.7.3.4.4 Variable Importance

vip(pull
    .pull
    . workflow
    . fit
    (wkfl
    . tidym
    . final
    $.
    . workflow
    [[1]])
    )

8.7.3.4.4.1 Best 10

## Warning: `pull` was deprecated in workflows 0.2.3.
## i Please use `extract_fit_parsnip()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
<figure><img src="image_279.png" /></figure>

vip(pull, pull_workflow_fit(wkfl_tidym_final$. workflow[[1]]), num_features = 23)

<figure><img src="image_280.png" /></figure>

8.7.3.4.4.2 All predictors
```R
testData_baked <- bakerecipePrep, new_data = test_tbl) ## convert the test data to the newly in
set.seed(42)
system.time(VarImp.pval <- wkfl_tidym_final %>% extract_fit_engine() %>% importance_pvalues(meth
```

### 8.7.3.4.4.3 P-values computed with permutation importance (PIMP)

```R
## user system elapsed
## 532.15 426.94 147.72
```

```R
VarImp.pvaldf <- VarImp.pval %>
as.data.frame() %>
rownames_to_column(var = "correlate") %>
arrange desc impor tance)
VarImp.pvaldf
```

```R
## correlate importance pvalue
## 1 Z2mnZ1 0.074190949 0.0004997501
## 2 Z4mnZ3 0.048110350 0.0004997501
## 3 Z3mnZ2 0.044619011 0.0004997501
## 4 A2mnA3 0.044447428 0.0004997501
## 5 Z1mnZ0 0.032294884 0.0004997501
## 6 H1A3c 0.024066365 0.0014992504
## 7 H1A2c 0.023872402 0.0004997501
## 8 A1mnA3 0.023424794 0.0014992504
## 9 Energy 0.017352252 0.0029985007
## 10 H2KH5Kc 0.016762902 0.0034982509
## 11 H1H2c 0.015770706 0.0014992504
## 12 H42Kc 0.015076914 0.0049975012
## 13 A1mnA2 0.014897871 0.0039980010
## 14 F0Bark 0.014450263 0.0059970015
## 15 H2H4c 0.013502827 0.0109945027
## 16 H1A1c 0.012935858 0.0064967516
## 17 soe 0.011697477 0.0094952524
## 18 HNR15 0.011190188 0.0064967516
## 19 SHR 0.010541158 0.0164917541
## 20 HNR35 0.009638482 0.0079960020
## 21 HNR25 0.009511660 0.0089955022
## 22 HNR05 0.006162064 0.0389805097
## 23 CPP 0.005035585 0.0819590205
```

### 8.7.3.4.5 Gains curves
This is an interesting features that show how much is gained when looking at various portions of the data. We see a gradual increase in the values. When 50% of the data were tested, around 83% of the results
within the non-guttural class were already identified. The more testing was
performed, the more confidence in the results there are and then when 84.96%
of the data were tested, 100% of the cases were found.

wkfl_tidym_final$.predictions[[1]] %>
gainCurve(context, ` .pred_Non-Guttural `) %>
autoplot()

<figure><img src="image_281.png" /></figure>

wkfl_tidym_final$.predictions[[1]] %>
roc curve(context, ` .pred_Non-Guttural `) %>
autoplot()
<figure><img src="image_282.png" /></figure>

### 8.7.3.4.6 ROC Curves

This is the end of this chapter introducing Random Forests. We have seen how to run them using `party`, `ranger` and `tidymodels`. The latter is a great package that allows to streamline the process of running machine learning models. It is not restricted to Random Forests, and can be used for any type of model!

## 8.8 session info

sessionInfo()

## R version 4.5.2 (2025-10-31 ucrt)
## Platform: x86_64-w64-mingw32/x64
## Running under: Windows 11 x64 (build 26200)
##
## Matrix products: default
## LAPACK version 3.12.1
##
## locale:
## [1] LC_COLLATE=English_United Kingdom.utf8
[2] LC_CTYPE=English_United Kingdom.utf8

[3] LC_MONETARY=English_United Kingdom.utf8

[4] LC_NUMERIC=C

[5] LC_TIME=English_United Kingdom.utf8

time zone: Europe/Paris

tzcode source: internal

attached base packages:

[1] stats4 grid stats graphics grDevices utils datasets

[8] methods base

other attached packages:

[1] performance_0.15.2 vip_0.4.1

[3] varImp_0.4 measures_0.3

[5] pROC_1.19.0.1 yardstick_1.3.2

[7] workflowsets_1.1.1 workflows_1.3.0

[9] tune_2.0.1 tailor_0.1.0

[11] rsample_1.3.1 parsnip_1.3.3

[13] modeldata_1.5.1 infer_1.0.9

[15] dials_1.4.2 scales_1.4.0

[17] tidymodels_1.4.1 doFuture_1.1.2

[19] future_1.68.0 foreach_1.5.2

[21] ranger_0.17.0 party_1.3-18

[23] strucchange_1.5-4 sandwich_3.1-1

[25] modeltools_0.2-24 mvtnorm_1.3-3

[27] zoo_1.8-14 ggrepel_0.9.6

[29] ggpubr_0.6.2 GGally_2.4.0

[31] cowplot_1.2.0 cluster_2.1.8.1

[33] recipes_1.3.1 scatterplot3d_0.3-44

[35] webshot_0.5.5 FactoInvestigate_1.9

[37] factoextra_1.0.7 FactoMineR_2.12

[39] quanteda.textstats_0.97.2 wordcloud_2.6

[41] RColorBrewer_1.1-3 ggraph_2.2.2

[43] textplot_0.2.2 udpipe_0.8.14

[45] quanteda.textplots_0.96.1 stopwords_2.3

[47] SnowballC_0.7.1 tm_0.7-16

[49] NLP_0.3-2 readtext_0.92.1

[51] quanteda_4.3.1 gutenbergr_0.3.0

[53] textdata_0.4.5 proustr_0.4.0

[55] janeaustenr_1.0.0 rvest_1.0.5

[57] tidytext_0.4.3 lattice_0.22-7

[59] paletteer_1.6.0 ggstatsplot_0.13.3

[61] ggstats_0.11.0 itsadug_2.4.1

[63] plotfunctions_1.4 mgcv_1.9-4

[65] nlme_3.1-168 lme4_1.1-37
<table><tr><td>[67]</td><td>Matrix_1.7-4</td><td>faux_1.2.3</td></tr><tr><td>[69]</td><td>car_3.1-3</td><td>carData_3.0-5</td></tr><tr><td>[71]</td><td>parameters_0.28.3</td><td>datawizard_1.3.0</td></tr><tr><td>[73]</td><td>effectsize_1.0.1</td><td>pwr_1.3-0</td></tr><tr><td>[75]</td><td>htmltools_0.5.8.1</td><td>sjPlot_2.9.0</td></tr><tr><td>[77]</td><td>DHARMA_0.4.7</td><td>ordinal_2023.12-4.1</td></tr><tr><td>[79]</td><td>psycho_0.6.1</td><td>PresenceAbsence_1.1.11</td></tr><tr><td>[81]</td><td>ggsignif_0.6.4</td><td>emmeans_2.0.0</td></tr><tr><td>[83]</td><td>corrplot_0.95</td><td>Hmisc_5.2-4</td></tr><tr><td>[85]</td><td>knitr_1.50</td><td>broom_1.0.10</td></tr><tr><td>[87]</td><td>cardx_0.3.0</td><td>gtsummary_2.4.0</td></tr><tr><td>[89]</td><td>ggdist_3.3.3</td><td>summarytools_1.1.4</td></tr><tr><td>[91]</td><td>phonR_1.0-7</td><td>languageR_1.6</td></tr><tr><td>[93]</td><td>lubridate_1.9.4</td><td>forcats_1.0.1</td></tr><tr><td>[95]</td><td>stringr_1.6.0</td><td>dplyr_1.1.4</td></tr><tr><td>[97]</td><td>purrr_1.2.0</td><td>readr_2.1.6</td></tr><tr><td>[99]</td><td>tidyr_1.3.1</td><td>tibble_3.3.0</td></tr><tr><td>[101]</td><td>ggplot2_4.0.1</td><td>tidyverse_2.0.0</td></tr></table>

<table><tr><td colspan="2">loaded via a namespace (and not attached):</td></tr><tr><td>[1]</td><td>igraph_2.2.1</td><td>Formula_1.2-5</td><td>rematch2_2.1.2</td></tr><tr><td>[4]</td><td>tidyselect_1.2.1</td><td>bit_4.6.0</td><td>GPfit_1.0-9</td></tr><tr><td>[7]</td><td>rjson_0.2.23</td><td>broomOT helpers_1.22.0</td><td>parallel_4.5.2</td></tr><tr><td>[10]</td><td>correlation_0.8.8</td><td>tinytex_0.58</td><td>cli_3.6.5</td></tr><tr><td>[13]</td><td>bayestestR_0.17.0</td><td>askpass_1.2.1</td><td>tokenizers_0.3.0</td></tr><tr><td>[16]</td><td>lhs_1.2.0</td><td>broom.mixed_0.2.9.6</td><td>dendextend_1.19.1</td></tr><tr><td>[19]</td><td>curl_7.0.0</td><td>evaluate_1.0.5</td><td>coin_1.4-3</td></tr><tr><td>[22]</td><td>gap_1.6</td><td>stringi_1.8.7</td><td>backports_1.5.0</td></tr><tr><td>[25]</td><td>magrittr_2.0.4</td><td>leaps_3.2</td><td>splines_4.5.2</td></tr><tr><td>[28]</td><td>nanonext_1.7.2</td><td>prodlim_2025.04.28</td><td>DT_0.34.0</td></tr><tr><td>[31]</td><td>nsyllable_1.0.1</td><td>jquerylib_0.1.4</td><td>withr_3.0.2</td></tr><tr><td>[34]</td><td>reformulas_0.4.2</td><td>class_7.3-23</td><td>tidygraph_1.3.1</td></tr><tr><td>[37]</td><td>htmlwidgets_1.6.4</td><td>splancs_2.01-45</td><td>fs_1.6.6</td></tr><tr><td>[40]</td><td>statnet.common_4.12.0</td><td>labeling_0.4.3</td><td>flashClust_1.01-2</td></tr><tr><td>[43]</td><td>see_0.12.0</td><td>network_1.19.0</td><td>gt_1.1.0</td></tr><tr><td>[46]</td><td>timechange_0.3.0</td><td>streamR_0.4.5</td><td>patchwork_1.3.2</td></tr><tr><td>[49]</td><td>data.table_1.17.8</td><td>timeDate_4051.111</td><td>sparsevctrs_0.3.4</td></tr><tr><td>[52]</td><td>commonmark_2.0.0</td><td>yaml_2.3.10</td><td>survival_3.8-3</td></tr><tr><td>[55]</td><td>readMDTable_0.3.2</td><td>crayon_1.5.3</td><td>mirai_2.5.2</td></tr><tr><td>[58]</td><td>tweenr_2.0.3</td><td>codetools_0.2-20</td><td>base64enc_0.1-3</td></tr><tr><td>[61]</td><td>sjlabelled_1.2.0</td><td>labelled_2.16.0</td><td>estimability_1.5.1</td></tr><tr><td>[64]</td><td>foreign_0.8-90</td><td>DiceDesign_1.10</td><td>pkgconfig_2.0.3</td></tr><tr><td>[67]</td><td>xml_1.5.0</td><td>viridisLite_0.4.2</td><td>xtable_1.8-4</td></tr><tr><td>[70]</td><td>litedown_0.8</td><td>plyr_1.8.9</td><td>httr_1.4.7</td></tr><tr><td>[73]</td><td>rbibutils_2.4</td><td>tools_4.5.2</td><td>globals_0.18.0</td></tr><tr><td>[76]</td><td>hardhat_1.4.2</td><td>htmlTable_2.4.3</td><td>checkmate_2.3.3</td></tr></table>
<table>
  <tbody>
    <tr>
      <td>[79]</td>
      <td>selectr_0.5-0</td>
      <td>ggeffects_2.3.1</td>
      <td>digest_0.6.39</td>
    </tr>
    <tr>
      <td>[82]</td>
      <td>qpdf_1.4.1</td>
      <td>numDeriv_2016.8-1.1</td>
      <td>bookdown_0.45</td>
    </tr>
    <tr>
      <td>[85]</td>
      <td>furrr_0.3.1</td>
      <td>farver_2.1.2</td>
      <td>tzdb_0.5.0</td>
    </tr>
    <tr>
      <td>[88]</td>
      <td>reshape2_1.4.5</td>
      <td>rapportools_1.2</td>
      <td>viridis_0.6.5</td>
    </tr>
    <tr>
      <td>[91]</td>
      <td>rpart_4.1.24</td>
      <td>glue_1.8.0</td>
      <td>cachem_1.1.0</td>
    </tr>
    <tr>
      <td>[94]</td>
      <td>polyclip_1.10-7</td>
      <td>generics_0.1.4</td>
      <td>parallelley_1.45.1</td>
    </tr>
    <tr>
      <td>[97]</td>
      <td>minqa_1.2.8</td>
      <td>tcltk_4.5.2</td>
      <td>pdftools_3.6.0</td>
    </tr>
    <tr>
      <td>[100]</td>
      <td>vroom_1.6.6</td>
      <td>utf8_1.2.6</td>
      <td>gower_1.0.2</td>
    </tr>
    <tr>
      <td>[103]</td>
      <td>graphlayouts_1.2.2</td>
      <td>sjmisc_2.8.11</td>
      <td>gridExtra_2.3</td>
    </tr>
    <tr>
      <td>[106]</td>
      <td>lava_1.8.2</td>
      <td>RCurl_1.98-1.17</td>
      <td>memoise_2.0.1</td>
    </tr>
    <tr>
      <td>[109]</td>
      <td>rmdown_2.30</td>
      <td>pander_0.6.6</td>
      <td>rstudioapi_0.17.1</td>
    </tr>
    <tr>
      <td>[112]</td>
      <td>rstantools_2.5.0</td>
      <td>hms_1.1.4</td>
      <td>colorspace_2.1-2</td>
    </tr>
    <tr>
      <td>[115]</td>
      <td>ellipse_0.5.0</td>
      <td>rlang_1.1.6</td>
      <td>quadprog_1.5-8</td>
    </tr>
    <tr>
      <td>[118]</td>
      <td>ipred_0.9-15</td>
      <td>ggforce_0.5.0</td>
      <td>xfun_0.54</td>
    </tr>
    <tr>
      <td>[121]</td>
      <td>multcompView_0.1-10</td>
      <td>coda_0.19-4.1</td>
      <td>sna_2.8</td>
    </tr>
    <tr>
      <td>[124]</td>
      <td>TH.data_1.1-5</td>
      <td>iterations_1.0.14</td>
      <td>matrixStats_1.5.0</td>
    </tr>
    <tr>
      <td>[127]</td>
      <td>abind_1.4-8</td>
      <td>ndjson_0.9.1</td>
      <td>ucminf_1.2.2</td>
    </tr>
    <tr>
      <td>[130]</td>
      <td>libcoin_1.0-10</td>
      <td>ggsci_4.1.0</td>
      <td>bitops_1.0-9</td>
    </tr>
    <tr>
      <td>[133]</td>
      <td>Rdpack_2.6.4</td>
      <td>ps_1.9.1</td>
      <td>compiler_4.5.2</td>
    </tr>
    <tr>
      <td>[136]</td>
      <td>statsExpressions_1.7.1</td>
      <td>boot_1.3-32</td>
      <td>distributional_0.5.0</td>
    </tr>
    <tr>
      <td>[139]</td>
      <td>listenv_0.10.0</td>
      <td>Rcpp_1.1.0</td>
      <td>MASS_7.3-65</td>
    </tr>
    <tr>
      <td>[142]</td>
      <td>gap datasets_0.0.6</td>
      <td>insight_1.4.3</td>
      <td>R6_2.6.1</td>
    </tr>
    <tr>
      <td>[145]</td>
      <td>fastmap_1.2.0</td>
      <td>multcomp_1.4-29</td>
      <td>fastmatch_1.1-6</td>
    </tr>
    <tr>
      <td>[148]</td>
      <td>rstatix_0.7.3</td>
      <td>nnet_7.3-20</td>
      <td>gtable_0.3.6</td>
    </tr>
    <tr>
      <td>[151]</td>
      <td>RcppParallel_5.1.11-1</td>
      <td>bit64_4.6.0-1</td>
      <td>attempt_0.3.1</td>
    </tr>
    <tr>
      <td>[154]</td>
      <td>lifecycle_1.0.4</td>
      <td>S7_0.2.1</td>
      <td>processx_3.8.6</td>
    </tr>
    <tr>
      <td>[157]</td>
      <td>pryr_0.1.6</td>
      <td>nloptr_2.2.1</td>
      <td>callr_3.7.6</td>
    </tr>
    <tr>
      <td>[160]</td>
      <td>sass_0.4.10</td>
      <td>vctrs_0.6.5</td>
      <td>zeallot_0.2.0</td>
    </tr>
    <tr>
      <td>[163]</td>
      <td>slam_0.1-55</td>
      <td>snakecase_0.11.1</td>
      <td>haven_2.5.5</td>
    </tr>
    <tr>
      <td>[166]</td>
      <td>sp_2.2-0</td>
      <td>future apply_1.20.0</td>
      <td>bslib_0.9.0</td>
    </tr>
    <tr>
      <td>[169]</td>
      <td>pillar_1.11.1</td>
      <td>cards_0.7.0</td>
      <td>prismatic_1.1.2</td>
    </tr>
    <tr>
      <td>[172]</td>
      <td>magick_2.9.0</td>
      <td>otel_0.2.0</td>
      <td>jsonlite_2.0.0</td>
    </tr>
    <tr>
      <td>[175]</td>
      <td> markdown_2.0</td>
      <td></td>
      <td></td>
    </tr>
  </tbody>
</table>