#weight=country+5th year /avg. pr country+5th year *10
weights_all <- c(33,20,22,15,15,12,8,7,5,16,20,14,10,9,9,8,9,4,53,49,35,12,7,7,8,7,5)
weight_sansletters <- c(37,25,27,18,18,16,10,11,7,17,24,15,11,11,11,9,10,5,56,65,58,19,11,11,11,11,9)

# make weigting variable - with all or with all without letters to editor
  for (i in 1:27) {
    scanpub$weightall[scanpub$country2year5==levels(scanpub$country2year5)[i]] <- weights_all[i]
    scanpub$weight_sansletters[scanpub$country2year5==levels(scanpub$country2year5)[i]] <- weight_sansletters[i]
    }

#scanpub$r09length<-recode(scanpub$n09length,"'<25%'='<25%';'25-50%'='25-50%';'50-75%'='50-99%';'75-100%'='50-99%'; NA=NA; else='>1 page'")
# sans letters
scanpub<-scanpub %>% filter(n10format!="Lettertoeditor") # drop letters

# duplicate rows
#scanpub_expandedsansletters<-expandRows(scanpub,"weight_sansletters") # if "no letters" # why error?
#scanpub<-scanpub_expandedsansletters

# with letters
#scanpub<-scanpub_copy  # all
#scanpub_weightall<-expandRows(scanpub,"weightall") # if "no letters" 
#scanpub<-scanpub_scanpub_weightall

count(scanpub)
## # A tibble: 1 x 1
##       n
##   <int>
## 1  3327
active_themes <- colnames(scanpub[(302:326)])
passive_themes <- active_themes[c(11,13,18,20,25,22,23,25)]
active_themes <- active_themes[-c(11,13,18,20,25,22,23,25)]
active_frames <- colnames(scanpub[551:563])
active_sources1 <- colnames(scanpub[(658:671)])
active_sources2 <- colnames(scanpub[(813:814)])
active_sources <- c(active_sources1,active_sources2)
passive_sources <- active_sources[c(1,2,3,6,7,11,12,13,14)]
active_sources <- active_sources[-c(1,2,3,6,7,11,12,13,14)]
passive_other <-colnames(scanpub[c("COUNTRY2","country2year5","r10genre5","r10genre3", "r02year15", "r02year5","r02year10","v03publication", "n09length", "weight_sansletters", "weightall")])

vars <- c(active_themes, active_frames, active_sources, passive_themes,  passive_sources, passive_other)
vars_facto<-vars[-c(57,59,60)]
vars <- vars[-c(46)]

scanpub<-scanpub[,vars]
data<-scanpub[c(1:38,55:62)]
data$country3 <- paste0(data$COUNTRY2,data$r02year15)
data$pub3 <- paste0(data$v03publication,data$r02year15)
data<-data %>% filter(complete.cases(.))
active<-data[c(1:38)]
passive<-data[c(39:48)]
passsimple <-data[c(39,42,45:47)]
passsimplepubyear <-data[c(48)]

