geoxp: an r package for exploratory spatial data analysis ... · geoxp: an r package for...

29
GeoXp: an R package for exploratory spatial Data analysis GeoXp: an R package for exploratory spatial Data analysis Spatial Econometric Association Conference - Toulouse 2011 Thibault LAURENT, Anne RUIZ-GAZEN and Christine THOMAS-AGNAN GREMAQ, Toulouse School of Economics 7 juillet 2011 T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Upload: others

Post on 06-Aug-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

GeoXp: an R package for exploratory spatial Dataanalysis

Spatial Econometric Association Conference - Toulouse 2011

Thibault LAURENT, Anne RUIZ-GAZEN and ChristineTHOMAS-AGNAN

GREMAQ, Toulouse School of Economics

7 juillet 2011

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 2: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

1 Introduction

2 Spatial statistics with R

3 GeoXp : Interactivity between statistic plots with maps

4 An application on real data

5 Innovations of GeoXp

6 Perspectives

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 3: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Introduction

Data Set

A data set of n observations and p variables (discrete, continuous) :

VariablesIndividuals 1 . . . p

1 x11 . . . x1p2 x21 . . . x2p...

... . . ....

n xn1 . . . xnp

Each observation is associated to a a spatial object (a point, a lineor a polygon).

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 4: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Introduction

Definition and objectives of Spatial Exploratory DataAnalysis (SEDA)

Definition : combine information given by techniques of EDAwith spatial information using mapping, interactivity betweenstatistical plots with maps or by creating new methods usingfor example neighborhood matrices.

Objectives : give qualitative response to the usual problems ofspatial analysis like detection of spatial autocorrelation,detection of local or global extreme values, detection ofspatial heterogeneity...

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 5: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Introduction

SEDA softwares

Because GIS do not take into account enough statisticalmethodology, researchers in spatial statistics have developedsoftwares which take into account this methodology :

