Académique Documents
Professionnel Documents
Culture Documents
Samuel AYANOU
Introduction
Dans la suite de notre travail il serait l’objet de repondre aux différentes questions qui nous
sont posées.
library(readxl)
library(janitor)
chisq.test, fisher.test
# library a rechargé
library(dplyr)
Attachement du package : 'dplyr'
filter, lag
library(stats)
library(base)
library(flextable)
library(knitr)
• on continue
na_var_eff <- colSums(is.na(projet))
na_var_pct <- colSums(is.na(projet)* 100/nrow(projet))
Variable Pourcen
Effectifs
s tage
key 0 0.0
q1 0 0.0
q2 0 0.0
q23 0 0.0
q24 0 0.0
q24a_1 0 0.0
q24a_2 0 0.0
Variable Pourcen
Effectifs
s tage
q24a_3 0 0.0
q24a_4 0 0.0
q24a_5 0 0.0
q24a_6 0 0.0
q24a_7 0 0.0
q24a_9 0 0.0
q24a_10 0 0.0
q25 0 0.0
q26 0 0.0
q12 0 0.0
q14b 1 0.4
q16 1 0.4
q20 0 0.0
filiere_1 0 0.0
filiere_2 0 0.0
filiere_3 0 0.0
filiere_4 0 0.0
q8 0 0.0
q81 0 0.0
gps_me
0 0.0
nlatitude
gps_me
nlongitu 0 0.0
de
submissi
0 0.0
ondate
start 0 0.0
Variable Pourcen
Effectifs
s tage
today 0 0.0
• verification des valeurs manquantes pour la variable key dans la base projet
# valeur manquante key
if (nrow(valeurs_manquantes) > 0) {
pme_concernees <- unique(valeurs_manquantes$PME)
print(pme_concernees)
} else {
print("Aucune valeur manquante pour la variable 'key'")
NULL
Création de variables
• je renomme la variable q1 en région
# je vais utiliser la fonction rename_data.frame de dplyr
library(dplyr)
# je renomme q1 en region q2 en departement, q23 en sexe en créant un nouveau
data.frame projet_renom
• créons maintenant la variable sexe_2 qui vaut 1 si sexe égale à Femme et 0 sinon.
# alors 1 si le sexe est femme et 0 sinon avec la fonction ifelse
projet_renom$sexe_2<- ifelse(projet_renom$sexe == "Femme", 1, 0)
• je crée un data.frame nommé langues qui prend les variables key et les variables
correspondantes décrites plus haut
# avec ma fonction select je crée un data.frame en choississant comme
variable key et tous les variable començant par q24a_
langues<- janitor::adorn_totals(langues,where="col")
langues <- dplyr:::rename.data.frame(langues, parle = Total)
langues
• je sélectionne uniquement les variables key et parle, l’objet de retour sera langues.
# avec la fonction select je règle mon problème
langues<- dplyr::select(langues,key, parle)
langues <- as.data.frame(langues)
Analyses descriptives
ouf l’analyse descriptive
# appel au package gtsummary
library(gtsummary)
#StandWithUkraine
as_flextable, continuous_summary
library(dplyr)
creation de tableau
repartition des PME suivant le sexe du responsable
# la fonction tbl_summary nous vient en aide en selectionnant la variable q23
) %>%
bold_labels() %>%
italicize_labels()
t_sexe
) %>%
bold_labels() %>%
italicize_labels()
t_instruction
) %>%
bold_labels() %>%
italicize_labels()
t_juridique
repartition des PME selon que cela soit dirige par un proprietaire/ locataire
# que faire sans tbl_summary ? je l'applique a q81
# afficher la table
t_sexe_ins
) %>%
add_p(source_note = TRUE)
t_sexe_jur
Tableau general
library(gtsummary)
# Et si je faisait un tableau ou je combine tous ?
table_gene <- projet_merge %>%
tbl_summary(
include = c(q12, q25, q81, q23), # différentes variables à inclure dans
le tableau
by = q23, # regroupement par sexe
label = list(
q23 ~ "Répartition des PME selon le sexe de leur responsable",
q12 ~ "Répartition des responsables des PME selon le statut juridique",
q81 ~ "Répartition des PME selon leur propriétaire/locataire",
q25 ~ "Répartition des responsables des PME selon le niveau
d'instruction"
)
) %>%
bold_labels() %>% # ajout des styles aux libellés
italicize_labels() %>%
gtsummary:: modify_header(
label = "__variable__",
$`pkgwide-str:theme_name`
[1] "JAMA"
$`pkgwide-fn:pvalue_fun`
function (x)
style_pvalue(x, digits = 2)
<bytecode: 0x000002ae5b511de0>
<environment: 0x000002ae5b54f8c8>
$`pkgwide-fn:prependpvalue_fun`
function (x)
style_pvalue(x, digits = 2, prepend_p = TRUE)
<bytecode: 0x000002ae5b511c20>
<environment: 0x000002ae5b54f8c8>
$`pkgwide-str:ci.sep`
[1] " to "
$`style_number-arg:decimal.mark`
[1] "."
$`style_number-arg:big.mark`
[1] ","
$`add_stat_label-arg:location`
[1] "row"
$`tbl_summary-str:continuous_stat`
[1] "{median} ({p25} – {p75})"
$`tbl_summary-str:categorical_stat`
[1] "{n} ({p})"
$`tbl_summary-fn:addnl-fn-to-run`
function (x)
{
add_stat_label(x)
}
<bytecode: 0x000002ae5b5119b8>
<environment: 0x000002ae5b54f8c8>
$`add_difference-fn:addnl-fn-to-run`
function (x)
{
tryCatch({
new_header_text <- paste0(x$table_styling$header %>%
filter(.data$column == "estimate") %>% pull("label"),
" **(**", x$table_styling$header %>% filter(.data$column ==
"ci") %>% pull("label"), "**)**")
estimate_footnote <- x$table_styling$footnote_abbrev %>%
filter(.data$column %in% "estimate") %>%
filter(dplyr::row_number() ==
dplyr::n(), !is.na(.data$footnote)) %>% dplyr::pull("footnote")
%>%
c("CI = Confidence Interval") %>% paste(collapse = ", ")
x %>% modify_table_styling(columns = "estimate", rows = !!
expr(.data$variable %in%
!!x$table_body$variable & !is.na(.data$estimate)),
cols_merge_pattern = "{estimate} ({conf.low} to {conf.high})") %>
%
modify_column_hide(any_of("ci")) %>% modify_header(list(estimate
= new_header_text)) %>%
modify_footnote(estimate ~ estimate_footnote, abbreviation =
TRUE)
}, error = function(e) x)
}
<bytecode: 0x000002ae5b511750>
<environment: 0x000002ae5b54f8c8>
$`tbl_regression-fn:addnl-fn-to-run`
function (x)
{
tryCatch({
new_header_text <- paste0(x$table_styling$header %>%
filter(.data$column == "estimate") %>% pull("label"),
" **(", style_number(x$inputs$conf.level, scale = 100),
"% CI)**")
estimate_footnote <- x$table_styling$footnote_abbrev %>%
filter(.data$column %in% "estimate") %>%
filter(dplyr::row_number() ==
dplyr::n(), !is.na(.data$footnote)) %>% dplyr::pull("footnote")
%>%
c("CI = Confidence Interval") %>% paste(collapse = ", ")
x %>% modify_table_styling(columns = "estimate", rows = !!
expr(.data$variable %in%
!!x$table_body$variable & !is.na(.data$estimate) &
!.data$reference_row %in% TRUE), cols_merge_pattern = "{estimate}
({conf.low} to {conf.high})") %>%
modify_column_hide(any_of("ci")) %>% modify_header(list(estimate
= new_header_text)) %>%
modify_footnote(estimate ~ estimate_footnote, abbreviation =
TRUE)
}, error = function(e) x)
}
<bytecode: 0x000002ae5b5214f8>
<environment: 0x000002ae5b54f8c8>
theme_gtsummary_journal(
journal = c("jama", "lancet", "nejm", "qjecon"),
set_theme = TRUE
table_gene
SA 1 (0.5%) 6 (10%)
variable Femme, N = 1911 Homme, N = 591
1
n (%)
# j'ai quelque chose de magnifique
A notre imagination
• Analyse par filiere
# une fonction plus simple
table<- function(bases, groupes, labell, includes){
t<-bases %>%
tbl_summary(
include = includes,
by = groupes,
percent="col",
label = labell
) %>%
bold_labels() %>% # ajout des styles aux libellés
italicize_labels()%>%
modify_header(
label = "__variable__",
stat_1 = "**non**, ({n}/{N})",
stat_2 = "**oui**, ({n}/{N})"
)
return(t)
}
• filière 1
# que dire sur les filieres ?
tbl_summary(
)
) %>%
t_fil_1
)
) %>%
bold_labels() %>% # ajout des styles aux libellés
italicize_labels()%>% modify_header(
label = "__variable__",
stat_1 = "**non**, ({n}/{N})",
stat_2 = "**oui**, ({n}/{N})" )
t_fil_2
non, (189/250)
0 (0)
34 (18)
9 (4.8)
8 (4.2)
21 (11)
4 (2.1)
non, (189/250)
42 (22)
1 (0.5)
51 (27)
19 (10)
66 (35)
39 (21)
59 (31)
25 (13)
17 (9.0)
172 (91)
20 (11)
8 (4.2)
1 (0.5)
39 (21)
12 (6.3)
3 (1.6)
6 (3.2)
non, (189/250)
0 (0)
4 (2.1)
16 (8.5)
3 (1.6)
3 (1.6)
2 (1.1)
22 (12)
0 (0)
5 (2.6)
1 (0.5)
1 (0.5)
0 (0)
2 (1.1)
1 (0.5)
23 (12)
6 (3.2)
1 (0.5)
10 (5.3)
5 (2.6)
non, (189/250)
4 (2.1)
56 (30)
12 (6.3)
1 (0.5)
43 (23)
22 (12)
0 (0)
0 (0)
46 (24)
)
) %>%
bold_labels() %>% # ajout des styles aux libellés
italicize_labels()%>%
modify_header(
label = "__variable__",
stat_1 = "**non**, ({n}/{N})",
stat_2 = "**oui**, ({n}/{N})"
t_fil_3
non, (161/250)
1 (0.6)
33 (20)
27 (17)
3 (1.9)
14 (8.7)
9 (5.6)
0 (0)
4 (2.5)
26 (16)
44 (27)
53 (33)
32 (20)
49 (30)
non, (161/250)
27 (17)
13 (8.1)
148 (92)
20 (12)
13 (8.1)
0 (0)
0 (0)
12 (7.5)
15 (9.3)
12 (7.5)
3 (1.9)
1 (0.6)
9 (5.6)
7 (4.3)
2 (1.2)
1 (0.6)
8 (5.0)
1 (0.6)
non, (161/250)
5 (3.1)
2 (1.2)
0 (0)
1 (0.6)
0 (0)
1 (0.6)
13 (8.1)
5 (3.1)
1 (0.6)
29 (18)
5 (3.1)
4 (2.5)
29 (18)
8 (5.0)
1 (0.6)
43 (27)
33 (20)
32 (20)
6 (3.7)
non, (161/250)
0 (0)
)
) %>%
bold_labels() %>% # ajout des styles aux libellés
italicize_labels()%>%
modify_header(
label = "__variable__",
stat_1 = "**non**, ({n}/{N})",
stat_2 = "**oui**, ({n}/{N})"
t_fil_4
non, (158/250)
20 (13)
1 (0.6)
0 (0)
non, (158/250)
39 (25)
12 (7.6)
14 (8.9)
12 (7.6)
1 (0.6)
4 (2.5)
12 (7.6)
4 (2.5)
3 (1.9)
2 (1.3)
8 (5.1)
1 (0.6)
5 (3.2)
0 (0)
1 (0.6)
0 (0)
2 (1.3)
0 (0)
9 (5.7)
2 (1.3)
non, (158/250)
0 (0)
6 (3.8)
68 (43)
30 (19)
42 (27)
18 (11)
15 (9.5)
143 (91)
0 (0)
34 (22)
26 (16)
7 (4.4)
17 (11)
5 (3.2)
42 (27)
1 (0.6)
19 (12)
non, (158/250)
7 (4.4)
5 (3.2)
1 (0.6)
36 (23)
5 (3.2)
1 (0.6)
43 (27)
0 (0)
25 (16)
0 (0)
42 (27)
oui, (61/250)
13 (21)
17 (28)
15 (25)
16 (26)
oui, (61/250)
7 (11)
54 (89)
oui, (61/250)
0 (0)
0 (0)
1 (1.6)
2 (3.3)
0 (0)
4 (6.6)
13 (21)
32 (52)
9 (15)
oui, (61/250)
0 (0)
1 (1.6)
0 (0)
21 (34)
0 (0)
0 (0)
5 (8.2)
0 (0)
3 (4.9)
0 (0)
31 (51)
0 (0)
5 (8.2)
0 (0)
0 (0)
0 (0)
12 (20)
oui, (61/250)
9 (15)
3 (4.9)
0 (0)
0 (0)
4 (6.6)
0 (0)
0 (0)
0 (0)
1 (1.6)
0 (0)
1 (1.6)
0 (0)
1 (1.6)
0 (0)
0 (0)
0 (0)
0 (0)
0 (0)
25 (41)
oui, (61/250)
oui, (61/250)
library(dplyr)
# duree de l enregistrement
projet_mod <- projet_merge %>% mutate( duree_enquete=
as.numeric(interval( start,submissiondate) %>% as.duration()))
)
) %>%
bold_labels() %>% # ajout des styles aux libellés
italicize_labels()%>%
modify_header(
label = "__variable/ duree de l'enqête__",
stat_1 = "**inferieur a un jour **, ({n}/{N})",
stat_2 = "**entre 1 et 10 jours**, ({n}/{N})",
stat_3 = "**plus de 10 jours**, ({n}/{N})"
)%>% as_flex_table()
table_date
allons faire de la cartographie
importation des données
library(ggplot2)
library(sf)
library(st)
Le chargement a nécessité le package : sda
ggplot(projet)+geom_sf(data=senegal)+geom_point(aes(x=gps_menlongitude,
y=gps_menlatitude, color= q23))+ labs (title= "réprésentation spatiale des
PME suivant le sexe", x="gps_menlongitude", y="gps_menlatitude" )+
theme_classic()
ggplot(projet)+geom_sf(data=senegal)+geom_point(aes(x=gps_menlongitude,
y=gps_menlatitude, color= q12))+ labs (title= "réprésentation spatiale des
PME suivant le niveau d'education ", x="gps_menlongitude",
y="gps_menlatitude" )+ theme_classic()
analyse spatiale de votre choix
# représentation spatiale des PME selon propriétaire ou locataire et Nombre
d’années d’experience professionnelle du dirigeant/responsable de la PME dans
l’entreprise
ggplot(data = projet) +
# Spatial representation of Senegal
geom_sf(data = senegal) +