result<-soc.mca(active, passsimple)
result<-invert(result,2)
#result<-invert(result,3)
result
##                         Specific Multiple Correspondence Analysis:                         
##  
##                     Statistics                                   Scree plot               
##  Active dimensions:                            14  |  1.     42.9%   **********************
##  Dimensions explaining 80% of inertia:          3  |  2.     26.3%   *************
##  Active modalities:                            76  |  3.     11.3%   ******
##  Supplementary modalities:                     26  |  4.      8.7%   ****
##  Individuals:                                3316  |  5.      6.1%   ***
##  Share of passive mass:                         0  |  6.      2.1%   *
##  Number of passive modalities:                  0  |  7.      1.3%   
## 
##                    The 38 active variables: [No. modalities - share of variance]                    
## 
##                v12social [2 - 3%]                   v12edu [2 - 3%] 
##                  v12work [2 - 3%]           v12integration [2 - 3%] 
##          v12familycustom [2 - 3%]             v12attitudes [2 - 3%] 
##                v12racism [2 - 3%]              v12religion [2 - 3%] 
##           v12natsecurity [2 - 3%]                 v12crime [2 - 3%] 
##               v12economy [2 - 3%]              v12legalimm [2 - 3%] 
##            v12illegalimm [2 - 3%]          v12civilsociety [2 - 3%] 
##             v12multicult [2 - 3%]               v12culture [2 - 3%] 
##             v12immdebate [2 - 3%]           v12civilrights [2 - 3%] 
##   v20victim_humanitarian [2 - 3%]            v20victim_war [2 - 3%] 
##  v20victim_racismdiscrim [2 - 3%]          v20victim_other [2 - 3%] 
##        v20hero_diversity [2 - 3%]      v20hero_integration [2 - 3%] 
##       v20hero_goodworker [2 - 3%]            v20hero_other [2 - 3%] 
##           v20threat_jobs [2 - 3%]    v20threat_publicorder [2 - 3%] 
##         v20threat_fiscal [2 - 3%] v20threat_socialcohesion [2 - 3%] 
##          v20threat_other [2 - 3%]                r13immigr [2 - 3%] 
##             r13nonimmigr [2 - 3%]                   r13ngo [2 - 3%] 
##                r13expert [2 - 3%]                 r13media [2 - 3%] 
##                   r13pol [2 - 3%]                r13civtot [2 - 3%]
contribution(result)
## 
##       Dimension 1. (+)       
##                                  Ctr    Coord
## v12multicult: 1                  9.7     1.52
## v20hero_integration: 1           9.6     1.72
## v20hero_goodworker: 1            7.1     1.36
## v12edu: 1                        6.1     1.23
## v12attitudes: 1                  5.6     1.42
## v20hero_diversity: 1             5.3     1.99
## v12work: 1                       4.8     0.81
## v12integration: 1                3.9     0.62
## v12culture: 1                    2.9     1.13
## v12immdebate: 1                  2.7     1.08
## v12familycustom: 1               2.4     0.71
## v20threat_socialcohesion: 1      2.4     1.09
## v20victim_racismdiscrim: 1       2.1     0.50
## v12racism: 1                     1.7     0.47
## v12religion: 1                   1.5     0.63
## 
##       Dimension 1. (-)       
##                                  Ctr    Coord
## v12crime: 1                      2.7    -0.50
## r13civtot: 1                     2.0    -0.46
## v12integration: 0                1.6    -0.26
## v20victim_humanitarian: 1        1.6    -0.46
## v12illegalimm: 1                 1.5    -0.77
## v12legalimm: 1                   1.4    -0.31
## v20threat_publicorder: 1         1.3    -0.51
contribution(result, 2)
## 
##       Dimension 2. (+)      
##                                 Ctr    Coord
## v12racism: 1                    9.1     1.01
## v20victim_racismdiscrim: 1      6.4     0.82
## v12crime: 1                     5.1     0.64
## v12legalimm: 0                  4.1     0.41
## v12religion: 1                  3.7     0.92
## v20victim_humanitarian: 0       1.7     0.23
## v12integration: 0               1.4     0.22
## 
##       Dimension 2. (-)      
##                                 Ctr    Coord
## v20victim_humanitarian: 1       6.3    -0.85
## v12legalimm: 1                  5.9    -0.59
## v12social: 1                    5.7    -0.93
## v12economy: 1                   5.0    -1.14
## v20threat_fiscal: 1             3.4    -1.27
## v12work: 1                      3.3    -0.63
## v12integration: 1               3.3    -0.53
## v12civilrights: 1               3.0    -0.69
## v12racism: 0                    2.5    -0.28
## v12crime: 0                     2.3    -0.28
## v20victim_racismdiscrim: 0      2.0    -0.25
## v12edu: 1                       1.9    -0.63
## v20victim_war: 1                1.9    -0.88
## v20hero_goodworker: 1           1.7    -0.61
## r13ngo: 1                       1.5    -0.57
contribution(result, 3)
## 
##       Dimension 3. (+)       
##                                  Ctr    Coord
## v20threat_socialcohesion: 1     10.1     1.83
## v12immdebate: 1                  7.5     1.51
## v20threat_fiscal: 1              6.7     1.59
## r13pol: 1                        5.6     0.69
## v12social: 1                     4.7     0.75
## v12economy: 1                    4.5     0.96
## v20threat_publicorder: 1         4.4     0.77
## v12integration: 1                3.1     0.46
## v12religion: 1                   3.1     0.74
## r13media: 1                      3.1     0.88
## v12familycustom: 1               1.9     0.53
## v12natsecurity: 1                1.6     0.56
## 
##       Dimension 3. (-)       
##                                  Ctr    Coord
## v20hero_goodworker: 1            8.3    -1.22
## r13immigr: 1                     4.8    -0.66
## v12culture: 1                    3.7    -1.05
## v20hero_integration: 1           3.0    -0.79
## v12work: 1                       2.5    -0.48
## v20hero_diversity: 1             2.2    -1.06
## r13pol: 0                        1.6    -0.20
contribution(result, 1:3, mode="variable")
## The contribution of the active variables
##  
##  r13civtot                    Dim.1  Dim.2  Dim.3   Freq
##  r13civtot: 0                   0.7    0.0    0.0   2434
##  r13civtot: 1                   2.0    0.1    0.0    882
##  Total                          2.7    0.1    0.0   3316
##  
##  r13expert                    Dim.1  Dim.2  Dim.3   Freq
##  r13expert: 0                   0.0    0.0    0.1   3126
##  r13expert: 1                   0.1    0.1    1.1    190
##  Total                          0.1    0.1    1.2   3316
##  
##  r13immigr                    Dim.1  Dim.2  Dim.3   Freq
##  r13immigr: 0                   0.1    0.1    1.3   2606
##  r13immigr: 1                   0.4    0.2    4.8    710
##  Total                          0.5    0.3    6.1   3316
##  
##  r13media                     Dim.1  Dim.2  Dim.3   Freq
##  r13media: 0                    0.1    0.1    0.3   3056
##  r13media: 1                    0.9    1.3    3.1    260
##  Total                          1.0    1.4    3.4   3316
##  
##  r13ngo                       Dim.1  Dim.2  Dim.3   Freq
##  r13ngo: 0                      0.0    0.2    0.0   2941
##  r13ngo: 1                      0.0    1.5    0.4    375
##  Total                          0.0    1.7    0.4   3316
##  
##  r13nonimmigr                 Dim.1  Dim.2  Dim.3   Freq
##  r13nonimmigr: 0                0.0    0.1    0.0   3031
##  r13nonimmigr: 1                0.1    0.7    0.5    285
##  Total                          0.1    0.8    0.5   3316
##  
##  r13pol                       Dim.1  Dim.2  Dim.3   Freq
##  r13pol: 0                      0.0    0.3    1.6   2571
##  r13pol: 1                      0.1    1.1    5.6    745
##  Total                          0.1    1.4    7.2   3316
##  
##  v12attitudes                 Dim.1  Dim.2  Dim.3   Freq
##  v12attitudes: 0                0.5    0.0    0.1   3057
##  v12attitudes: 1                5.6    0.6    0.9    259
##  Total                          6.1    0.6    1.0   3316
##  
##  v12civilrights               Dim.1  Dim.2  Dim.3   Freq
##  v12civilrights: 0              0.1    0.6    0.1   2798
##  v12civilrights: 1              0.4    3.0    0.5    518
##  Total                          0.5    3.6    0.6   3316
##  
##  v12civilsociety              Dim.1  Dim.2  Dim.3   Freq
##  v12civilsociety: 0             0.1    0.0    0.0   3142
##  v12civilsociety: 1             0.9    0.4    0.7    174
##  Total                          1.0    0.4    0.7   3316
##  
##  v12crime                     Dim.1  Dim.2  Dim.3   Freq
##  v12crime: 0                    1.2    2.3    0.2   2294
##  v12crime: 1                    2.7    5.1    0.4   1022
##  Total                          3.9    7.4    0.6   3316
##  
##  v12culture                   Dim.1  Dim.2  Dim.3   Freq
##  v12culture: 0                  0.2    0.1    0.3   3101
##  v12culture: 1                  2.9    0.9    3.7    215
##  Total                          3.1    1.0    4.0   3316
##  
##  v12economy                   Dim.1  Dim.2  Dim.3   Freq
##  v12economy: 0                  0.1    0.5    0.5   3002
##  v12economy: 1                  1.3    5.0    4.5    314
##  Total                          1.4    5.5    5.0   3316
##  
##  v12edu                       Dim.1  Dim.2  Dim.3   Freq
##  v12edu: 0                      0.8    0.2    0.0   2934
##  v12edu: 1                      6.1    1.9    0.0    382
##  Total                          6.9    2.1    0.0   3316
##  
##  v12familycustom              Dim.1  Dim.2  Dim.3   Freq
##  v12familycustom: 0             0.4    0.0    0.3   2873
##  v12familycustom: 1             2.4    0.0    1.9    443
##  Total                          2.8    0.0    2.2   3316
##  
##  v12illegalimm                Dim.1  Dim.2  Dim.3   Freq
##  v12illegalimm: 0               0.1    0.1    0.0   3073
##  v12illegalimm: 1               1.5    0.8    0.2    243
##  Total                          1.6    0.9    0.2   3316
##  
##  v12immdebate                 Dim.1  Dim.2  Dim.3   Freq
##  v12immdebate: 0                0.2    0.0    0.5   3103
##  v12immdebate: 1                2.7    0.5    7.5    213
##  Total                          2.9    0.5    8.0   3316
##  
##  v12integration               Dim.1  Dim.2  Dim.3   Freq
##  v12integration: 0              1.6    1.4    1.3   2342
##  v12integration: 1              3.9    3.3    3.1    974
##  Total                          5.5    4.7    4.4   3316
##  
##  v12legalimm                  Dim.1  Dim.2  Dim.3   Freq
##  v12legalimm: 0                 1.0    4.1    0.1   1953
##  v12legalimm: 1                 1.4    5.9    0.1   1363
##  Total                          2.4   10.0    0.2   3316
##  
##  v12multicult                 Dim.1  Dim.2  Dim.3   Freq
##  v12multicult: 0                1.3    0.2    0.0   2921
##  v12multicult: 1                9.7    1.1    0.1    395
##  Total                         11.0    1.3    0.1   3316
##  
##  v12natsecurity               Dim.1  Dim.2  Dim.3   Freq
##  v12natsecurity: 0              0.1    0.1    0.2   2996
##  v12natsecurity: 1              1.3    1.3    1.6    320
##  Total                          1.4    1.4    1.8   3316
##  
##  v12racism                    Dim.1  Dim.2  Dim.3   Freq
##  v12racism: 0                   0.5    2.5    0.1   2590
##  v12racism: 1                   1.7    9.1    0.4    726
##  Total                          2.2   11.6    0.5   3316
##  
##  v12religion                  Dim.1  Dim.2  Dim.3   Freq
##  v12religion: 0                 0.2    0.5    0.4   2956
##  v12religion: 1                 1.5    3.7    3.1    360
##  Total                          1.7    4.2    3.5   3316
##  
##  v12social                    Dim.1  Dim.2  Dim.3   Freq
##  v12social: 0                   0.1    1.1    0.9   2785
##  v12social: 1                   0.7    5.7    4.7    531
##  Total                          0.8    6.8    5.6   3316
##  
##  v12work                      Dim.1  Dim.2  Dim.3   Freq
##  v12work: 0                     1.3    0.9    0.7   2623
##  v12work: 1                     4.8    3.3    2.5    693
##  Total                          6.1    4.2    3.2   3316
##  
##  v20hero_diversity            Dim.1  Dim.2  Dim.3   Freq
##  v20hero_diversity: 0           0.2    0.0    0.1   3190
##  v20hero_diversity: 1           5.3    0.1    2.2    126
##  Total                          5.5    0.1    2.3   3316
##  
##  v20hero_goodworker           Dim.1  Dim.2  Dim.3   Freq
##  v20hero_goodworker: 0          0.9    0.2    1.0   2955
##  v20hero_goodworker: 1          7.1    1.7    8.3    361
##  Total                          8.0    1.9    9.3   3316
##  
##  v20hero_integration          Dim.1  Dim.2  Dim.3   Freq
##  v20hero_integration: 0         1.0    0.1    0.3   3011
##  v20hero_integration: 1         9.6    0.6    3.0    305
##  Total                         10.6    0.7    3.3   3316
##  
##  v20hero_other                Dim.1  Dim.2  Dim.3   Freq
##  v20hero_other: 0                 0      0      0   3236
##  v20hero_other: 1               0.0    0.0    0.8     80
##  Total                          0.0    0.0    0.8   3316
##  
##  v20threat_fiscal             Dim.1  Dim.2  Dim.3   Freq
##  v20threat_fiscal: 0            0.0    0.2    0.4   3144
##  v20threat_fiscal: 1            0.1    3.4    6.7    172
##  Total                          0.1    3.6    7.1   3316
##  
##  v20threat_jobs               Dim.1  Dim.2  Dim.3   Freq
##  v20threat_jobs: 0                0      0      0   3262
##  v20threat_jobs: 1              0.2    1.2    0.1     54
##  Total                          0.2    1.2    0.1   3316
##  
##  v20threat_other              Dim.1  Dim.2  Dim.3   Freq
##  v20threat_other: 0               0      0      0   3144
##  v20threat_other: 1             0.2    0.4    0.3    172
##  Total                          0.2    0.4    0.3   3316
##  
##  v20threat_publicorder        Dim.1  Dim.2  Dim.3   Freq
##  v20threat_publicorder: 0       0.2    0.2    0.8   2831
##  v20threat_publicorder: 1       1.3    1.2    4.4    485
##  Total                          1.5    1.4    5.2   3316
##  
##  v20threat_socialcohesion     Dim.1  Dim.2  Dim.3   Freq
##  v20threat_socialcohesion: 0    0.2    0.0    0.6   3121
##  v20threat_socialcohesion: 1    2.4    0.1   10.1    195
##  Total                          2.6    0.1   10.7   3316
##  
##  v20victim_humanitarian       Dim.1  Dim.2  Dim.3   Freq
##  v20victim_humanitarian: 0      0.4    1.7    0.0   2598
##  v20victim_humanitarian: 1      1.6    6.3    0.0    718
##  Total                            2      8      0   3316
##  
##  v20victim_other              Dim.1  Dim.2  Dim.3   Freq
##  v20victim_other: 0               0      0      0   2782
##  v20victim_other: 1             0.2    0.1    0.2    534
##  Total                          0.2    0.1    0.2   3316
##  
##  v20victim_racismdiscrim      Dim.1  Dim.2  Dim.3   Freq
##  v20victim_racismdiscrim: 0     0.6    2.0    0.1   2541
##  v20victim_racismdiscrim: 1     2.1    6.4    0.3    775
##  Total                          2.7    8.4    0.4   3316
##  
##  v20victim_war                Dim.1  Dim.2  Dim.3   Freq
##  v20victim_war: 0               0.0    0.1    0.0   3113
##  v20victim_war: 1               0.6    1.9    0.3    203
##  Total                          0.6    2.0    0.3   3316
## Average contribution per modality: 1.3
## Total number of individuals: 3316
balance(result)
##       + Contrib. - Contrib. Balance (+/-)
##  [1,]     0.7657     0.2343        3.2682
##  [2,]     0.4442     0.5558        0.7992
##  [3,]     0.6538     0.3462        1.8885
##  [4,]     0.5933     0.4067        1.4591
##  [5,]     0.6679     0.3321        2.0115
##  [6,]     0.5078     0.4922        1.0315
##  [7,]     0.6134     0.3866        1.5865
##  [8,]     0.7733     0.2267        3.4103
##  [9,]     0.5569     0.4431        1.2570
## [10,]     0.5571     0.4429        1.2577
## [11,]     0.4422     0.5578        0.7929
## [12,]     0.5864     0.4136        1.4176
## [13,]     0.5890     0.4110        1.4329
## [14,]     0.5915     0.4085        1.4479
# trim variabelnamn
result$names.sup <-  sapply(strsplit(result$names.sup, ": "), tail, 1) 
# result$names.mod <-  sapply(strsplit(result$names.mod, ": "), tail, 1) # fjernar variabelnamn i kategorinamnet

map.ind(result, dim=c(1,2))

map.ind(result, dim=c(3,2))

map.ctr(result, dim = c(1,2), ctr.dim=c(1), label.size = 3)

map.ctr(result, dim = c(3,2), ctr.dim=c(2), label.size = 3)

map.ctr(result, dim = c(3,2), ctr.dim=c(3), label.size = 3)

map <- map.sup(result, dim = c(1, 2), label.size = 2)
map.path(result,data$r02year10, map, dim=c(1,2))

map <- map.sup(result, dim = c(3, 2), label.size = 2)
map.path(result,data$r02year10, map, dim=c(3,2))

map.active(result, dim=c(1,2), point.size=result$ctr.mod[, 1]) # size acc.to contribution

map.active(result, dim=c(3,2), point.size=result$ctr.mod[, 1]) # size acc.to contribution

 map.active(result, dim=c(1,2), point.size=result$ctr.mod[, 1], label.size=3, point.shape = 21, label.repel = FALSE)

 map.active(result, dim=c(3,2), point.size=result$ctr.mod[, 1], label.size=3, point.shape = 21, label.repel = FALSE)

# map.array(c(nor_ind, nor_ctr))
class    <- which(data$r10genre3 == 'news')
csa.res <- soc.csa(result, class, sup=passsimple)
## Warning in lapply(obj, as.numeric): NAs introduced by coercion
contribution(csa.res,1)
## 
##       Dimension 1. (+)       
##                                  Ctr    Coord
## v20hero_integration: 1          11.9     1.93
## v20hero_goodworker: 1           11.7     1.76
## v12work: 1                       7.6     1.02
## v12edu: 1                        7.1     1.33
## v12multicult: 1                  5.9     1.20
## v20hero_diversity: 1             4.5     1.84
## v12integration: 1                3.7     0.60
## v12culture: 1                    3.4     1.23
## v12attitudes: 1                  3.1     1.08
## v12familycustom: 1               2.6     0.75
## v12crime: 0                      2.3     0.31
## v20threat_socialcohesion: 1      1.7     0.91
## 
##       Dimension 1. (-)       
##                                  Ctr    Coord
## v12crime: 1                      5.2    -0.69
## v20threat_publicorder: 1         2.5    -0.70
## r13civtot: 1                     2.2    -0.49
## v12natsecurity: 1                2.1    -0.79
## v12work: 0                       2.0    -0.27
## v12integration: 0                1.5    -0.25
## v20hero_goodworker: 0            1.4    -0.22
contribution(csa.res,2)
## 
##       Dimension 2. (+)      
##                                 Ctr    Coord
## v20victim_humanitarian: 1      10.9     1.08
## v12legalimm: 1                  8.7     0.70
## v12social: 1                    5.3     0.87
## v12civilrights: 1               4.8     0.84
## v20victim_war: 1                3.6     1.16
## v20threat_fiscal: 1             3.6     1.26
## v12economy: 1                   3.3     0.90
## v12integration: 1               2.8     0.47
## v12crime: 0                     2.3     0.28
## r13ngo: 1                       2.2     0.67
## r13pol: 1                       2.2     0.48
## v12racism: 0                    2.0     0.24
## v20victim_racismdiscrim: 0      1.5     0.22
## 
##       Dimension 2. (-)      
##                                 Ctr    Coord
## v12racism: 1                    7.1    -0.87
## v12legalimm: 0                  6.1    -0.49
## v12crime: 1                     5.1    -0.62
## v20victim_racismdiscrim: 1      5.1    -0.71
## v20victim_humanitarian: 0       3.0    -0.30
## v12culture: 1                   2.7    -0.99
## v12religion: 1                  2.1    -0.67
## v12multicult: 1                 1.5    -0.53
csa.measures(csa.res, correlations = T, cosines = F, cosine.angles = F, dim=1:3)
## 
##                Measures for Class Specific Multiple Correspondence Analysis:                
##  
## 
##  Correlations: 
##  
##              MCA: 1   MCA: 2   MCA: 3
##   CSA: 1       0.97    -0.26    -0.18
##   CSA: 2      -0.18    -0.94     0.20
##   CSA: 3       0.11     0.05     0.89
## 
## 
map.active(csa.res, label.size=3, label.repel = T, map.title = "News 1-2")