GeoDa (L. Anselin, https://www.geoda.uiuc.edu/)

Spatial Econometric Toolbox on Matlab (K. Pace - J. LeSage,http://www.spatial-econometrics.com/)

Many R packages (R. Bivand maintains the spatial Task Viewshttp://cran.r-project.org/web/views/Spatial.html -see also the R Wikihttp://wiki.r-project.org/rwiki/doku.php?id=tips:

spatial-data).

Spatial Econometric with Gauss

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 6: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Spatial statistics with R

1 Introduction

2 Spatial statistics with R

3 GeoXp : Interactivity between statistic plots with maps

4 An application on real data

5 Innovations of GeoXp

6 Perspectives

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 7: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Spatial statistics with R

Spatial statistic with R

R, GNU projet http://cran.r-project.org/

R. Bivand, E. Pebezma, V. Gomez-Rubio (2008), AppliedSpatial Data Analysis with R, Springer-Verlag.

R Spatial task viewhttp://cran.r-project.org/web/views/Spatial.html

Main packages for mapping : rgdal and maptools(import/export of spatial files, convert CRS/projection, etc),sp (definition of the Spatial classes and methods) and raster(for images).

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 8: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Spatial statistics with R

Mapping with R

1 import the spatial file (.shp, .MIF, etc) intoR (readShapeFile, etc). There exists four main kind ofsptatial objects : points, polygons, lines, pixels.

2 eventually, change the CRS/projection

3 use the functions plot, points, legend, etc. for mapping.

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 9: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Spatial statistics with R

Mapping with R : example

library(sp)

library(maptools)

xx = readShape-

Poly("NY8_utm18.shp",IDvar="AREAKEY",

CRS("+proj=utm +zone=18 +datum=WGS84"))

plot(xx,main="NY data",col=’blue3’)title("N-Y Leukemia Data")

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 10: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Spatial statistics with R

Representation of SpatialPointsDataFrame andSpatialPolygonDataFrame objects

Soil Sample near the Meuse river

●● ●

●●

●●●

●●

●●

●●●●●●

●●●●●●

●●

●●

●●

●●

●●

●●

●●●

●●●●●

●●

●●

●●

● ●●

●●

●●●

●●

●●

●●

● ●

●●●

● ●●

●●

●●●

●●

●●●

Type of soil

123

0 1000 m

E

N

W

S

Core−periphery dummy

01

Core−periphery / Income in Columbus OH

●●

●●

●●

● ●●●●●

●● ●

●●

●●

●●● ● ●

●●●●● ●●

● ●● ● ●

● ● ●●

● ●●●

●●

●●●●

Income

2.13.23.74.35.6

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 11: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Spatial statistics with R

Representation of raster and PolyLines object

178000 179000 180000 181000 182000

3300

0033

1000

3320

0033

3000

3340

00

500

1000

1500

−127.5 −127 −126.5 −126

48.5

4949

.5

Longitude (°)

Latit

ude

(°)

500−800 m800−1200 m

1200−1600 m

LTS Survey Tracks

VancouverIsland

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 12: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Spatial statistics with R

Some advices

Which projection system ? Which reference system (veryimportant to give units to the distances) ?

Choice of palettes is important (see RColorBrewer package).

How find class intervals for continuous numerical variables :classInt package (“equal interval”,“quantile”,“K-means”, etc).

Interpolation can be useful to have a global view of spatialdistribution (variables, residuals, coefficients of GWR model,etc), see package akima.

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 13: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Interactivity

1 Introduction

2 Spatial statistics with R

3 GeoXp : Interactivity between statistic plots with maps

4 An application on real data

5 Innovations of GeoXp

6 Perspectives

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 14: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Interactivity

Package GeoXp

Package GeoXp : interactive spatial exploratory data analysis

may be download on http://cran.r-project.org.

a vignette : vignette("presentation_geoxp").

use the sp norm as defined by R. Bivand et al.

T. Laurent, A. Ruiz-Gazen et C. Thomas-Agnan(Forthcoming), “GeoXp : an R package for ExploratorySpatial Data Analysis”, JSS.

GeoXp, also available on Matlab

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 15: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Interactivity

Use of GeoXp

Arguments of a GeoXp function xxxmap (ex : histomap, barmap,densitymap, etc) :

a spatial object of class SpatialxxxDataFrame

the name of the studied variable(s) (univariate or multivariateanalysis)

options (colors, legend, etc.)

3 main kind of functions :

univariate analysis : histomap(columbus,"CRIME")

bivariate analysis :polyboxplotmap(columbus,c("CRIME","CP"))

spatial econometric function - spatial weight matrix(moranplotmap, neighbourmap, etc.)

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 16: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Interactivity

GeoXp visual

A Tcl/Tk window, a map and a graphic

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 17: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Application

1 Introduction

2 Spatial statistics with R

3 GeoXp : Interactivity between statistic plots with maps

4 An application on real data

5 Innovations of GeoXp

6 Perspectives

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 18: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Application

Lorenz curve

data(mp.school)

coordinates(mp.school)<-cbind("longitude","latitude")ginimap(mp.school,"Nb.students")

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 19: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Application

Variogramme

variocloudmap(mp.school,"Nb.students.per.class")

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 20: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Application

Moran scatterplot of the number of students per class

coords <- coordinates(mp.school)

col.knn <- knn2nb(knearneigh(coords, k=4))moranplotmap(mp.school,"Nb.students.per.class",nb2listw(col.knn))

0 1

rurality.index

020

4060

80

18 20 22 24 26 28

20

21

22

23

2

4

2

5

2

6

2

7

Number of students per class

Wx(

Num

ber

of s

tude

nts

per c

lass

)

●●

●●

●●

●●

●●

●●

●●

●●

●●

●●

●●

● ●

● ●

●●

●●

●●

● ●

● ●

●●

● ●

●●

●●

FOIX

RODEZ

TOULOUSEAUCH

TARBES

ALBIMONTAUBAN

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 21: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Application

Drift map for the number of students per class

driftmap(mp.school,"Nb.students.per.class")

400000 500000 600000

1750

000

1850

000

1950

000

Number of students per class

●●

●●

●●

●●

●●

● ●

●●

●●●●

●●●●●●●●●● ●●

●●

●●●●

●●● ●●

●●●●●●

●●

●●

●●

●●

●●

●●

●●

●●

●●

●●

● ●

●●

●●

●●

●●

●●●

●●

●●

●●

●●

●●

●●

●●

●●

● ●

●●

●●

18 20 22 24 26 28

var.snv

lat

●●

● ●

●●

●●

●●

●●

●●

●● ●●

● ●● ●●● ●●●●●●

●●

●●

● ●●●● ●●

●● ●● ● ●

●●

●●

●●●

●●

● ●

●●

●●

●●

●●

●●

● ●

●●

●●

● ●

●●

● ●●

● ●

●●

●●

● ●

● ●

● ●

●●

●●

●●

●●

●●●

1820

2224

2628

●●

● ●●

●●

●●

●●

●●●

●●

●●

●●

● ●

●●

●●

●●

●●

●●

●●

●●

●●

●●

●●

●●

●●

●●

● ●

● ●

●●

● ● ●

−2:

2

Num

ber

of s

tude

nts

per

clas

s

Number of students per class

MeanMedian

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 22: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Innovations of GeoXp

1 Introduction

2 Spatial statistics with R

3 GeoXp : Interactivity between statistic plots with maps

4 An application on real data

5 Innovations of GeoXp

6 Perspectives

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 23: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Innovations of GeoXp

Analysis of the spatial weight matrix

example(columbus)

histnbmap(columbus, col.gal.nb, criteria=(columbus$CP==1),xlab="distance of the neighbor the farest")

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 24: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Innovations of GeoXp

Analysis of outliers

Fothcoming

Pairwise spatial distances

Pai

rwis

e M

ahal

anob

is d

ista

nces

0 1 2 3 4

510

1520

25

● ● ●●

● ●

●● ●● ●

●●

●●●

●●● ●

● ●

●●

● ● ●

● ●

●●●

●●

● ●

●●

● ●

●●

●●●

●●● ●

● ●

●●

●●

● ●●

● ●

●●●●

● ●

●●● ●

●●●●

●●

●●

● ● ●

● ●

●●

●●

●●

●●

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 25: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Conclusion and perspectives

1 Introduction

2 Spatial statistics with R

3 GeoXp : Interactivity between statistic plots with maps

4 An application on real data

5 Innovations of GeoXp

6 Perspectives

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 26: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Conclusion and perspectives

Having an interface such as GeoDa

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 27: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Conclusion and perspectives

Selecting directly the polygon such as a GIS or Arc Matlab

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 28: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Conclusion and perspectives

Manipulating directly the SGBD such as a GIS orArc Matlab

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis

Page 29: GeoXp: an R package for exploratory spatial Data analysis ... · GeoXp: an R package for exploratory spatial Data analysis 1 Introduction 2 Spatial statistics with R 3 GeoXp : Interactivity

GeoXp: an R package for exploratory spatial Data analysis

Conclusion and perspectives

Other perspectives

Zoom on the device

Add origin-destination flow graphics

Mircromaps (Carr and Pickle)

T. Laurent, A. Ruiz-Gazen and C. Thomas-Agnan GeoXp: an R package for exploratory spatial Data analysis