Quelle est la distribution de la population des communes en France ?
Data set : fichier INSEE population communes
Lien : https://www.insee.fr/fr/statistiques/3545833?sommaire=3292701
On importe le fichier de données
d <- read.csv2(file.choose())
head(d)
## Code.région Nom.de.la.région Code.département Code.arrondissement
## 1 84 Auvergne-Rhône-Alpes 01 2
## 2 84 Auvergne-Rhône-Alpes 01 1
## 3 84 Auvergne-Rhône-Alpes 01 1
## 4 84 Auvergne-Rhône-Alpes 01 2
## 5 84 Auvergne-Rhône-Alpes 01 1
## 6 84 Auvergne-Rhône-Alpes 01 1
## Code.canton Code.commune Nom.de.la.commune Population.municipale
## 1 08 1 L' Abergement-Clémenciat 767
## 2 01 2 L' Abergement-de-Varey 241
## 3 01 4 Ambérieu-en-Bugey 14 127
## 4 22 5 Ambérieux-en-Dombes 1 619
## 5 04 6 Ambléon 109
## 6 01 7 Ambronay 2 615
## Population.comptée.à.part Population.totale
## 1 18 785
## 2 1 242
## 3 504 14 631
## 4 33 1 652
## 5 6 115
## 6 107 2 722
On peut chercher sa commune
d[d$Nom.de.la.commune == "Narcy",]
## Code.région Nom.de.la.région Code.département Code.arrondissement
## 19319 44 Grand Est 52 3
## 21994 27 Bourgogne-Franche-Comté 58 4
## Code.canton Code.commune Nom.de.la.commune Population.municipale
## 19319 08 347 Narcy 255
## 21994 01 189 Narcy 533
## Population.comptée.à.part Population.totale
## 19319 5 260
## 21994 16 549
d[d$Nom.de.la.commune == "Nancy",]
## Code.région Nom.de.la.région Code.département Code.arrondissement
## 20124 44 Grand Est 54 3
## Code.canton Code.commune Nom.de.la.commune Population.municipale
## 20124 99 395 Nancy 105 162
## Population.comptée.à.part Population.totale
## 20124 2 401 107 563
On met en forme la variable “Population.municipale”
class(d$Population.municipale)
## [1] "character"
head(d$Population.municipale)
## [1] "767" "241" "14 127" "1 619" "109" "2 615"
d$Population.municipale <- gsub(" ", "", d$Population.municipale)
d$Population.municipale <- as.numeric(d$Population.municipale)
head(d$Population.municipale)
## [1] 767 241 14127 1619 109 2615
On regarde la distribution de la population des communes
library(psych)
describe(d$Population.municipale)
## vars n mean sd median trimmed mad min max range skew
## X1 1 35441 1867.62 8483.46 451 691.37 467.02 0 471941 471941 19.82
## kurtosis se
## X1 626.4 45.06
hist(d$Population.municipale)
On regarde quatre catégories de communes:
1) moins de 500 habitants (small)
2) entre 500 et 1999 habitants (mid)
3) entre 2000 et 99 999 habitants (big)
4) plus de 100 000 habitants (large)
d$small <- rep(0,nrow(d))
d$mid <- rep(0,nrow(d))
d$big <- rep(0,nrow(d))
d$large <- rep(0,nrow(d))
for (i in 1:nrow(d)) {
ifelse(d$Population.municipale[i] <= 500, d$small[i] <- 1, d$small[i] <- 0)
ifelse(d$Population.municipale[i] > 500 & d$Population.municipale[i] <= 1999, d$mid[i] <- 1, d$mid[i] <- 0)
ifelse(d$Population.municipale[i] > 2000 & d$Population.municipale[i] <= 99999, d$big[i] <- 1, d$big[i] <- 0)
ifelse(d$Population.municipale[i] >= 100000, d$large[i] <- 1, d$large[i] <- 0)
}
Communes moins de 500 habitants (small)
sum(d$small)
## [1] 18782
(sum(d$small)/nrow(d))*100
## [1] 52.99512
Communes entre 500 et 1999 habitants (mid)
sum(d$mid)
## [1] 11316
(sum(d$mid)/nrow(d))*100
## [1] 31.92912
Communes entre 2000 et 99 999 habitants (big)
sum(d$big)
## [1] 5289
(sum(d$big)/nrow(d))*100
## [1] 14.92339
Communes plus de 100 000 habitants (large)
sum(d$large)
## [1] 50
(sum(d$large)/nrow(d))*100
## [1] 0.1410795
Dans ce cas on peut appliquer une transformation logarithmique à la variable
Effet d’une transformation logarithmique
hist(log(d$Population.municipale))