简体   繁体   English

空间相关图

[英]Spatial correlogram

I am trying to run a spatial auto correlogram for a project looking at deforestation in the Atlantic forest, Brazil. 我正在为一个研究巴西大西洋森林中的森林砍伐的项目运行空间自动相关图。

I am however confused as to why I am hitting this problem. 但是,我对为什么遇到这个问题感到困惑。

Problem 问题

When I run the initial part of my code i receive an error of 当我运行代码的初始部分时,出现错误

Error: ncol(x) == 2 is not TRUE 错误:ncol(x)== 2不是TRUE

My code is 我的代码是

r.nb <- dnearneigh(as.matrix(shapeS$POINT_X,shapeS$POINT_Y),
                   d1=200, d2=100000, latlong=FALSE)

and then I hope to move run this code 然后我希望继续运行此代码

p.cor <- sp.correlogram(r.nb, deforestation, order=15,
                        method="I", randomisation=FALSE)

r.nb <- dnearneigh(as.matrix(shapeS$POINT_X,shapeS$POINT_Y), 
                   d1=200, d2=100000, latlong=FALSE)

My data is 我的数据是

A vector data set with the headings 具有标题的矢量数据集

POINTID GRID_CODE POINT_X POINT_Y

You need to use cbind , not as.matrix , or the approach that I show below. 您需要使用cbind ,不as.matrix ,或者说,我下面展示的方法。 Always identify the R packages you are using. 始终标识您正在使用的R软件包。 You claim that your data set a 'vector data set'. 您声称您的数据集是“向量数据集”。 I doubt that. 我不信。 I am assuming it is a matrix. 我假设它是一个矩阵。

If it is a matrix, you can do 如果是矩阵,则可以

m <- shapeS[, c('POINT_X', 'POINT_Y')]
library(spdep)
r.nb <- dnearneigh(m, d1=200, d2=100000, latlong=FALSE)

It it is a data.frame, you can do 它是一个data.frame,你可以做

m <- as.matrix(shapeS[, c('POINT_X', 'POINT_Y')])

or 要么

m <- cbind(shapeS$POINT_X, shapeS$POINT_Y)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM