You are on page 1of 17

Spatial Analysis Autocorrelation Gianni Gorgoglione

1

Spatial Autocorrelation and Geostatistics in R
Work axample in R
Part I

1. library(gstat)
data(meuse.all)

2. variables: 17
Rows: 164

Variable Level of measurement
sample Ordinal
x Ordinal
y Ordinal
cadmium ratio
copper ratio
lead ratio
zinc ratio
elev ratio
dist.m Ratio
om Ratio
ffreq ratio
soil ratio
lime Ordinal
landuse nominal
in.pit nominal
in.meuse155 nominal
in.BMcD nominal

3. Unit: ppm
4. sort(meuse.all$copper)
[1] 14 16 17 18 18 18 18 19 19 20 20 20 20 20 20 20 20 20 20 21 21 21 21 21 21 21 21
21 22 22 22 22 22 22 22 22 22
[38] 22 23 23 23 23 23 23 23 23 23 24 24 24 24 24 24 24 24 24 25 25 25 25 25 25 26 26
26 26 26 26 27 27 27 27 27 27
Spatial Analysis Autocorrelation Gianni Gorgoglione


2

[75] 27 27 27 29 29 29 29 29 30 30 31 31 31 31 31 32 32 32 32 33 33 34 34 34 35 35 35
36 36 36 36 37 37 38 38 38 39
[112] 39 39 41 42 45 46 46 47 47 47 47 48 48 49 50 50 51 53 53 55 55 61 63 65 66 67 68
68 69 69 72 74 75 75 76 76 77
[149] 77 78 80 81 81 85 85 86 88 90 93 95 104 108 117 128

5. zincsum <- unclass(meuse.all$zinc)
summary(zincsum)
Min. 1st Qu. Median Mean 3rd Qu. Max.
107.0 191.8 307.5 464.6 662.5 1839.0

Median is 307.5 and it is the number in the middle between the highest and the lowest value of
zinc concentrations.
Mean is equal to 464.6 and tell us about the average value among all concentrations of zinc.
It is possible to suggest a description of the zinc dataset distribution. The mean gives you an idea
of how close the data points are. The median describes a range of the data so that it is possible
to organize data maybe in 2 bins. Besides, the higher value of the mean can suggest that the
dataset has higher values than the median number.
6. Hist(zincsum)
hist(zincsum, breaks = 18, freq=T,include.lowest = TRUE, right =
TRUE,density = NULL, angle = 45, col = ("blue"),main="Zinc")
Spatial Analysis Autocorrelation Gianni Gorgoglione


3

ZincLog10
meuse.all$zinc.1
F
r
e
q
u
e
n
c
y
2.0 2.5 3.0 3.5
0
5
1
0
1
5
2
0

The are values between 100 and 300 with a frequency with a range between 0-50, values
between 300 and 800 with a frequency below 20. The rest of values have a frequency below 5.


7. meuse.all$zinc.1<- log10(zincsum)
meuse.all$zinc.1
8. summary(meuse.all$zinc.1)
Min. 1st Qu. Median Mean 3rd Qu. Max.
2.029 2.283 2.488 2.546 2.821 3.265

Now it is possible to distinguish a uniform data distribution below a frequency of 10. It looks
that the sample comes from 1 population. However , there is some data with extreme high
values that can make assume the presence of another kind of population.






Zinc
zincsum
F
r
e
q
u
e
n
c
y
500 1000 1500
0
1
0
2
0
3
0
4
0
5
0
Spatial Analysis Autocorrelation Gianni Gorgoglione


4
























9. cadmium<- log10(cadmium)
lead<- log10(lead)
copper<- log10(copper)
meuse.all$lead.1<- lead
meuse.all$copper.1<- copper
meuse.all$cadmium.1<- cadmium
str(meuse.all)
the structure of meuse.all has more variables.
10.


Spatial Analysis Autocorrelation Gianni Gorgoglione


5


It looks that exists an autocorrelation between the zinc and copper distribution. The spatial
location of the two metals looks to coexist. There are some outliers but it is not significant since
it is not a large quantity.



11.

pairs(meuse.all[18:21])

Spatial Analysis Autocorrelation Gianni Gorgoglione


6






















From the plotted array it seems existing a relationship between all the four metals. The spatial
distribution is concentrated on a way. We can conclude that the metals have a strong relationship with
each other. In other words, the values of all the metal pairs lie over a distinct location giving origin to a
shape. That means that similar values are closer than other for the two compared metals.
Spatial Analysis Autocorrelation Gianni Gorgoglione


7

Part II

1.
require('sp')
coordinates(meuse.all)<-c('x','y')

The column of x and y changed to a object called coordinates.
2.
data(meuse.riv)
plot(meuse.all)
lines(meuse.riv)


The pattern looks random at the first look. The distribution of the sample does not look have a clustered
or regular pattern.


3.

plot(meuse.all,asp=1,cex=4*meuse.all$zinc.1/max(meuse.all$zinc.1),pch=1)
Spatial Analysis Autocorrelation Gianni Gorgoglione


8




CEX: The cex parameter of the plot function gives a scale to the symbol of the variable, thus in our case
this parameter has been set as 4.
ASP: When asp is set equal to 1 the distances between points are represented with more
accuracy on the screen.
MAX: Returns the (parallel) maxima and minima of the input values


According to the Toblers law,
variables closer to each other
share similar values. Thus, we
can see that along the river
the values are more similar
and we can suppose that the
concentration of zinc along
the river have same values as
well.

Spatial Analysis Autocorrelation Gianni Gorgoglione


9

4.
hscat(meuse.all$zinc.1~1,meuse.all,(0:15)*100)


Parameters description for function hscat:
Width: the width of subsequent distance intervals into which data point pairs are grouped for
semivariance estimates (0:15)*100
Cloud: the area of semi-variogram (range)
Data: dataframe where the data are taken


By observing the scatter plot of the variable meuse.all$zinc.1 it is possible to notice a
stronger autocorrelation at low lags with few values. The greater distances are, the
more the number of values are. On the other hand, there are more values where there
is a weak correlation with a ratio near to 0. That does not confirm the strong correlation
for the zinc concentration but rather a weak one.
However, in the end, we can conclude that at bigger distances between the points, the
difference between the values is more consistent.

Spatial Analysis Autocorrelation Gianni Gorgoglione


10



5.
Meuse.all$zinc.1 ~ 1 means that the variable zinc.1data has been assigned as
constant trend to the variogram
NP: number of point pairs
DIST: average distance of all point pairs
GAMMA: actual sample variogram

Tab.1 Variogram(meuse.all$zinc.1~1, meuse.all)
LAG NP DIST GAMMA
1 60 80.0948 0.03541949
2 336 164.1146 0.05150425
3 461 267.7307 0.06566955
4 529 372.8053 0.08631192
5 623 478.5473 0.09213795
6 631 585.6598 0.11049674
7 664 692.5486 0.10870265
8 660 795.9618 0.11668905
9 677 902.8950 0.12288617
10 625 1011.8034 0.12622050
11 567 1117.9600 0.13561422
12 542 1221.2978 0.11675121
13 518 1328.9376 0.12833136
14 514 1436.9733 0.11375821
15 462 1542.2698 0.11416743

v<-variogram(meuse.all$zinc.1~1, meuse.all)
v.fit = fit.variogram(v, model = vgm(1, "Sph", 700, 1))
> plot(v,v.fit)









distance
s
e
m
i
v
a
r
i
a
n
c
e
0.05
0.10
500 1000 1500
Spatial Analysis Autocorrelation Gianni Gorgoglione


11



These values for the second Lag are:
np DIST gamma
336 164.1146 0.05150425



6.
v<-variogram(meuse.all$zinc.1~1, meuse.all)
plot(v,v.fit)




