Do profiles have incremental validity in predicting grades ?.
Open data
        setwd("~/Dropbox/R Stat")
        load("cluster_rio_som.RData")
        library(ggplot2)
        library(sjPlot)
        library(kohonen) 
## Loading required package: class
## Loading required package: MASS
        library(forcats)
Cluster solutions (ward and self organizing maps som)
table(grp9)
## grp9
##    1    2    3    4    5    6    7    8    9 
## 4187 1503 4168 2144  813 4343 3384 1259 2786
table(cluster_som$unit.classif)
## 
##    1    2    3    4    5    6    7    8    9 
## 2781 3624 1454 2622 2365 2619 2000 4343 2779
table(cluster_som$unit.classif, grp9)
##    grp9
##        1    2    3    4    5    6    7    8    9
##   1    3  712  693    2   14   48  924   89  296
##   2   90    1  429  254   35 2345  161    0  309
##   3    0  361    0    0   29    0   50  881  133
##   4    2  143  231    0   17  153 1553  138  385
##   5  342    1   77 1460   62  354    0    0   69
##   6  204  249  350   89  556  653  410   57   51
##   7    0   16   92   11  100  103   53   94 1531
##   8 1248   20 2172   37    0  621  233    0   12
##   9 2298    0  124  291    0   66    0    0    0
library(gmodels)
CrossTable(cluster_som$unit.classif, grp9, 
           expected = FALSE, prop.r = TRUE, prop.c = FALSE, prop.t = FALSE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  24587 
## 
##  
##                          | grp9 
## cluster_som$unit.classif |         1 |         2 |         3 |         4 |         5 |         6 |         7 |         8 |         9 | Row Total | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##                        1 |         3 |       712 |       693 |         2 |        14 |        48 |       924 |        89 |       296 |      2781 | 
##                          |   467.605 |  1727.988 |   104.129 |   238.521 |    66.089 |   399.921 |   765.341 |    20.027 |     1.160 |           | 
##                          |     0.001 |     0.256 |     0.249 |     0.001 |     0.005 |     0.017 |     0.332 |     0.032 |     0.106 |     0.113 | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##                        2 |        90 |         1 |       429 |       254 |        35 |      2345 |       161 |         0 |       309 |      3624 | 
##                          |   450.268 |   219.539 |    55.916 |    12.170 |    60.055 |  4540.533 |   228.753 |   185.570 |    25.159 |           | 
##                          |     0.025 |     0.000 |     0.118 |     0.070 |     0.010 |     0.647 |     0.044 |     0.000 |     0.085 |     0.147 | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##                        3 |         0 |       361 |         0 |         0 |        29 |         0 |        50 |       881 |       133 |      1454 | 
##                          |   247.606 |   833.094 |   246.483 |   126.790 |     7.571 |   256.832 |   112.612 |  8737.241 |     6.121 |           | 
##                          |     0.000 |     0.248 |     0.000 |     0.000 |     0.020 |     0.000 |     0.034 |     0.606 |     0.091 |     0.059 | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##                        4 |         2 |       143 |       231 |         0 |        17 |       153 |      1553 |       138 |       385 |      2622 | 
##                          |   442.518 |     1.863 |   102.535 |   228.640 |    56.033 |   207.689 |  3938.090 |     0.104 |    26.003 |           | 
##                          |     0.001 |     0.055 |     0.088 |     0.000 |     0.006 |     0.058 |     0.592 |     0.053 |     0.147 |     0.107 | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##                        5 |       342 |         1 |        77 |      1460 |        62 |       354 |         0 |         0 |        69 |      2365 | 
##                          |     9.162 |   142.579 |   261.705 |  7622.297 |     3.357 |     9.728 |   325.504 |   121.102 |   147.749 |           | 
##                          |     0.145 |     0.000 |     0.033 |     0.617 |     0.026 |     0.150 |     0.000 |     0.000 |     0.029 |     0.096 | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##                        6 |       204 |       249 |       350 |        89 |       556 |       653 |       410 |        57 |        51 |      2619 | 
##                          |   131.308 |    49.365 |    19.891 |    85.062 |  2544.279 |    78.351 |     6.808 |    44.335 |   203.528 |           | 
##                          |     0.078 |     0.095 |     0.134 |     0.034 |     0.212 |     0.249 |     0.157 |     0.022 |     0.019 |     0.107 | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##                        7 |         0 |        16 |        92 |        11 |       100 |       103 |        53 |        94 |      1531 |      2000 | 
##                          |   340.586 |    92.354 |   180.005 |   153.095 |    17.344 |   177.306 |   179.472 |     0.691 |  7507.583 |           | 
##                          |     0.000 |     0.008 |     0.046 |     0.005 |     0.050 |     0.051 |     0.026 |     0.047 |     0.765 |     0.081 | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##                        8 |      1248 |        20 |      2172 |        37 |         0 |       621 |       233 |         0 |        12 |      4343 | 
##                          |   349.504 |   226.994 |  2800.008 |   308.327 |   143.607 |    27.839 |   222.566 |   222.387 |   468.406 |           | 
##                          |     0.287 |     0.005 |     0.500 |     0.009 |     0.000 |     0.143 |     0.054 |     0.000 |     0.003 |     0.177 | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##                        9 |      2298 |         0 |       124 |       291 |         0 |        66 |         0 |         0 |         0 |      2779 | 
##                          |  7035.957 |   169.880 |   255.736 |     9.775 |    91.891 |   367.751 |   382.484 |   142.301 |   314.894 |           | 
##                          |     0.827 |     0.000 |     0.045 |     0.105 |     0.000 |     0.024 |     0.000 |     0.000 |     0.000 |     0.113 | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##             Column Total |      4187 |      1503 |      4168 |      2144 |       813 |      4343 |      3384 |      1259 |      2786 |     24587 | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
## 
## 
subs <- round(cluster$height - c(0, cluster$height[-length(cluster$height)]), 3)
plot(cluster$height)

plot(cluster, hang = -1)
rect.hclust(cluster, k=9, border="red")

source("cluster_fig_senna1.R")  
What profiles characterizes each cluster? Results from ward method
cluster_fig(bd = sv1_rio[ , 178:183], grp = grp9, min=-3, max=3, interv = .5, interc = 0)

cluster_fig(bd = sv1_rio[ , 178:183], grp = cluster_som$unit.classif, min=-3, max=3, interv = .5, interc = 0)

What is the incremental validity of clusters in predicting standardized achievement ?
fit <- lm(formula = cog_portug~grade0+age2+sex+correct_grade2+
        F1.Cons.th+F2.Extr.th+F3.Nint.th+F4.Nloc.th+F5.Agre.th+
        F6.Opns.th+ cls_w+cls_w*F1.Cons.th+cls_w*F6.Opns.th, 
        contrasts =  list( cls_w = contr.sum), data=sv1_rio )
    cog_portug
    B CI std. Beta CI p
(Intercept)   6.24 5.74 – 6.74     <.001
grade0   0.43 0.39 – 0.48 0.15 0.13 – 0.16 <.001
age2   -0.02 -0.04 – 0.00 -0.01 -0.03 – 0.00 .094
sex   1.05 0.92 – 1.18 0.11 0.09 – 0.12 <.001
correct_grade2   1.92 1.78 – 2.06 0.19 0.17 – 0.20 <.001
F1.Cons.th   0.23 0.14 – 0.32 0.05 0.03 – 0.07 <.001
F2.Extr.th   -0.47 -0.55 – -0.38 -0.10 -0.11 – -0.08 <.001
F3.Nint.th   0.05 -0.03 – 0.13 0.01 -0.01 – 0.03 .215
F4.Nloc.th   -0.50 -0.58 – -0.42 -0.10 -0.12 – -0.08 <.001
F5.Agre.th   0.08 -0.01 – 0.17 0.02 -0.00 – 0.03 .091
F6.Opns.th   0.74 0.65 – 0.82 0.15 0.13 – 0.17 <.001
cls_w
cls_w1   -0.26 -0.54 – 0.01 -0.03 -0.06 – 0.00 .059
cls_w2   -0.39 -1.00 – 0.23 -0.03 -0.09 – 0.02 .217
cls_w3   -0.07 -0.28 – 0.15 -0.01 -0.03 – 0.02 .541
cls_w4   0.07 -0.27 – 0.41 0.01 -0.03 – 0.04 .702
cls_w5   0.83 0.25 – 1.42 0.06 0.02 – 0.11 .005
cls_w6   -0.13 -0.34 – 0.08 -0.01 -0.04 – 0.01 .209
cls_w7   -0.08 -0.32 – 0.15 -0.01 -0.03 – 0.02 .472
cls_w8   -0.09 -0.58 – 0.39 -0.01 -0.05 – 0.03 .709
F1.Cons.th:cls_w1   -0.03 -0.24 – 0.17 -0.00 -0.02 – 0.02 .767
F1.Cons.th:cls_w2   0.16 -0.15 – 0.48 0.02 -0.02 – 0.05 .303
F1.Cons.th:cls_w3   0.14 -0.08 – 0.36 0.01 -0.01 – 0.03 .207
F1.Cons.th:cls_w4   -0.13 -0.39 – 0.14 -0.01 -0.03 – 0.01 .352
F1.Cons.th:cls_w5   0.38 0.05 – 0.71 0.02 0.00 – 0.05 .022
F1.Cons.th:cls_w6   -0.01 -0.23 – 0.21 -0.00 -0.02 – 0.02 .909
F1.Cons.th:cls_w7   -0.15 -0.40 – 0.10 -0.01 -0.03 – 0.01 .241
F1.Cons.th:cls_w8   -0.26 -0.47 – -0.06 -0.03 -0.05 – -0.01 .012
F6.Opns.th:cls_w1   0.09 -0.09 – 0.27 0.01 -0.01 – 0.03 .305
F6.Opns.th:cls_w2   -0.02 -0.34 – 0.29 -0.00 -0.03 – 0.02 .891
F6.Opns.th:cls_w3   0.26 0.07 – 0.45 0.02 0.01 – 0.04 .008
F6.Opns.th:cls_w4   0.12 -0.12 – 0.37 0.01 -0.01 – 0.03 .325
F6.Opns.th:cls_w5   -0.53 -0.85 – -0.21 -0.05 -0.08 – -0.02 .001
F6.Opns.th:cls_w6   0.08 -0.15 – 0.30 0.01 -0.01 – 0.03 .489
F6.Opns.th:cls_w7   0.04 -0.17 – 0.24 0.00 -0.02 – 0.02 .737
F6.Opns.th:cls_w8   -0.10 -0.36 – 0.16 -0.01 -0.04 – 0.02 .456
Observations   21944
R2 / adj. R2   .145 / .144
fit <- lm(formula = cog_math~grade0+age2+sex+correct_grade2+
        F1.Cons.th+F2.Extr.th+F3.Nint.th+F4.Nloc.th+F5.Agre.th+
        F6.Opns.th+ cls_w + cls_w*F1.Cons.th + cls_w*F6.Opns.th, 
        contrasts =  list( cls_w = contr.sum), data=sv1_rio )
    cog_math
    B CI std. Beta CI p
(Intercept)   14.38 13.93 – 14.82     <.001
grade0   -0.59 -0.63 – -0.55 -0.23 -0.25 – -0.22 <.001
age2   -0.01 -0.02 – 0.01 -0.00 -0.02 – 0.01 .553
sex   -0.31 -0.43 – -0.19 -0.04 -0.05 – -0.02 <.001
correct_grade2   1.26 1.13 – 1.38 0.14 0.13 – 0.16 <.001
F1.Cons.th   0.38 0.29 – 0.46 0.09 0.07 – 0.11 <.001
F2.Extr.th   -0.24 -0.31 – -0.16 -0.06 -0.07 – -0.04 <.001
F3.Nint.th   0.05 -0.02 – 0.12 0.01 -0.01 – 0.03 .178
F4.Nloc.th   -0.11 -0.18 – -0.03 -0.03 -0.04 – -0.01 .004
F5.Agre.th   0.02 -0.06 – 0.10 0.01 -0.01 – 0.02 .561
F6.Opns.th   0.28 0.20 – 0.36 0.07 0.05 – 0.09 <.001
cls_w
cls_w1   -0.01 -0.25 – 0.24 -0.00 -0.03 – 0.03 .948
cls_w2   -0.40 -0.94 – 0.15 -0.04 -0.09 – 0.01 .152
cls_w3   0.07 -0.12 – 0.26 0.01 -0.02 – 0.03 .481
cls_w4   -0.06 -0.36 – 0.24 -0.01 -0.04 – 0.03 .692
cls_w5   0.34 -0.18 – 0.85 0.03 -0.02 – 0.08 .204
cls_w6   -0.06 -0.24 – 0.13 -0.01 -0.03 – 0.02 .554
cls_w7   0.19 -0.02 – 0.39 0.02 -0.00 – 0.05 .070
cls_w8   -0.22 -0.65 – 0.21 -0.02 -0.06 – 0.02 .319
F1.Cons.th:cls_w1   -0.07 -0.26 – 0.11 -0.01 -0.03 – 0.01 .440
F1.Cons.th:cls_w2   0.36 0.08 – 0.63 0.04 0.01 – 0.08 .012
F1.Cons.th:cls_w3   0.12 -0.07 – 0.32 0.01 -0.01 – 0.03 .221
F1.Cons.th:cls_w4   -0.06 -0.30 – 0.18 -0.01 -0.03 – 0.02 .632
F1.Cons.th:cls_w5   0.15 -0.14 – 0.44 0.01 -0.01 – 0.03 .305
F1.Cons.th:cls_w6   -0.34 -0.53 – -0.14 -0.03 -0.05 – -0.01 .001
F1.Cons.th:cls_w7   0.02 -0.21 – 0.24 0.00 -0.02 – 0.02 .889
F1.Cons.th:cls_w8   -0.02 -0.20 – 0.16 -0.00 -0.02 – 0.02 .826
F6.Opns.th:cls_w1   0.05 -0.11 – 0.21 0.01 -0.02 – 0.03 .578
F6.Opns.th:cls_w2   0.23 -0.05 – 0.50 0.02 -0.00 – 0.05 .110
F6.Opns.th:cls_w3   0.12 -0.05 – 0.29 0.01 -0.01 – 0.03 .163
F6.Opns.th:cls_w4   -0.19 -0.41 – 0.03 -0.02 -0.04 – 0.00 .086
F6.Opns.th:cls_w5   -0.07 -0.36 – 0.21 -0.01 -0.04 – 0.02 .606
F6.Opns.th:cls_w6   -0.18 -0.38 – 0.02 -0.02 -0.04 – 0.00 .077
F6.Opns.th:cls_w7   -0.08 -0.27 – 0.10 -0.01 -0.03 – 0.01 .382
F6.Opns.th:cls_w8   0.11 -0.13 – 0.34 0.01 -0.01 – 0.04 .373
Observations   21944
R2 / adj. R2   .090 / .089
fit <- lm(formula = cog_portug~grade0+age2+sex+correct_grade2+
        F1.Cons.th+F2.Extr.th+F3.Nint.th+F4.Nloc.th+F5.Agre.th+
        F6.Opns.th+ cls_som+cls_som*F1.Cons.th+cls_som*F6.Opns.th, 
        contrasts =  list( cls_som = contr.sum), data=sv1_rio )
    cog_portug
    B CI std. Beta CI p
(Intercept)   6.19 5.69 – 6.69     <.001
grade0   0.44 0.39 – 0.48 0.15 0.14 – 0.16 <.001
age2   -0.02 -0.04 – 0.00 -0.01 -0.03 – 0.00 .101
sex   1.04 0.91 – 1.17 0.11 0.09 – 0.12 <.001
correct_grade2   1.92 1.78 – 2.06 0.19 0.17 – 0.20 <.001
F1.Cons.th   0.11 0.02 – 0.20 0.02 0.00 – 0.04 .015
F2.Extr.th   -0.46 -0.55 – -0.37 -0.09 -0.11 – -0.08 <.001
F3.Nint.th   0.15 0.06 – 0.24 0.03 0.01 – 0.05 .001
F4.Nloc.th   -0.38 -0.47 – -0.30 -0.08 -0.10 – -0.06 <.001
F5.Agre.th   -0.02 -0.11 – 0.07 -0.00 -0.02 – 0.01 .709
F6.Opns.th   0.75 0.66 – 0.84 0.15 0.14 – 0.17 <.001
cls_som
cls_som1   0.24 -0.07 – 0.56 0.02 -0.01 – 0.05 .127
cls_som2   -0.09 -0.32 – 0.14 -0.01 -0.03 – 0.01 .444
cls_som3   1.01 0.44 – 1.58 0.09 0.04 – 0.13 .001
cls_som4   0.11 -0.13 – 0.36 0.01 -0.01 – 0.03 .362
cls_som5   -0.50 -0.82 – -0.18 -0.05 -0.08 – -0.02 .002
cls_som6   -0.33 -0.62 – -0.05 -0.03 -0.06 – -0.01 .020
cls_som7   0.44 0.11 – 0.78 0.04 0.01 – 0.07 .010
cls_som8   -0.02 -0.27 – 0.23 -0.00 -0.03 – 0.02 .863
F1.Cons.th:cls_som1   0.12 -0.11 – 0.36 0.01 -0.01 – 0.04 .298
F1.Cons.th:cls_som2   0.10 -0.15 – 0.35 0.01 -0.01 – 0.03 .437
F1.Cons.th:cls_som3   -0.25 -0.46 – -0.04 -0.03 -0.06 – -0.00 .023
F1.Cons.th:cls_som4   -0.09 -0.37 – 0.19 -0.01 -0.03 – 0.02 .531
F1.Cons.th:cls_som5   -0.16 -0.42 – 0.10 -0.02 -0.04 – 0.01 .217
F1.Cons.th:cls_som6   0.15 -0.10 – 0.40 0.01 -0.01 – 0.03 .239
F1.Cons.th:cls_som7   0.12 -0.15 – 0.39 0.01 -0.01 – 0.03 .385
F1.Cons.th:cls_som8   0.04 -0.19 – 0.26 0.00 -0.02 – 0.02 .740
F6.Opns.th:cls_som1   -0.19 -0.44 – 0.06 -0.02 -0.04 – 0.01 .135
F6.Opns.th:cls_som2   0.00 -0.26 – 0.26 0.00 -0.03 – 0.03 .978
F6.Opns.th:cls_som3   -0.21 -0.45 – 0.04 -0.02 -0.05 – 0.00 .094
F6.Opns.th:cls_som4   0.29 0.03 – 0.54 0.03 0.00 – 0.05 .026
F6.Opns.th:cls_som5   0.14 -0.12 – 0.39 0.01 -0.01 – 0.04 .289
F6.Opns.th:cls_som6   0.17 -0.06 – 0.40 0.02 -0.01 – 0.05 .152
F6.Opns.th:cls_som7   -0.26 -0.51 – -0.01 -0.03 -0.06 – -0.00 .041
F6.Opns.th:cls_som8   0.14 -0.08 – 0.37 0.02 -0.01 – 0.05 .215
Observations   21944
R2 / adj. R2   .146 / .144
fit <- lm(formula = cog_math~grade0+age2+sex+correct_grade2+
        F1.Cons.th+F2.Extr.th+F3.Nint.th+F4.Nloc.th+F5.Agre.th+
        F6.Opns.th+ cls_som+cls_som*F1.Cons.th+cls_som*F6.Opns.th, 
        contrasts =  list( cls_som = contr.sum), data=sv1_rio )
    cog_math
    B CI std. Beta CI p
(Intercept)   14.34 13.89 – 14.78     <.001
grade0   -0.59 -0.62 – -0.55 -0.23 -0.25 – -0.22 <.001
age2   -0.01 -0.02 – 0.01 -0.00 -0.02 – 0.01 .557
sex   -0.31 -0.43 – -0.20 -0.04 -0.05 – -0.02 <.001
correct_grade2   1.26 1.13 – 1.38 0.14 0.13 – 0.16 <.001
F1.Cons.th   0.32 0.24 – 0.40 0.08 0.06 – 0.10 <.001
F2.Extr.th   -0.23 -0.31 – -0.15 -0.06 -0.07 – -0.04 <.001
F3.Nint.th   0.09 0.01 – 0.17 0.02 0.00 – 0.04 .029
F4.Nloc.th   -0.06 -0.13 – 0.02 -0.01 -0.03 – 0.00 .123
F5.Agre.th   0.00 -0.08 – 0.08 0.00 -0.02 – 0.02 .986
F6.Opns.th   0.29 0.21 – 0.37 0.07 0.05 – 0.09 <.001
cls_som
cls_som1   0.03 -0.25 – 0.31 0.00 -0.03 – 0.04 .823
cls_som2   0.07 -0.14 – 0.27 0.01 -0.02 – 0.03 .528
cls_som3   0.01 -0.50 – 0.52 0.00 -0.05 – 0.05 .964
cls_som4   0.19 -0.03 – 0.41 0.02 -0.00 – 0.05 .085
cls_som5   -0.20 -0.49 – 0.08 -0.02 -0.05 – 0.01 .159
cls_som6   -0.13 -0.38 – 0.12 -0.01 -0.04 – 0.01 .305
cls_som7   0.28 -0.02 – 0.57 0.03 -0.00 – 0.06 .070
cls_som8   0.14 -0.08 – 0.36 0.02 -0.01 – 0.05 .216
F1.Cons.th:cls_som1   0.33 0.12 – 0.54 0.04 0.02 – 0.07 .002
F1.Cons.th:cls_som2   -0.20 -0.42 – 0.02 -0.02 -0.05 – 0.00 .081
F1.Cons.th:cls_som3   0.10 -0.09 – 0.29 0.01 -0.01 – 0.04 .283
F1.Cons.th:cls_som4   0.05 -0.20 – 0.30 0.00 -0.02 – 0.03 .683
F1.Cons.th:cls_som5   -0.08 -0.31 – 0.15 -0.01 -0.04 – 0.02 .493
F1.Cons.th:cls_som6   0.24 0.02 – 0.46 0.02 0.00 – 0.05 .032
F1.Cons.th:cls_som7   -0.23 -0.47 – 0.02 -0.02 -0.05 – 0.00 .066
F1.Cons.th:cls_som8   -0.14 -0.34 – 0.06 -0.01 -0.04 – 0.01 .176
F6.Opns.th:cls_som1   -0.03 -0.25 – 0.19 -0.00 -0.03 – 0.02 .793
F6.Opns.th:cls_som2   -0.11 -0.34 – 0.12 -0.01 -0.04 – 0.01 .350
F6.Opns.th:cls_som3   0.11 -0.11 – 0.32 0.01 -0.02 – 0.04 .340
F6.Opns.th:cls_som4   0.15 -0.07 – 0.38 0.02 -0.01 – 0.04 .177
F6.Opns.th:cls_som5   -0.04 -0.27 – 0.18 -0.01 -0.03 – 0.02 .701
F6.Opns.th:cls_som6   0.18 -0.03 – 0.39 0.02 -0.00 – 0.05 .085
F6.Opns.th:cls_som7   -0.18 -0.40 – 0.05 -0.02 -0.05 – 0.01 .120
F6.Opns.th:cls_som8   0.04 -0.17 – 0.24 0.01 -0.02 – 0.03 .729
Observations   21944
R2 / adj. R2   .090 / .089