map.sup(csa.res, label.size=3, label.repel = T, map.title = "News 1-2")
## Warning: Removed 13 rows containing missing values (geom_point).
## Warning: Removed 13 rows containing missing values (geom_text_repel).

#map.csa.mca.array(csa.res, ndim = 3)

class    <- which(data$r10genre3 == 'column')
csa.res <- soc.csa(result, class,sup=passsimple)
## Warning in lapply(obj, as.numeric): NAs introduced by coercion
contribution(csa.res,1)
## 
##       Dimension 1. (+)       
##                                  Ctr    Coord
## r13media: 1                     25.5     3.45
## v12immdebate: 1                 20.4     3.41
## v12attitudes: 1                  8.9     2.05
## v12multicult: 1                  8.0     1.56
## v12religion: 1                   5.3     1.34
## v20victim_racismdiscrim: 1       3.7     0.76
## v12racism: 1                     3.6     0.78
## v20threat_socialcohesion: 1      2.2     1.17
## v20hero_diversity: 1             1.5     1.21
## 
##       Dimension 1. (-)       
##                                  Ctr    Coord
## r13media: 0                      2.2    -0.29
## v20victim_humanitarian: 1        1.7    -0.53
## v12legalimm: 1                   1.4    -0.35
## v12immdebate: 0                  1.4    -0.23
contribution(csa.res,2)
## 
##       Dimension 2. (+)      
##                                 Ctr    Coord
## r13media: 1                    14.8     2.41
## v12economy: 1                  11.2     1.91
## v12immdebate: 1                11.2     2.32
## v12social: 1                    5.8     1.06
## v20threat_fiscal: 1             4.9     1.70
## v12legalimm: 1                  3.4     0.51
## v12civilrights: 1               2.7     0.73
## v20victim_humanitarian: 1       2.7     0.62
## v12illegalimm: 1                2.5     1.03
## v12racism: 0                    1.5     0.25
## v20threat_jobs: 1               1.5     1.70
## 
##       Dimension 2. (-)      
##                                 Ctr    Coord
## v12multicult: 1                 5.6    -1.20
## v12racism: 1                    5.5    -0.88
## v12religion: 1                  4.0    -1.07
## v20victim_racismdiscrim: 1      2.7    -0.60
## v12legalimm: 0                  2.4    -0.36
## v20hero_diversity: 1            1.7    -1.18
csa.measures(csa.res, correlations = T, cosines = F, cosine.angles = F, dim=1:3)
## 
##                Measures for Class Specific Multiple Correspondence Analysis:                
##  
## 
##  Correlations: 
##  
##              MCA: 1   MCA: 2   MCA: 3
##   CSA: 1       0.61     0.62     0.51
##   CSA: 2      -0.12    -0.64     0.51
##   CSA: 3       0.73    -0.40    -0.05
## 
## 
map.active(csa.res, label.size=3, label.repel = T, map.title = "Column")

