-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.mlm.R
194 lines (172 loc) · 8.92 KB
/
4.mlm.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
library(lme4)
library(lmerTest)
library(sjPlot)
#---European countries---
ds_ml <- ISC_lvR %>% filter(!COUNTRY %in% c(CNTne, CNT2cne)) %>%
dplyr::select(cycle, IDSCHOOL, COUNTRY, SENWGT, all_of(Indicfa), all_of(Man_cate), all_of(Man_cont))
knitr::kable(table(ds_ml$cycle,ds_ml$COUNTRY), caption = "European countries included in the analysis") %>% print()
Man_cate2 <- Man_cate[!grepl(paste0(c("T_HIGHEDFA", "T_HISCED"), collapse = "|"), Man_cate)]
Man_cont2 <- Man_cont[!grepl(paste0(c("T_NISB", "T_CITRESP"), collapse = "|"), Man_cont)]
formReg <- paste0(paste(Man_cate2, collapse = " + "), " + ", paste(Man_cont2, collapse = " + "))
Man_cate3 <- Man_cate2[!grepl(paste0(c("T_HIGHEDEXP", "T_RELIG", "T_PROTES1"), collapse = "|"), Man_cate2)]
Man_cont3 <- Man_cont2[!grepl(paste0(c("T_NISB", "T_HISEI", "T_PROTES", "T_CNTATT", "T_ELECPART", "T_LEGACT", "T_WIDEPART", "T_CITRESP"), collapse = "|"), Man_cont2)]
formReg1 <- paste0(paste(Man_cate3, collapse = " + "), " + ", paste(Man_cont3, collapse = " + "))
# attr(ds_ml$Ethn_Equal, "label") <- NULL
# attr(ds_ml$Gend_Equal, "label") <- NULL
# attr(ds_ml$Immi_Equal, "label") <- NULL
attr(ds_ml$Ethn_Equal, "class") <- NULL
attr(ds_ml$Gend_Equal, "class") <- NULL
attr(ds_ml$Immi_Equal, "class") <- NULL
#--- Nested in cycles----------
# -----------------------------#
##### 2 cycles 2009/2016########
# -----------------------------#
ds_ml0 <- ds_ml %>% filter(cycle %in% c("C2", "C3"))
# Null model
L3 <- list()
for(i in 1:length(Indicfa)){
form <- as.formula(paste0(Indicfa[i],"~ (1|cycle) + (1|cycle:COUNTRY) + (1|cycle:COUNTRY:IDSCHOOL)"))
L3[[i]] <- lmer(form, data=ds_ml0, weights=SENWGT, REML=FALSE)
}
t2cNull <- tab_model(L3, collapse.ci = TRUE, p.style = "stars")
# Model 1
Lr3 <- list()
for(i in 1:length(Indicfa)){
form <- as.formula(paste0(Indicfa[i],"~ ", formReg, "+ (1|cycle) + (1|cycle:COUNTRY) + (1|cycle:COUNTRY:IDSCHOOL)"))
Lr3[[i]] <- lmer(form, data=ds_ml0, weights=SENWGT, REML=FALSE)
}
t2cMod1 <- tab_model(Lr3, collapse.ci = TRUE, p.style = "stars")
rm(L3, Lr3)
# -----------------------------#
### 3 cycles 1999/2009/2016 ###
# -----------------------------#
# Null model
L3 <- list()
for(i in 1:length(Indicfa)){
form <- as.formula(paste0(Indicfa[i],"~ (1|cycle) + (1|cycle:COUNTRY) + (1|cycle:COUNTRY:IDSCHOOL)"))
L3[[i]] <- lmer(form, data=ds_ml, weights=SENWGT, REML=FALSE)
}
t3cNull <- tab_model(L3, collapse.ci = TRUE, p.style = "stars")
# Model 1
Lr3 <- list()
for(i in 1:length(Indicfa)){
form <- as.formula(paste0(Indicfa[i],"~ ", formReg1, "+ (1|cycle) + (1|cycle:COUNTRY) + (1|cycle:COUNTRY:IDSCHOOL)"))
Lr3[[i]] <- lmer(form, data=ds_ml, weights=SENWGT, REML=FALSE)
}
t3cMod1 <- tab_model(Lr3, collapse.ci = TRUE, p.style = "stars")
rm(L3, Lr3)
# -----------------------------#
### By cycles 1999/2009/2016 ###
# -----------------------------#
# Null model
Lr2 <- list(GEND = list(), IMMI = list(), ETHN = list())
trNull <- list(GEND = list(), IMMI = list(), ETHN = list())
for(k in 1:length(Indicfa)){
for(j in 1:3){
if(j==1) form <- as.formula(paste0(Indicfa[k],"~ (1|COUNTRY) + (1|COUNTRY:IDSCHOOL)"))
else form <- as.formula(paste0(Indicfa[k],"~ (1|COUNTRY) + (1|COUNTRY:IDSCHOOL)"))
Lr2[[k]][[j]] <- lmer(form, data=ds_ml[ds_ml$cycle == paste0("C",j),], weights=SENWGT, REML=FALSE)
}
trNull[[k]] <- tab_model(Lr2[[k]], dv.labels = c("CIVED 1999", "ICCS 2009", "ICCS 2016"),
collapse.ci = TRUE, p.style = "stars", title = sjlabelled::get_label(eval(parse(text=paste0("ISC_lvR$",Indicfa[k])))))
}
rm(Lr2)
# Model 1
Lr2 <- list(GEND = list(), IMMI = list(), ETHN = list())
trMod1 <- list(GEND = list(), IMMI = list(), ETHN = list())
for(k in 1:length(Indicfa)){
for(j in 1:3){
if(j==1) form <- as.formula(paste0(Indicfa[k],"~ ", formReg1, "+ (1|COUNTRY) + (1|COUNTRY:IDSCHOOL)"))
else form <- as.formula(paste0(Indicfa[k],"~ ", formReg, "+ (1|COUNTRY) + (1|COUNTRY:IDSCHOOL)"))
Lr2[[k]][[j]] <- lmer(form, data=ds_ml[ds_ml$cycle == paste0("C",j),], weights=SENWGT, REML=FALSE)
}
trMod1[[k]] <- tab_model(Lr2[[k]], dv.labels = c("CIVED 1999", "ICCS 2009", "ICCS 2016"),
collapse.ci = TRUE, p.style = "stars", title = sjlabelled::get_label(eval(parse(text=paste0("ISC_lvR$",Indicfa[k])))))
}
rm(Lr2)
###Non european countries
ds_mlne <- ISC_lvR %>% filter(COUNTRY %in% c(CNTne, CNT2cne)) %>%
dplyr::select(cycle, IDSCHOOL, COUNTRY, SENWGT, all_of(Indicfa), all_of(Man_cate), all_of(Man_cont))
knitr::kable(table(ds_mlne$cycle,ds_mlne$COUNTRY), caption = "Non-European countries included in the analysis") %>% print()
Man_cate2 <- Man_cate[!grepl(paste0(c("T_HIGHEDFA", "T_HISCED"), collapse = "|"), Man_cate)]
Man_cont2 <- Man_cont[!grepl(paste0(c("T_NISB", "T_CITRESP"), collapse = "|"), Man_cont)]
formReg <- paste0(paste(Man_cate2, collapse = " + "), " + ", paste(Man_cont2, collapse = " + "))
Man_cate3 <- Man_cate2[!grepl(paste0(c("T_HIGHEDEXP", "T_RELIG", "T_PROTES1"), collapse = "|"), Man_cate2)]
Man_cont3 <- Man_cont2[!grepl(paste0(c("T_NISB", "T_HISEI", "T_PROTES", "T_CNTATT", "T_ELECPART", "T_LEGACT", "T_WIDEPART", "T_CITRESP"), collapse = "|"), Man_cont2)]
formReg1 <- paste0(paste(Man_cate3, collapse = " + "), " + ", paste(Man_cont3, collapse = " + "))
# attr(ds_mlne$Ethn_Equal, "label") <- NULL
# attr(ds_mlne$Gend_Equal, "label") <- NULL
# attr(ds_mlne$Immi_Equal, "label") <- NULL
#
attr(ds_mlne$Ethn_Equal, "class") <- NULL
attr(ds_mlne$Gend_Equal, "class") <- NULL
attr(ds_mlne$Immi_Equal, "class") <- NULL
#--- Nested in cycles----------
# -----------------------------#
##### 2 cycles 2009/2016########
# -----------------------------#
ds_mlne0 <- ds_mlne %>% filter(cycle %in% c("C2", "C3"))
Indicfane <- Indicfa[!grepl("Immi_Equal", Indicfa)]
# Null model
L3 <- list()
for(i in 1:length(Indicfane)){
form <- as.formula(paste0(Indicfane[i],"~ (1|cycle) + (1|cycle:COUNTRY) + (1|cycle:COUNTRY:IDSCHOOL)"))
L3[[i]] <- lmer(form, data=ds_mlne0, weights=SENWGT, REML=FALSE)
}
Nt2cNull <- tab_model(L3, collapse.ci = TRUE, p.style = "stars")
# Model 1
Lr3 <- list()
for(i in 1:length(Indicfane)){
form <- as.formula(paste0(Indicfane[i],"~ ", formReg, "+ (1|cycle) + (1|cycle:COUNTRY) + (1|cycle:COUNTRY:IDSCHOOL)"))
Lr3[[i]] <- lmer(form, data=ds_mlne0, weights=SENWGT, REML=FALSE)
}
Nt2cMod1 <- tab_model(Lr3, collapse.ci = TRUE, p.style = "stars")
rm(L3, Lr3)
# -----------------------------#
### 3 cycles 1999/2009/2016 ###
# -----------------------------#
# Null model
L3 <- list()
for(i in 1:length(Indicfane)){
form <- as.formula(paste0(Indicfane[i],"~ (1|cycle) + (1|cycle:COUNTRY) + (1|cycle:COUNTRY:IDSCHOOL)"))
L3[[i]] <- lmer(form, data=ds_mlne, weights=SENWGT, REML=FALSE)
}
Nt3cNull <- tab_model(L3, collapse.ci = TRUE, p.style = "stars")
# Model 1
Lr3 <- list()
for(i in 1:length(Indicfane)){
form <- as.formula(paste0(Indicfane[i],"~ ", formReg1, "+ (1|cycle) + (1|cycle:COUNTRY) + (1|cycle:COUNTRY:IDSCHOOL)"))
Lr3[[i]] <- lmer(form, data=ds_mlne, weights=SENWGT, REML=FALSE)
}
Nt3cMod1 <- tab_model(Lr3, collapse.ci = TRUE, p.style = "stars")
rm(L3, Lr3)
# -----------------------------#
### By cycles 1999/2009/2016 ###
# -----------------------------#
# Null model
Lr2 <- list(GEND = list(), IMMI = list(), ETHN = list())
NtrNull <- list(GEND = list(), IMMI = list(), ETHN = list())
for(k in 1:length(Indicfa)){
if(Indicfa[k] == "Immi_Equal") {t <- 1:2; dv <- c("CIVED 1999", "ICCS 2009")}else {t <- 1:3; dv <-c("CIVED 1999", "ICCS 2009", "ICCS 2016")}
for(j in t){
form <- as.formula(paste0(Indicfa[k],"~ (1|COUNTRY) + (1|COUNTRY:IDSCHOOL)"))
Lr2[[k]][[j]] <- lmer(form, data=ds_mlne[ds_mlne$cycle == paste0("C",j),], weights=SENWGT, REML=FALSE)
}
NtrNull[[k]] <- tab_model(Lr2[[k]], dv.labels = dv,
collapse.ci = TRUE, p.style = "stars", title = sjlabelled::get_label(eval(parse(text=paste0("ISC_lvR$",Indicfa[k])))))
}
rm(Lr2)
# Model 1
Lr2 <- list(GEND = list(), IMMI = list(), ETHN = list())
NtrMod1 <- list(GEND = list(), IMMI = list(), ETHN = list())
for(k in 1:length(Indicfa)){
if(Indicfa[k] == "Immi_Equal") {t <- 1:2; dv <- c("CIVED 1999", "ICCS 2009")}else {t <- 1:3; dv <-c("CIVED 1999", "ICCS 2009", "ICCS 2016")}
for(j in t){
if(j==1) form <- as.formula(paste0(Indicfa[k],"~ ", formReg1, "+ (1|COUNTRY) + (1|COUNTRY:IDSCHOOL)"))
else form <- as.formula(paste0(Indicfa[k],"~ ", formReg, "+ (1|COUNTRY) + (1|COUNTRY:IDSCHOOL)"))
Lr2[[k]][[j]] <- lmer(form, data=ds_mlne[ds_mlne$cycle == paste0("C",j),], weights=SENWGT, REML=FALSE)
}
NtrMod1[[k]] <- tab_model(Lr2[[k]], dv.labels = dv,
collapse.ci = TRUE, p.style = "stars", title = sjlabelled::get_label(eval(parse(text=paste0("ISC_lvR$",Indicfa[k])))))
}
rm(Lr2)