6.a The low nugget and the fact of the presence of a range give to us the evidence of
a spatial dependence
6.b In this case the spatial dependence is lost at ca. 900.
6.c The spatial dependence is 0 at ca. 0.025 semivariance
6.d A semivariance should be positive and not equal to 0.
distance
s
e
m
i
v
a
r
i
a
n
c
e
0.05
0.10
500 1000 1500
Spatial Analysis Autocorrelation Gianni Gorgoglione


12

6.e The average maximum semivariance is point where there not any possible
correlation. The comparison between objects start from lag 1 to n lags until it
reaches the maximum spatial dataset sample. This point is called sill.
7.
zinc.dir<- variogram(meuse.all$zinc.1~1, meuse.all,alpha= c(0,
45, 90, 135))
zinc.dir.fit = vgm(1, "Sph", 900, 1)
plot(zinc.dir,zinc.dir.fit)

From the above Anisotropy variograms it is possible to see that there is more
continuity for the direction with 45 degree.
A variogram that changes according to the direction is called ANISOTROPY


distance
s
e
m
i
v
a
r
i
a
n
c
e
0.05
0.10
0.15
0.20
500 1000 1500
0 45
90
500 1000 1500
0.05
0.10
0.15
0.20
135
Spatial Analysis Autocorrelation Gianni Gorgoglione


13





Part III


1. show.vgms()





2.
distance
s
e
m
i
v
a
r
i
a
n
c
e
0
1
2
3
vgm(1,"Nug",0)
0.0 1.0 2.0 3.0
vgm(1,"Exp",1)vgm(1,"Sph",1)
0.0 1.0 2.0 3.0
vgm(1,"Gau",1)vgm(1,"Exc",1)
vgm(1,"Mat",1)vgm(1,"Ste",1) vgm(1,"Cir",1) vgm(1,"Lin",0)
0
1
2
3
vgm(1,"Bes",1)
0
1
2
3
vgm(1,"Pen",1)vgm(1,"Per",1)vgm(1,"Wav",1)vgm(1,"Hol",1)vgm(1,"Log",1)
0.0 1.0 2.0 3.0
vgm(1,"Pow",1)
0
1
2
3
vgm(1,"Spl",1)
Spatial Analysis Autocorrelation Gianni Gorgoglione


14

vgm(1, Sph, 300, 0.5)

vm = fit.variogram(v, model = vgm(1, "Sph", 700, 1))
3.
plot(v, model = vm)



4.
data(meuse.grid)

5.
## CHANGE dataset frame object AS spatial object
coordinates(meuse.grid) <- c("x","y")
## TRANSFORM point data Frame TO pixel data frame object
meuse.grid<-as(meuse.grid,"SpatialPixelsDataFrame")
distance
s
e
m
i
v
a
r
i
a
n
c
e
0.05
0.10
500 1000 1500
Spatial Analysis Autocorrelation Gianni Gorgoglione


15

OK prediction, log-ppm Zn
2.2
2.4
2.6
2.8
3.0
3.2
## What is the spatial resolution of the data set?
str(meuse.grid)
cellsize : Named num [1:2] 40 40
6.
OK<-krige(meuse.all$zinc.1 ~ 1, locations = meuse.all,
newdata=meuse.grid, model=vm)
Krige(
the dependent variable using ~ 1, meuse.all$zinc.1 ~ 1
spatial data locations (coordinates) of the object, locations = meuse.all
the dependent variable as data frame, newdata=meuse.grid
variogram model of dependent variable model=vm
)
7.
spplot(OK, "var1.pred", asp=1, col.regions=bpy.colors(64),main="OK
prediction, log-ppm Zn")











Spatial Analysis Autocorrelation Gianni Gorgoglione


16

OK
predictionvariance, log-ppm Zn^2
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.10





The prediction of high concentration of zinc follows the preview pattern analysis, i.e. the
high values of zinc are located along the river. The higher the distance from the river, the lower
the predicted values of zinc concentration.
















Spatial Analysis Autocorrelation Gianni Gorgoglione


17

The prediction of variance in the figure above shows how zinc concentration values are
dispersed from the predicted values. The lower prediction variance is depicted in that picture
with cooler color as light blue far from the river side except for where the river changes course.

You might also like