map.sup(csa.res, label.size=3, label.repel = T, map.title = "Column")
## Warning: Removed 13 rows containing missing values (geom_point).

## Warning: Removed 13 rows containing missing values (geom_text_repel).

csa.res <-csa.all(result, data$COUNTRY2)
csa.res$measures$NOR$cor
##          MCA: 1   MCA: 2  MCA: 3  MCA: 4   MCA: 5
## CSA: 1 0.959735  0.13168 -0.3693  0.1606 -0.03056
## CSA: 2 0.070666 -0.90583 -0.2881 -0.1944  0.45072
## CSA: 3 0.004845 -0.02601  0.4467  0.2547  0.11054
## CSA: 4 0.023009 -0.25537 -0.2699  0.3057 -0.60228
## CSA: 5 0.003030  0.02647 -0.1134 -0.1201  0.01322
csa.res$measures$SWE$cor
##          MCA: 1   MCA: 2  MCA: 3   MCA: 4  MCA: 5
## CSA: 1  0.91658  0.31900  0.1935 -0.31103  0.1008
## CSA: 2  0.29271 -0.86935 -0.1536  0.30979  0.3097
## CSA: 3  0.00629  0.31118 -0.3245  0.34357  0.3885
## CSA: 4 -0.17295  0.02293  0.7291 -0.01278  0.6589
## CSA: 5  0.13281  0.11404  0.1252  0.70406 -0.2117
csa.res$measures$DEN$cor
##          MCA: 1  MCA: 2  MCA: 3    MCA: 4  MCA: 5
## CSA: 1  0.84204 -0.4374  0.2558  0.008826 -0.3783
## CSA: 2  0.45158  0.6755 -0.1935  0.550585  0.3570
## CSA: 3 -0.19037  0.2350  0.8631  0.387005 -0.1865
## CSA: 4  0.09603  0.2570  0.2364 -0.635763  0.2826
## CSA: 5 -0.05775 -0.3138  0.1821 -0.047566  0.5660
class    <- which(data$COUNTRY2 == 'NOR')
csa.res <- soc.csa(result, class,sup=passsimple)
## Warning in lapply(obj, as.numeric): NAs introduced by coercion
contribution(csa.res,1)
## 
##      Dimension 1. (+)      
##                                Ctr    Coord
## v20hero_diversity: 1          13.9     2.91
## v12multicult: 1                8.8     1.31
## v20hero_integration: 1         7.5     1.37
## v20hero_goodworker: 1          5.8     1.12
## v12edu: 1                      4.4     0.94
## v12integration: 1              4.4     0.59
## v12culture: 1                  3.2     1.07
## v12work: 1                     3.0     0.58
## v12religion: 1                 2.9     0.78
## v12legalimm: 0                 2.5     0.31
## v12familycustom: 1             2.3     0.64
## r13immigr: 1                   2.0     0.47
## r13civtot: 0                   1.7     0.23
## 
##      Dimension 1. (-)      
##                                Ctr    Coord
## v12illegalimm: 1               5.4    -1.30
## r13civtot: 1                   4.7    -0.64
## v12legalimm: 1                 3.5    -0.45
## v12crime: 1                    2.6    -0.44
## v20victim_humanitarian: 1      2.6    -0.53
## v20threat_publicorder: 1       2.4    -0.61
## v12integration: 0              1.8    -0.24
contribution(csa.res,2)
## 
##       Dimension 2. (+)      
##                                 Ctr    Coord
## v20victim_humanitarian: 1      13.5     1.09
## v20victim_war: 1               13.5     2.06
## v12legalimm: 1                  6.3     0.54
## v12crime: 0                     5.0     0.37
## r13ngo: 1                       3.9     0.81
## v12social: 1                    3.3     0.63
## v12work: 1                      3.1     0.53
## v20hero_goodworker: 1           2.2     0.63
## v12civilrights: 1               1.5     0.43
## 
##       Dimension 2. (-)      
##                                 Ctr    Coord
## v12crime: 1                    11.2    -0.83
## v20threat_publicorder: 1        6.1    -0.90
## v12legalimm: 0                  4.4    -0.38
## v20victim_humanitarian: 0       3.7    -0.30
## v12racism: 1                    3.3    -0.54
## v20victim_racismdiscrim: 1      2.8    -0.48
## v12natsecurity: 1               1.9    -0.62
## v12religion: 1                  1.7    -0.54
map.active(csa.res, label.size=3, label.repel = T, map.title = "Norway CSA 1-2")

map.sup(csa.res, label.size=3, label.repel = T, map.title = "Norway CSA 1-2")
## Warning: Removed 19 rows containing missing values (geom_point).
## Warning: Removed 19 rows containing missing values (geom_text_repel).

csa.res <- soc.csa(result, class,sup=passive)
## Warning in lapply(obj, as.numeric): NAs introduced by coercion
## Warning in lapply(obj, as.numeric): NAs introduced by coercion
map.ctr(csa.res, dim = c(1,2), ctr.dim=c(1), label.size = 3, map.title = "Norway CSA ctr axis 1")

map.ctr(csa.res, dim = c(1,2), ctr.dim=c(2), label.size = 3, map.title = "Norway CSA ctr axis 2")

class    <- which(data$COUNTRY2 == 'SWE')
csa.res <- soc.csa(result, class, sup=passsimple)
## Warning in lapply(obj, as.numeric): NAs introduced by coercion
contribution(csa.res,1)
## 
##       Dimension 1. (+)      
##                                 Ctr    Coord
## v12attitudes: 1                17.5     2.78
## v12multicult: 1                12.5     1.90
## v20victim_racismdiscrim: 1      8.2     1.10
## v12racism: 1                    7.9     1.12
## r13media: 1                     4.3     1.38
## v12immdebate: 1                 3.5     1.38
## v12culture: 1                   3.1     1.29
## v20hero_goodworker: 1           3.1     0.99
## v20hero_integration: 1          3.0     1.06
## v12work: 1                      2.0     0.58
## v12edu: 1                       1.6     0.68
## v20hero_diversity: 1            1.5     1.18
## 
##       Dimension 1. (-)      
##                                 Ctr    Coord
## v20victim_other: 1              3.6    -0.88
## v20victim_racismdiscrim: 0      2.5    -0.34
## v12racism: 0                    2.2    -0.31
## v12multicult: 0                 1.7    -0.26
## v12attitudes: 0                 1.5    -0.24
## v20victim_humanitarian: 1       1.5    -0.48
## r13civtot: 1                    1.5    -0.45
contribution(csa.res,2)
## 
##       Dimension 2. (+)      
##                                 Ctr    Coord
## v12civilsociety: 1              5.4     1.75
## v20victim_humanitarian: 1       4.9     0.83
## v20hero_goodworker: 1           4.8     1.15
## v12work: 1                      4.5     0.81
## v12legalimm: 1                  4.5     0.57
## v12integration: 1               4.2     0.66
## v20hero_integration: 1          3.8     1.11
## v12edu: 1                       3.7     0.99
## v20hero_other: 1                3.4     2.06
## v12economy: 1                   3.0     0.97
## v12civilrights: 1               3.0     0.76
## r13immigr: 1                    2.9     0.64
## v12racism: 0                    2.7     0.32
## v20victim_racismdiscrim: 0      1.9     0.28
## v12social: 1                    1.8     0.59
## v20victim_war: 1                1.8     0.94
## v12crime: 0                     1.6     0.27
## 
##       Dimension 2. (-)      
##                                 Ctr    Coord
## v12racism: 1                    9.6    -1.15
## v20victim_racismdiscrim: 1      6.4    -0.91
## v12crime: 1                     3.6    -0.60
## v12legalimm: 0                  3.1    -0.40
## v20threat_other: 1              2.6    -1.23
## v12integration: 0               1.8    -0.27
## v20victim_humanitarian: 0       1.4    -0.23
map.active(csa.res, label.size=3, label.repel = T, map.title = "Sweden CSA 1-2")

