[R-sig-Geo] Spatial Autocorrelation

Danlin Yu yud at mail.montclair.edu
Tue Jun 3 15:42:03 CEST 2008


Jennifer:

To calculate the moran's Index, you need a spatial weight linkage object 
(in SPDEP language, a listw object). The listw object can be obtained 
from the set of coordinates you have. I'll show how I did it from the 
set of information you provide:

I copy&paste your information into a ".csv" file, say "samples.csv". 
Here are the commands in R:

#load SPDEP:

library(spdep)

#change the current folder to where your ".csv" file is, then read it 
using read.csv() function into a list object called test:

test<-read.csv("samples.csv")

#combine the first two columns to be coordinates:

coords<-cbind(test$loc_x,test$loc_y)

#create a neighborhood list object (in SPDEP, an "nb" object)
#since they are points object, you have two choices determining the 
neighbor list, one is dnearneigh(), which uses lower and upper distance 
bound to determine
#neighborhood, another is knearneigh(), which uses the number of nearest 
neighbors to determine the neighborhood. You can use ?dnearneigh or 
?knearneigh to find out more
#for illustration purpose, I am using the knearneigh() function here, 
and assume 4 nearest neighbors as every point's neighborhood:

test.nb<-knn2nb(knearneigh(coords,k=4))

#create the listw object:

test.listw<-nb2listw(test.nb)

#now since you have the listw object (test.listw), you can calculate the 
Moran's Index for the variable you are interested, let's assume it is 
descham_sp:

descham_sp<-test$descham_sp
descham_sp.moran<-moran(descham_sp,test.listw,length(descham_sp),Szero(test.listw))

#you can test whether or not the calcuated Moran's Index is 
statistically significantly using either randomization or saddlepoint 
approximation:

#randomization:

moran.test(descham_sp,test.listw)

#saddlepoint approximation:

lm.morantest.sad(lm(descham_sp~1),test.listw)


The relevant reference can be found by using ? plus relevant function names.

Hope this helps.

Cheers,
Danlin

Jennifer Argent wrote:
> Hi,
> &nbsp;
> I want to test for spatial autocorrelation of vegetation cover in fixed plots across a site. I thought that using Moran's I in spdep would be suitable but as I am fairly new to R I am quite confused by the script and how I should set out my data.
> &nbsp;
> My data is in the following format (an extract only)&nbsp;with location in an x,y&nbsp;columns followed by the variables concerning vegetation&nbsp;in percentage cover
> &nbsp;
>
>
>
>
>
>
> loc_x
> loc_y
> &nbsp;festuca_sp
> lolium_sp
> agrostis_sp
> descham_sp
> calluna_vulg
> perc_cov
>
> 409471
> 397133
> 6
> 0
> 0
> 0
> 100
> 98
>
> 409475
> 397141
> 0
> 0
> 0
> 12
> 65
> 95
>
> 409511
> 397279
> 0
> 0
> 1
> 85
> 30
> 98
>
> 409513
> 397284
> 0
> 0
> 1
> 40
> 0
> 99
>
> 409511
> 397276
> 0
> 0
> 1
> 30
> 0
> 90
>
> 409498
> 397073
> 0
> 0
> 1
> 30
> 60
> 98
>
> 409509
> 397076
> 0
> 0
> 0
> 4
> 60
> 99
>
> 409508
> 397060
> 8
> 0
> 0
> 0
> 60
> 100
>
> 409598
> 397107
> 15
> 0
> 1
> 45
> 0
> 90
>
> 409595
> 397109
> 1
> 0
> 1
> 44
> 0
> 98
>
> 409589
> 397121
> 5
> 0
> 1
> 60
> 0
> 95
> &nbsp;
> I would really appreciate advice on this as I am still finding my feet with R. I am using R in windows xp.
> &nbsp;
> Kind regards
> Jen
>
>
>
>
>
>       __________________________________________________________
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>   

-- 
___________________________________________
Danlin Yu, Ph.D.
Assistant Professor
Department of Earth & Environmental Studies
Montclair State University
Montclair, NJ, 07043
Tel: 973-655-4313
Fax: 973-655-4072
email: yud at mail.montclair.edu
webpage: csam.montclair.edu/~yu




More information about the R-sig-Geo mailing list