[英]point pattern analysis in Spatstat
I am quite new to R and am having some trouble setting up my data for some point pattern analysis.我对 R 很陌生,并且在为某些点模式分析设置数据时遇到了一些麻烦。
What I want to do: conduct a point pattern analysis on NYC arrest data and see if there exists a spatial dependence between arrests and Covid-19 cases.我想做的是:对纽约市逮捕数据进行点模式分析,看看逮捕和 Covid-19 案件之间是否存在空间依赖性。
What I've done so far: downloaded data in the form of shapefiles到目前为止我所做的:以 shapefile 的形式下载数据
https://data.cityofnewyork.us/City-Government/Borough-Boundaries/tqmj-j8zm (the ZIP code boundaries) https://data.cityofnewyork.us/City-Government/Borough-Boundaries/tqmj-j8zm (ZIP 代码边界)
https://www1.nyc.gov/site/nypd/stats/crime-statistics/citywide-crime-stats.page (year to date data for arrests in NYC by zip code) https://www1.nyc.gov/site/nypd/stats/crime-statistics/citywide-crime-stats.page (zip 代码在纽约市逮捕的年初至今数据)
Code:代码:
library(readxl)
library(rgdal) #Brings Spatial Data in R
library(spatstat) # Spatial Statistics
library(lattice) #Graphing
library(maptools)
library(raster)
library(ggplot2)
library(RColorBrewer)
library(broom)
# Load nyc zip code boundary polygon shapefile
s <- readOGR("/Users/my_name/Documents/fproject/zip","zip")
nyc <- as(s,"owin")
### OGR data source with driver: ESRI Shapefile
Source: "/Users/my_name/Documents/project/zip", layer: "zip"
with 263 features
# Load nyc arrests point feature shapefile
> s <- readOGR("/Users/my_name/Documents/project/nycarrests/","geo1")
### OGR data source with driver: ESRI Shapefile
Source: "/Users/my_name/Documents/project/nycarrests", layer: "geo1"
with 103376 features
It has 19 fields
#Converting the dataset into a point pattern
arrests <- as(s,"ppp”)
### Error in as.ppp.SpatialPointsDataFrame(from) :
Only projected coordinates may be converted to spatstat class objects
This gave me the error above.这给了我上面的错误。
I know the error has to do with the coordinates not being in the cartesian coordinates.我知道错误与坐标不在笛卡尔坐标中有关。 So my question is:
所以我的问题是:
How can I convert my sp object to have (projected) cartesian coordinates in order to convert it to a point pattern (poisson point process)?如何将我的 sp object 转换为具有(投影)笛卡尔坐标以便将其转换为点模式(泊松点过程)?
Any help would be greatly appreciated任何帮助将不胜感激
You are looking for spTransform
.您正在寻找
spTransform
。
When asking an R question, please include some example data like this当问一个 R 问题时,请包括一些这样的示例数据
library(raster)
filename <- system.file("external/lux.shp", package="raster")
p <- shapefile(filename)
Solution解决方案
utm <- "+proj=utm +zone=32 +datum=WGS84"
x <- spTransform(p, utm)
x
#class : SpatialPolygonsDataFrame
#features : 12
#extent : 266045.9, 322163.8, 5481445, 5563062 (xmin, xmax, ymin, ymax)
#crs : +proj=utm +zone=32 +datum=WGS84 +units=m +no_defs
#variables : 5
#names : ID_1, NAME_1, ID_2, NAME_2, AREA
#min values : 1, Diekirch, 1, Capellen, 76
#max values : 3, Luxembourg, 12, Wiltz, 312
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.