map.ctr(csa.res, dim = c(1,2), ctr.dim=c(1), label.size = 3, map.title = "Sweden CSA ctr axis 1")

map.ctr(csa.res, dim = c(1,2), ctr.dim=c(2), label.size = 3, map.title = "Sweden CSA ctr axis 2")

map.sup(csa.res, dim = c(1,2), label.size = 3, map.title = "Sweden CSA")
## Warning: Removed 19 rows containing missing values (geom_point).
## Warning: Removed 19 rows containing missing values (geom_text_repel).

class    <- which(data$COUNTRY2 == 'DEN')
csa.res <- soc.csa(result, class,sup=passsimple)
## Warning in lapply(obj, as.numeric): NAs introduced by coercion
contribution(csa.res,1)
## 
##       Dimension 1. (+)       
##                                  Ctr    Coord
## v20threat_fiscal: 1             11.5     2.81
## v12edu: 1                        8.3     1.61
## v20hero_integration: 1           7.1     1.66
## v20threat_socialcohesion: 1      6.7     2.01
## v12social: 1                     6.0     1.16
## v12economy: 1                    5.5     1.44
## v12integration: 1                5.2     0.79
## v12work: 1                       3.8     0.81
## v20hero_goodworker: 1            3.2     1.02
## v12immdebate: 1                  2.4     1.15
## v20hero_diversity: 1             2.4     1.49
## v12crime: 0                      1.8     0.31
## v12familycustom: 1               1.7     0.67
## v12multicult: 1                  1.6     0.69
## r13pol: 1                        1.4     0.48
## 
##       Dimension 1. (-)       
##                                  Ctr    Coord
## v20threat_publicorder: 1         4.6    -1.06
## v12crime: 1                      4.1    -0.69
## v12natsecurity: 1                2.5    -0.97
## v12integration: 0                2.1    -0.33
## v20victim_humanitarian: 1        1.4    -0.47
contribution(csa.res,2)
## 
##       Dimension 2. (+)       
##                                  Ctr    Coord
## v12religion: 1                   9.1     1.70
## v20hero_integration: 1           6.2     1.52
## v20threat_socialcohesion: 1      6.2     1.91
## v20hero_diversity: 1             4.4     2.01
## v12familycustom: 1               3.3     0.93
## v12immdebate: 1                  3.2     1.32
## v12multicult: 1                  2.7     0.89
## v12culture: 1                    2.0     1.04
## v12legalimm: 0                   1.9     0.33
## v12edu: 1                        1.5     0.67
## v20threat_fiscal: 0              1.4     0.23
## 
##       Dimension 2. (-)       
##                                  Ctr    Coord
## v20threat_fiscal: 1             25.3    -4.12
## v12economy: 1                    6.4    -1.54
## v12social: 1                     2.9    -0.79
## v12legalimm: 1                   2.7    -0.47
## v20victim_humanitarian: 1        2.2    -0.60
contribution(csa.res,3)
## 
##       Dimension 3. (+)       
##                                  Ctr    Coord
## v20threat_socialcohesion: 1     19.8     3.14
## v20threat_publicorder: 1        16.1     1.79
## v20threat_fiscal: 1              6.4     1.90
## v12religion: 1                   3.7     1.00
## v12crime: 1                      2.9     0.52
## v12familycustom: 1               2.5     0.73
## v12immdebate: 1                  2.2     1.01
## v12natsecurity: 1                1.7     0.71
## 
##       Dimension 3. (-)       
##                                  Ctr    Coord
## v20hero_goodworker: 1            7.4    -1.41
## v20hero_integration: 1           5.1    -1.27
## v12work: 1                       3.4    -0.69
## v20hero_diversity: 1             3.0    -1.52
## v20threat_publicorder: 0         2.8    -0.31
## r13immigr: 1                     2.7    -0.61
## v20victim_humanitarian: 1        1.4    -0.44
map.active(csa.res, label.size=3, label.repel = T, map.title = "Denmark CSA 1-2")

map.active(csa.res, label.size=3, label.repel = T, dim=c(3,2), map.title = "Denmark CSA 3-2")

map.ctr(csa.res, dim = c(1,2), ctr.dim=c(1), label.size = 3, map.title = "Denmark CSA ctr axis 1")

map.ctr(csa.res, dim = c(1,2), ctr.dim=c(2), label.size = 3, map.title = "Denmark CSA ctr axis 2")

map.ctr(csa.res, dim = c(3,2), ctr.dim=c(3), label.size = 3, map.title = "Denmark CSA ctr axis 3")

map.sup(csa.res, dim = c(1,2), label.size = 3, map.title = "Denmark CSA 1-2")
## Warning: Removed 18 rows containing missing values (geom_point).
## Warning: Removed 18 rows containing missing values (geom_text_repel).

map.sup(csa.res, dim = c(3,2), label.size = 3, map.title = "Denmark CSA 3-2")
## Warning: Removed 18 rows containing missing values (geom_point).

## Warning: Removed 18 rows containing missing values (geom_text_repel).

csa.res <-csa.all(result, data$r02year15)
csa.res$measures$`70-84`$cor
##          MCA: 1  MCA: 2   MCA: 3      MCA: 4  MCA: 5
## CSA: 1  0.92549 -0.3472 -0.20127 -0.23405841 -0.1699
## CSA: 2  0.24474  0.1605 -0.56923  0.22021743  0.5597
## CSA: 3 -0.10608 -0.6904  0.08565 -0.10832927  0.5319
## CSA: 4  0.21479  0.3650  0.53898 -0.17783185  0.2768
## CSA: 5  0.02248  0.3997 -0.13591 -0.00003358 -0.1018
csa.res$measures$`85-99`$cor
##          MCA: 1   MCA: 2  MCA: 3   MCA: 4   MCA: 5
## CSA: 1  0.96421  0.25320  0.0605  0.05317 -0.13073
## CSA: 2  0.19282 -0.90533  0.4407  0.06739  0.02642
## CSA: 3  0.12373 -0.13377 -0.4548  0.12147  0.85957
## CSA: 4 -0.03494  0.23337  0.6785 -0.43906  0.43491
## CSA: 5 -0.08860  0.06814  0.2912  0.82424  0.08796
csa.res$measures$`00-`$cor
##          MCA: 1   MCA: 2  MCA: 3   MCA: 4   MCA: 5
## CSA: 1  0.89254  0.38874  0.1893  0.10411  0.16093
## CSA: 2  0.42526 -0.87273 -0.2205 -0.06242 -0.12350
## CSA: 3 -0.08683 -0.22391  0.5847  0.77130  0.04814
## CSA: 4 -0.01280 -0.13633  0.7122 -0.60788  0.17457
## CSA: 5 -0.03099 -0.03824 -0.1096  0.07765  0.78366
class    <- which(data$r02year15 == '70-84')
csa.res <- soc.csa(result, class,sup=passsimple)
## Warning in lapply(obj, as.numeric): NAs introduced by coercion
maptitle<-"1970-84"
map.active(csa.res, label.size=3, label.repel = T, map.title = maptitle)

map.active(csa.res, label.size=3, label.repel = T, dim=c(3,2), map.title = maptitle)

map.ctr(csa.res, dim = c(1,2), ctr.dim=c(1), label.size = 3, map.title = maptitle)

map.ctr(csa.res, dim = c(1,2), ctr.dim=c(2), label.size = 3, map.title = maptitle)

map.ctr(csa.res, dim = c(3,2), ctr.dim=c(3), label.size = 3, map.title = maptitle)

map.sup(csa.res, dim = c(1,2), label.size = 3, map.title = maptitle)
## Warning: Removed 15 rows containing missing values (geom_point).
## Warning: Removed 15 rows containing missing values (geom_text_repel).

map.sup(csa.res, dim = c(3,2), label.size = 3, map.title = maptitle)
## Warning: Removed 15 rows containing missing values (geom_point).

## Warning: Removed 15 rows containing missing values (geom_text_repel).

class    <- which(data$r02year15 == '00-')
csa.res <- soc.csa(result, class,sup=passsimple)
## Warning in lapply(obj, as.numeric): NAs introduced by coercion
maptitle<-"2000-"
map.active(csa.res, label.size=3, label.repel = T, map.title = maptitle)

map.active(csa.res, label.size=3, label.repel = T, dim=c(3,2), map.title = maptitle)

map.ctr(csa.res, dim = c(1,2), ctr.dim=c(1), label.size = 3, map.title = maptitle)

map.ctr(csa.res, dim = c(1,2), ctr.dim=c(2), label.size = 3, map.title = maptitle)

map.ctr(csa.res, dim = c(3,2), ctr.dim=c(3), label.size = 3, map.title = maptitle)

map.sup(csa.res, dim = c(1,2), label.size = 3, map.title = maptitle)
## Warning: Removed 15 rows containing missing values (geom_point).

## Warning: Removed 15 rows containing missing values (geom_text_repel).

map.sup(csa.res, dim = c(3,2), label.size = 3, map.title = maptitle)
## Warning: Removed 15 rows containing missing values (geom_point).

## Warning: Removed 15 rows containing missing values (geom_text_repel).