Filtering plotted elements in MJCA by their name

83 Views Asked by At

I am trying to perform a MJCA on the WG93 dataset, and I would like to see how education level varies with having a strong opinion. The issue is that I do not know how to filter unnecessary elements from the mjca object. That is, given the level names vector data_mjca$levelnames, I would like to choose only those elements that contain either "edu", "1" or "5" in them. Specifically in the code below I would like to eliminate any element whose name is [A-D]:[1-4]. How could this be done?

library(ca)
library(ggplot2)
wg <- read.table("~/data_path/WG93_full.txt",
                 header=T, sep="\t")
View(wg)
wg.mjca <- mjca(wg, lambda="indicator", reti=T)
plot(wg.mjca, arrows=c(T,T))
summary(wg.mjca)

Summary:

Columns:
      name   mass  qlt  inr     k=1 cor ctr    k=2 cor ctr  
1  |   A:1 |   20  255   33 |   967 148  63 |  823 107  52 |
2  |   A:2 |   53  109   23 |   426 106  33 |  -71   3   1 |
3  |   A:3 |   33  228   29 |  -180  10   4 | -844 218  94 |
4  |   A:4 |   29  165   30 |  -769 152  60 |  228  13   6 |
5  |   A:5 |    8  238   37 | -1639 157  73 | 1183  82  43 |
6  |   B:1 |   12  362   38 |  1466 191  87 | 1390 172  88 |
7  |   B:2 |   29  129   29 |   635 101  40 | -335  28  13 |
8  |   B:3 |   34  115   27 |   330  34  13 | -515  82  35 |
9  |   B:4 |   46  129   25 |  -454  98  33 | -256  31  12 |
10 |   B:5 |   23  417   36 | -1105 234  97 |  979 184  86 |
11 |   C:1 |   25  484   36 |  1131 270 110 | 1005 213  99 |
12 |   C:2 |   52  125   23 |   293  49  15 | -365  76  27 |
13 |   C:3 |   32  181   29 |  -295  25  10 | -729 156  67 |
14 |   C:4 |   25  181   32 |  -899 174  71 |  181   7   3 |
15 |   C:5 |    9  252   37 | -1309 109  51 | 1504 144  76 |
16 |   D:1 |   10  146   34 |   534  21  10 | 1301 125  65 |
17 |   D:2 |   38   14   26 |   -67   2   1 | -187  13   5 |
18 |   D:3 |   33  162   29 |   -48   1   0 | -731 162  70 |
19 |   D:4 |   37    7   26 |   -98   3   1 | -105   4   2 |
20 |   D:5 |   25  174   30 |   102   2   1 |  906 172  80 |
21 | sex:1 |   70   95   18 |  -268  69  17 | -163  26   7 |
22 | sex:2 |   73   95   18 |   258  69  17 |  157  26   7 |
23 | age:1 |   15   25   33 |  -437  22  10 |  138   2   1 |
24 | age:2 |   34   50   27 |  -330  35  13 |  220  15   7 |
25 | age:3 |   26    4   28 |  -136   4   2 |  -21   0   0 |
26 | age:4 |   24   11   28 |   -56   1   0 | -230  11   5 |
27 | age:5 |   20   16   30 |   217   8   3 | -225   8   4 |
28 | age:6 |   23  121   31 |   787 121  50 |   43   0   0 |
29 | edu:1 |    6    8   34 |   414   8   4 |   83   0   0 |
30 | edu:2 |   62  180   22 |   467 167  47 | -131  13   4 |
31 | edu:3 |   40   30   25 |  -170  11   4 | -221  19   8 |
32 | edu:4 |   15  114   34 |  -750  68  30 |  618  46  23 |
33 | edu:5 |    8   34   32 |  -644  25  12 |  403  10   5 |
34 | edu:6 |   11   51   32 |  -700  43  19 |  315   9   4 |
1

There are 1 best solutions below

0
On BEST ANSWER
library(ca)
wg.mjca <- mjca(wg93, lambda="indicator", reti=T)
my_summary <- summary(wg.mjca)

subset(my_summary$columns,
       grepl('(^edu)|(1$)|(5$)', name))
#>     name mass  qlt  inr   k=1 cor ctr  k=2 cor.1 ctr.1
#> 1    A:1   20  255   33   967 148  63  823   107    52
#> 5    A:5    8  238   37 -1639 157  73 1183    82    43
#> 6    B:1   12  362   38  1466 191  87 1390   172    88
#> 10   B:5   23  417   36 -1105 234  97  979   184    86
#> 11   C:1   25  484   36  1131 270 110 1005   213    99
#> 15   C:5    9  252   37 -1309 109  51 1504   144    76
#> 16   D:1   10  146   34   534  21  10 1301   125    65
#> 20   D:5   25  174   30   102   2   1  906   172    80
#> 21 sex:1   70   95   18  -268  69  17 -163    26     7
#> 23 age:1   15   25   33  -437  22  10  138     2     1
#> 27 age:5   20   16   30   217   8   3 -225     8     4
#> 29 edu:1    6    8   34   414   8   4   83     0     0
#> 30 edu:2   62  180   22   467 167  47 -131    13     4
#> 31 edu:3   40   30   25  -170  11   4 -221    19     8
#> 32 edu:4   15  114   34  -750  68  30  618    46    23
#> 33 edu:5    8   34   32  -644  25  12  403    10     5
#> 34 edu:6   11   51   32  -700  43  19  315     9     4