R language Computing Moran ' I

Source: Internet
Author: User

R language Computing Moran ' I
Install.packages ("Maptools")#A package that draws a mapInstall.packages ("SPDEP")#Spatial statistics, Moran ' IInstall.packages ("Tripack") Install.packages ("Rann") Library ("Maptools") Library ("SPDEP") Library ("Tripack") Library ("Rann")#Read spatial dataRdata <-Readshapepoly ("d:/data/cairo.shp")#reading SHP polygon DataNames (Rdata)#Show data field nameHead ([email protected])#Show property sheet#Paint by field twoSpplot (Rdata[c ("tfr96_03","tfr86_03")], main="Spatial distribute of tfr96_03",#Picture nameXlab ="X Coords",#Horizontal NameYlab ="Y Coords",#Ordinate nameCut = 30#Segmented       )#Draw by FieldSpplot (rdata["tfr96_03"], main="Spatial distribute of tfr96_03",#Picture nameXlab ="X Coords",#Horizontal NameYlab ="Y Coords",#Ordinate nameCut = 30#Segmented       )#neighbor Generation by Edge adjacency (mode one)QUEEN_NB <-poly2nb (rdata, Queen = TRUE)#There are 8 ofROOK_NB <-poly2nb (rdata, Queen = FALSE)#There are 4 of#Get center point coordinate numberCoords <-coordinates (RDATA)#map data to data frame-Generate IDIDs <-row.names (As.data.frame (rdata))#Set Drawing ParametersOopar <-par (Mfrow = C (), Mar= C (3,3,1,1) +0.1)#Draw BorderPlot (rdata, border ="Grey", main ="Queen-style")#Add to modify the previous diagramPlot (QUEEN_NB, coords, col ="DodgerBlue", add= TRUE, pch = 0.5, CeX =)#Generate adjacency Relationship (Mode II) Knearneigh () definition k-nearK4_NB<-knn2nb (Knearneigh (coords, k = 4), Row.names =IDs)

#To identify the symmetry of the adjacency relationship is. SYMMETRIC.NB (k4_nb, verbose = FALSE, force =TRUE)#complement adjacency RelationshipN.COMP.NB (K4_NB) $nc k4_w <-NB2LISTW (K4_NB)#calculate Moran ' IMoran.test (rdata$tfr96_03, LISTW =k4_w)#calculate Moran ' I (Monte Carlo method)MORAN.MC (rdata$tfr96_03, LISTW = k4_w, Nsim = 999)

 

R language Computing Moran ' I

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.