{"word_count": 431, "character_count": 4983}
A few months ago, I did mention that France was a country with strong inequalities, especially when you look at higher education, and research teams. Paris has almost 50% of the CNRS researchers, while only 3% of the population lives there.CNRS, &#34;répartition des chercheurs en SHS&#34; https://t.co/39dcJJBwrF, Paris 47.52% IdF 66.85% (pop 3.39% et 18.18% resp) pic.twitter.com/OsEXiFywPf&#8212; Arthur Charpentier (@freakonometrics) 28 septembre 2015It looks like Paris is the only city, in France. And I wanted to check that, indeed, France is a country with strong inequalities, when we look at population density.Using data from sedac.ciesin.columbia.edu, it is possible to get population density on a small granularity level,&#62; rm(list=ls())&#62; base=read.table(+      "/home/charpentier/glp00ag.asc",+      skip=6)&#62; X=t(as.matrix(base,ncol=8640))&#62; X=X[,ncol(X):1]The scales for latitudes and longitudes can be obtained from the text file,&#62; #ncols         8640&#62; #nrows         3432&#62; #xllcorner     -180&#62; #yllcorner     -58&#62; #cellsize      0.0416666666667Hence, we have&#62; library(maps)&#62; world=map(database="world")&#62; vx=seq(-180,180,length=nrow(X)+1)&#62; vx=(vx[2:length(vx)]+vx[1:(length(vx)-1)])/2&#62; vy=seq(-58,85,length=ncol(X)+1)&#62; vy=(vy[2:length(vy)]+vy[1:(length(vy)-1)])/2If we plot our density, as in a previous post, on Where People Live,&#62; I=seq(1,nrow(X),by=10)&#62; J=seq(1,ncol(X),by=10)&#62; image(vx[I],vy[J],log(1+X[I,J]),+ col=rev(heat.colors(101)))&#62; lines(world[[1]],world[[2]])we can see that we have a match, between the big population matrix, and polygons of countries.Consider France, for instance. We can download the contour polygon with higher precision,&#62; library(rgdal)&#62; fra=download.file("http://biogeo.ucdavis.edu/data/gadm2.8/rds/FRA_adm0.rds",+ "fr.rds")&#62; Fra=readRDS("fr.rds")&#62; n=length(Fra@polygons[[1]]@Polygons)&#62; L=rep(NA,n)&#62; for(i in 1:n) L[i]=nrow(Fra@polygons[[1]]@Polygons[[i]]@coords)&#62; idx=which.max(L)&#62; polygon_Fr=+       Fra@polygons[[1]]@Polygons[[idx]]@coords&#62; min_poly=apply(polygon_Fr,2,min)&#62; max_poly=apply(polygon_Fr,2,max)&#62; idx_i=which((vx&#62;min_poly[1])&#38;(vx&#60;max_poly[1]))&#62; idx_j=which((vy&#62;min_poly[2])&#38;(vy&#60;max_poly[2]))&#62; sub_X=X[idx_i,idx_j]&#62; image(vx[idx_i],vy[idx_j],+       log(sub_X+1),col=rev(heat.colors(101)),+       xlab="",ylab="")&#62; lines(polygon_Fr)We are now able to extract information about population for France, only (actually, it is only mainland France, islands are not considered here... to avoid complicated computations&#62; library(sp)&#62; xy=expand.grid(x = vx[idx_i], y = vy[idx_j])&#62; dim(xy)[1] 65730     2Here, we have 65,730 small squares, in France.&#62; pip=point.in.polygon(xy[,1],xy[,2],+     polygon_Fr[,1],polygon_Fr[,2])&#62;0&#62; dim(pip)=dim(sub_X)&#62; Fr=sub_X[pip]&#62; sum(Fr)[1] 58105272Observe that the total population within the French polygon is close to 60 million people, which is consistent with actual figures. Now, if we look more carefully at repartition over the French territory&#62; library(ineq)&#62; Gini(Fr)[1] 0.7296936Gini coefficient is rather high (over 70%), but it is also possible to visualize Lorenz curve,&#62; plot(Lc(Fr))Observe that in 5% of the territory, we can find almost 54% of the population&#62; 1-min(LcF$L[LcF$p&#62;.95])[1] 0.5462632In order to compare with other countries, consider the&#62; LC=function(rds="fr.rds"){+ Fra=readRDS(rds)+ n=length(Fra@polygons[[1]]@Polygons)+ L=rep(NA,n)+ for(i in 1:n) L[i]=nrow(Fra@polygons[[1]]@Polygons[[i]]@coords)+ idx=which.max(L)+ polygon_Fr=+      Fra@polygons[[1]]@Polygons[[idx]]@coords+ min_poly=apply(polygon_Fr,2,min)+ max_poly=apply(polygon_Fr,2,max)+ idx_i=which((vx&#62;min_poly[1])&#38;(vx&#60;max_poly[1]))+ idx_j=which((vy&#62;min_poly[2])&#38;(vy&#60;max_poly[2]))+ sub_X=X[idx_i,idx_j]+ xy=expand.grid(x = vx[idx_i], y = vy[idx_j])+ dim(xy)+ pip=point.in.polygon(xy[,1],xy[,2],+     polygon_Fr[,1],polygon_Fr[,2])&#62;0+ dim(pip)=dim(sub_X)+ Fr=sub_X[pip]+ return(list(gini=Gini(Fr),LC=Lc(Fr))+ }&#62; FRA=LC()For instance, consider Germany, or Italy&#62; deu=download.file("http://biogeo.ucdavis.edu/data/gadm2.8/rds/DEU_adm0.rds","deu.rds")&#62; DEU=LC("deu.rds")&#62; ita=download.file("http://biogeo.ucdavis.edu/data/gadm2.8/rds/ITA_adm0.rds","ita.rds")&#62; ITA=LC("ita.rds")It is possible to plot Lorenz curve, together,&#62; plot(FRA$LC,col="blue")&#62; lines(DEU$LC,col="black")&#62; lines(ITA$LC,col="red")Observe that France is clearly below the other ones. Compared with Germany, there is a significant difference&#62; FRA$gini[1] 0.7296936&#62; DEU$gini[1] 0.5088853More precisely, if 54% of French people live in 5% of the territory, only 40% of Italians, and 32% of the Germans,&#62; 1-min(FRA$LC$L[FRA$LC$p&#62;.95])[1] 0.5462632&#62; 1-min(ITA$LC$L[ITA$LC$p&#62;.95])[1] 0.3933227&#62; 1-min(DEU$LC$L[DEU$LC$p&#62;.95])[1] 0.3261124