-- Attaching packages --------------------------------------- tidyverse 1.3.2 --
v ggplot2 3.3.6 v purrr 0.3.5
v tibble 3.1.8 v dplyr 1.0.10
v tidyr 1.2.1 v stringr 1.4.1
v readr 2.1.3 v forcats 0.5.2
-- Conflicts ------------------------------------------ tidyverse_conflicts() --
x dplyr::filter() masks stats::filter()
x dplyr::lag() masks stats::lag()
library(easystats)
# Attaching packages: easystats 0.5.2 (red = needs update)
x insight 0.18.4 v datawizard 0.6.2
v bayestestR 0.13.0 v performance 0.10.0
v parameters 0.19.0 v effectsize 0.8.0
v modelbased 0.8.5 v correlation 0.8.3
v see 0.7.3 v report 0.5.5
Restart the R-Session and update packages in red with `easystats::easystats_update()`.
library(gtsummary)
#Uighur
library(gt)library(lme4)
Le chargement a nécessité le package : Matrix
Attachement du package : 'Matrix'
Les objets suivants sont masqués depuis 'package:tidyr':
expand, pack, unpack
library(brms)
Le chargement a nécessité le package : Rcpp
Loading 'brms' package (version 2.18.0). Useful instructions
can be found by typing help('brms'). A more detailed introduction
to the package is available through vignette('brms_overview').
Attachement du package : 'brms'
L'objet suivant est masqué depuis 'package:lme4':
ngrps
L'objet suivant est masqué depuis 'package:stats':
ar
library(RColorBrewer)library(sf)
Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 7.2.1; sf_use_s2() is TRUE
library(flextable)
Attachement du package : 'flextable'
Les objets suivants sont masqués depuis 'package:gtsummary':
as_flextable, continuous_summary
L'objet suivant est masqué depuis 'package:purrr':
compose
setwd("C:/Users/bmotteba/Nextcloud/Donnees/Bresil/OD_SaoPaulo/OD_2017/Banco de dados")load("ba.RData")
Cross table Home based vs Outdoor Worplace
#show_header_names(z1) #connaitre le nom des colonnesba %>%tbl_cross(TRAB1_REf, TRABEXT1f, percent ="cell" , label =c(1~"Home based" , 2~"Outdoors") ) %>%bold_labels() %>%as_gt()%>%tab_header(title ="Workers by type of workplace",subtitle ="and the 3 groups included in the analysis") %>%tab_source_note(source_note ="Source: Data: Sao Paulo OD survey 2007 & 2017") %>%tab_footnote( footnote ="Home Based Work",locations =cells_body(columns = stat_2, 2)) %>%tab_footnote( footnote ="Outdoor Workers without a known work address",locations =cells_body(columns = stat_1, 3)) %>%tab_footnote( footnote ="Worker reference group",locations =cells_body(columns = stat_2, 3))
Workers by type of workplace
and the 3 groups included in the analysis
Outdoors
Total
Yes
No
Home based
Yes
2,000 (2.6%)
6,436 (8.4%)1
8,436 (11%)
No
9,618 (13%)2
55,093 (72%)3
64,711 (84%)
Other
1,727 (2.3%)
1,868 (2.4%)
3,595 (4.7%)
Total
13,345 (17%)
63,397 (83%)
76,742 (100%)
Source: Data: Sao Paulo OD survey 2007 & 2017
1 Home Based Work
2 Outdoor Workers without a known work address
3 Worker reference group
Preparation & summary of variables
# On enl�ve les agriculteurs, les employ�s de maison log�s sur place# On ne s�lectionne que les individus qui d�clarent TRAB1_RE == 1ba$Workplace <-"Other"ba$Workplace[ba$TRAB1_REf =="Yes"& ba$TRABEXT1f =="No"] <-"Home Based"ba$Workplace[ba$TRAB1_REf =="No"& ba$TRABEXT1f =="Yes"] <-"Outdoor"ba$Workplace[ba$TRAB1_REf =="No"& ba$TRABEXT1f =="No"] <-"Reference"bar <-subset(ba, SETOR1_rec !=1& SIT_FAM_rec !=6& Workplace !="Other")bar$SIT_FAM_rec <-factor(bar$SIT_FAM_rec)bar$SETOR1_rec <-factor(bar$SETOR1_rec)z1 <- bar %>%tbl_cross(yearf, Workplace, percent ="col", margin ="column", label =list(yearf ="Year")) %>%add_p()z2 <- bar %>%tbl_cross(VINC1_rec, Workplace, percent ="col", margin ="column", label =list(VINC1_rec ="Job type")) %>%add_p()z3 <- bar %>%tbl_cross(SETOR1_rec, Workplace, percent ="col", margin ="column", label =list(SETOR1_rec ="Activity sector")) %>%add_p()z4 <- bar %>%tbl_cross(SEXOf, Workplace, percent ="col", margin ="column", label =list(SEXOf ="Gender")) %>%add_p() z5 <- bar %>%tbl_cross(single, Workplace, percent ="col", margin ="column", label =list(single ="Single")) %>%add_p() z6 <- bar %>%tbl_cross(GRAU_INS_rec, Workplace, percent ="col", margin ="column", label =list(GRAU_INS_rec ="Education level")) %>%add_p()z7 <- bar %>%tbl_cross(QT_AUTO_rec, Workplace, percent ="col", margin ="column", label =list(QT_AUTO_rec ="Number of cars")) %>%add_p()tbl_stack(tbls =list(z1, z2, z3, z4, z5, z6, z7)) %>%bold_labels() %>%bold_labels() %>%as_gt()%>%tab_header(title ="Description of the variables used in the models") %>%tab_source_note(source_note ="Source: Data: Sao Paulo OD survey 2007 & 2017")
Description of the variables used in the models
Workplace
Total
p-value1
Home Based
Outdoor
Reference
Year
<0.001
2007
2,570 (48%)
7,373 (77%)
27,005 (49%)
36,948 (53%)
2017
2,730 (52%)
2,199 (23%)
27,908 (51%)
32,837 (47%)
Job type
<0.001
1
503 (9.5%)
4,786 (50%)
34,449 (63%)
39,738 (57%)
2
251 (4.7%)
906 (9.5%)
5,023 (9.1%)
6,180 (8.9%)
3
5 (<0.1%)
614 (6.4%)
4,129 (7.5%)
4,748 (6.8%)
4
2,841 (54%)
2,334 (24%)
4,739 (8.6%)
9,914 (14%)
5
137 (2.6%)
326 (3.4%)
2,078 (3.8%)
2,541 (3.6%)
6
721 (14%)
345 (3.6%)
2,002 (3.6%)
3,068 (4.4%)
7
842 (16%)
261 (2.7%)
2,493 (4.5%)
3,596 (5.2%)
Activity sector
<0.001
11
113 (2.1%)
332 (3.5%)
4,895 (8.9%)
5,340 (7.7%)
2
87 (1.6%)
392 (4.1%)
1,127 (2.1%)
1,606 (2.3%)
3
385 (7.3%)
864 (9.0%)
6,694 (12%)
7,943 (11%)
4
889 (17%)
1,789 (19%)
9,913 (18%)
12,591 (18%)
5
27 (0.5%)
554 (5.8%)
629 (1.1%)
1,210 (1.7%)
6
8 (0.2%)
707 (7.4%)
637 (1.2%)
1,352 (1.9%)
7
54 (1.0%)
237 (2.5%)
2,322 (4.2%)
2,613 (3.7%)
8
324 (6.1%)
104 (1.1%)
1,212 (2.2%)
1,640 (2.4%)
9
286 (5.4%)
280 (2.9%)
2,454 (4.5%)
3,020 (4.3%)
10
113 (2.1%)
501 (5.2%)
4,755 (8.7%)
5,369 (7.7%)
12
2,997 (57%)
3,288 (34%)
18,060 (33%)
24,345 (35%)
13
17 (0.3%)
524 (5.5%)
2,215 (4.0%)
2,756 (3.9%)
Gender
<0.001
1
2,634 (50%)
6,699 (70%)
28,077 (51%)
37,410 (54%)
2
2,666 (50%)
2,873 (30%)
26,836 (49%)
32,375 (46%)
Single
<0.001
0
4,679 (88%)
9,021 (94%)
51,528 (94%)
65,228 (93%)
1
621 (12%)
551 (5.8%)
3,385 (6.2%)
4,557 (6.5%)
Education level
<0.001
3
1,718 (32%)
2,878 (30%)
12,125 (22%)
16,721 (24%)
4
1,718 (32%)
3,863 (40%)
22,257 (41%)
27,838 (40%)
5
1,864 (35%)
2,831 (30%)
20,531 (37%)
25,226 (36%)
Number of cars
<0.001
0
1,815 (34%)
3,184 (33%)
19,515 (36%)
24,514 (35%)
1
2,435 (46%)
4,105 (43%)
23,252 (42%)
29,792 (43%)
2
837 (16%)
1,719 (18%)
9,324 (17%)
11,880 (17%)
3
213 (4.0%)
564 (5.9%)
2,822 (5.1%)
3,599 (5.2%)
Source: Data: Sao Paulo OD survey 2007 & 2017
1 Pearson's Chi-squared test
Model 1 & 2 : Outdoors & Home-based Work
# On enl�ve les agriculteurs, les employ�s de maison log�s sur place# On ne s�lectionne que les individus qui d�clarent TRAB1_RE == 1ba$SIT_FAM_rec <-factor(ba$SIT_FAM_rec)ba$SETOR1_rec <-factor(ba$SETOR1_rec)ba$TRAB1_REb <-ifelse(ba$TRAB1_RE ==1, 1, 0)ba$TRABEXT1b <-ifelse(ba$TRABEXT1 ==1, 1, 0)#Model 1 Unknown workplace outside of home vs Known Workplace (no HBW)ba1 <-subset(ba, SETOR1_rec !=1& SIT_FAM_rec !=6& TRAB1_REf =="No" )model1<-glmer(TRABEXT1b ~1+ (0+ yearf | VINC1_rec) + yearf+ SIT_FAM_rec + SEXOf + QT_AUTO_rec + GRAU_INS_rec + SETOR1_rec + IDADE + single ,family = binomial, nAGQ =0#, REML=F ,control =glmerControl(calc.derivs =FALSE) ,data = ba1)#Model 2 Home based work (HBW) vs Known Workplaceba2 <-subset(ba, SETOR1_rec !=1& SIT_FAM_rec !=6& TRAB1_RE !=3& TRABEXT1f =="No" )model2<-glmer(TRAB1_REb ~1+ (0+ yearf | VINC1_rec) + yearf+ SIT_FAM_rec + SEXOf + QT_AUTO_rec + GRAU_INS_rec + SETOR1_rec + IDADE + single #+ CRITERIOBR ,family = binomial, nAGQ =0#, REML=F ,control =glmerControl(calc.derivs =FALSE) ,data = ba2)compare_parameters(model1, model2, style ="se_p", effects ="all",column_names =c("Outdoor workplace", "Home based work")) %>%print_html(caption="Models parameters", digits ="signif2")
Models parameters
Parameter
Outdoor workplace
Home based work
Fixed Effects
(Intercept)
-1.6*** (0.17)
-3.3*** (0.64)
yearf (2017)
-1.7*** (0.22)
-0.57 (0.34)
SIT FAM rec (2)
-0.038 (0.036)
-0.085 (0.046)
SIT FAM rec (3)
-0.11** (0.036)
-0.33*** (0.058)
SIT FAM rec (4)
-0.19*** (0.052)
-0.0025 (0.072)
SEXOf (2)
-0.6*** (0.028)
0.27*** (0.038)
QT AUTO rec (1)
0.15*** (0.029)
0.026 (0.04)
QT AUTO rec (2)
0.16*** (0.039)
-0.24*** (0.055)
QT AUTO rec (3)
0.14* (0.058)
-0.44*** (0.088)
GRAU INS rec (4)
-0.057 (0.031)
-0.32*** (0.044)
GRAU INS rec (5)
-0.22*** (0.037)
-0.55*** (0.051)
SETOR1 rec (2)
1.1*** (0.089)
0.22 (0.16)
SETOR1 rec (3)
0.34*** (0.073)
0.64*** (0.12)
SETOR1 rec (4)
0.69*** (0.069)
0.42*** (0.11)
SETOR1 rec (5)
2.2*** (0.09)
0.37 (0.24)
SETOR1 rec (6)
2.5*** (0.087)
-0.56 (0.39)
SETOR1 rec (7)
0.27** (0.093)
0.19 (0.18)
SETOR1 rec (8)
-0.15 (0.12)
0.52*** (0.13)
SETOR1 rec (9)
0.46*** (0.092)
0.56*** (0.13)
SETOR1 rec (10)
0.28*** (0.077)
-0.85*** (0.14)
SETOR1 rec (12)
0.63*** (0.065)
1.1*** (0.11)
SETOR1 rec (13)
1.1*** (0.081)
0.093 (0.28)
IDADE
0.0017 (0.0011)
0.0086*** (0.0014)
single (1)
0.058 (0.053)
0.46*** (0.061)
Random Effects
SD (yearf2007: VINC1_rec)
0.38 (NA)
1.6 (NA)
SD (yearf2017: VINC1_rec)
0.67 (NA)
2.4 (NA)
Cor (yearf2007~yearf2017: VINC1_rec: VINC1_rec)
0.56 (NA)
0.98 (NA)
Best Linear Unbiased Predictions
estimate_grouplevel(model1, type =c("total")) %>%pivot_wider(names_from = Parameter,values_from = Coefficient) %>%print_html(caption="Probability of an Outdoor Workplace (Best Linear Unbiased Predictions)", digits ="signif2") #%>% flextable
Probability of an Outdoor Workplace
(Best Linear Unbiased Predictions)
Level
yearf2007
yearf2017
1
-0.34
-1.6
2
-0.13
-1.5
3
-0.22
-1.6
4
0.72
-0.33
5
-0.049
-2.4
6
0.4
-2.1
7
-0.36
-2.3
estimate_grouplevel(model2, type =c("total")) %>%pivot_wider(names_from = Parameter,values_from = Coefficient) %>%print_html(caption="Probability of Home Based Work (Best Linear Unbiased Predictions)", digits ="signif2")
Probability of Home Based Work
(Best Linear Unbiased Predictions)
Level
yearf2007
yearf2017
1
-1.3
-2.5
2
-0.53
-1.1
3
-3
-5
4
1.7
2
5
0.18
-0.59
6
1.2
1.9
7
1.7
1.2
compare_performance(model1, model2) %>%print_html(digits ="signif3", caption="Indices of model performance", layout="vertical") %>%tab_header(title =md("**Indices of model performance**"), )%>%tab_source_note(source_note ="Source: Data: Sao Paulo OD survey 2007 & 2017" ) %>%cols_label(model1 ="Outdoor workplace", model2 ="Home based work")
Warning: When comparing models, please note that probably not all models were fit
from same data.