简体   繁体   English

Spatstat 中的点模式分析

[英]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.

相关问题 带R的spatstat:定义空间点模式窗口时出错 - spatstat wiht R: Error with defining the window of spatial point pattern 使用 spatstat 进行点模式分类:我做错了什么? - Point pattern classification with spatstat: what am I doing wrong? 是否可以在 Rstudio 中使用 SpatStat 向 3D 点模式添加标记? - Is it possible to add marks to a 3D point pattern using SpatStat in Rstudio? 如何使用 spatstat 检查线性网络上点模式的过度拟合 - how check overfitting on point pattern on a linear network using spatstat spatstat从点模式中删除标记,然后删除这些点 - spatstat deleting marks from a point pattern and subseuently the points 使用 spatstat 进行点模式分类:如何选择合适的带宽? - Point pattern classification with spatstat: how to choose the right bandwidth? 如何使用 R 中的 spatstat 在点模式 (ppp) 中将物种绘制为不同的颜色? - How do I plot species as different colours in a point pattern (ppp) using spatstat in R? Spatstat:根据Quadrat计数测试,尽管点模式不一致,但Lcross仍会导致奇怪的情节 - Spatstat: Inhomogeneous Lcross leads to strange plot, despite inhomogeneous point pattern according to quadrat count tests 在spatstat中使用“包络”功能对空间点模式超帧进行基于仿真的假设检验 - Simulation-based hypothesis testing on spatial point pattern hyperframes using “envelope” function in spatstat R:spatstat:Thomas集群过程的残差分析 - R: spatstat: Residual analysis for Thomas cluster processes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM