checkranin(tlim, tt, "tlim") 错误:'tlim[1]' 必须 < 'tlim[2]'

问题描述

所以我目前正在尝试执行一个时空核密度函数,我可以看到核密度分布随时间的变化。这是使用 sparr 包尝试的。我正在运行以下代码


smell_Cases <- subset(newdata_proj,smell == '1',select=c(x,y,smell))

smell_controls <- subset(newdata_proj,smell == '0',smell))
smell_ppp <- list()

smell_ppp$cases<-ppp((smell_Cases$x),smell_Cases$y,marks=as_vector(as.integer(smell_Cases$smell)),window=as.owin(as_Spatial(boundary)))

smell_ppp$controls<-ppp((smell_controls$x),smell_controls$y,window=as.owin(as_Spatial(boundary)))

smell_ppp_Cases <- smell_ppp$cases


hlam <- LIK.spattemp(smell_ppp_Cases)

然后得到如下错误checkranin(tlim,tt,"tlim") 中的错误:'tlim[1]' 必须是

解决方法

错误是说您提供的数据的时间窗口无效。根据 help(LIK.spattemp) 中的文档(请参阅“pp”和“tt”参数的条目),如果您不提供每次观察的时间(您在上述函数调用中未完成)该函数将尝试使用数据对象的“标记”。你的数据对象的标记是观察次数吗?无论如何,我们需要 MWE 来全力帮助您。

,

@蒂尔曼戴维斯

不是很长:

smell <- read_csv('smell_report_2020_2021.csv') %>%
  subset(.,select= c("skewed_longitude","skewed_latitude","smell_category")) %>%
  st_as_sf(.,coords=c("skewed_longitude","skewed_latitude"))

st_crs(smell) = 4326

#Transform the coordinates to U.S Atlas Equal Area(crs=2163):
newdata_proj<-st_transform(smell,crs=2272)%>%
  st_coordinates(.)%>%
  cbind(.,smell$smell_category)%>%
  as.data.frame(.)
colnames(newdata_proj)<-c("x","y","smell")


#Read the contiguous United States boundary shapefile and transform toU.S Atlas Equal Area:
boundary<-st_read("Data/Allegheny_County_Zip_Code_Boundaries.shp")

plot(boundary)

# boundary.sf <- st_transform(boundary,"+proj=utm +zone=19 +ellps=GRS80 +datum=NAD83 +units=m +no_defs")
# boundary

# Dissolve boundaries to just the outline of the county
plot(boundary$geom)
plot(st_union(boundary$geom))

boundary <- st_union(boundary$geom)
plot(boundary)


#the Spatial relative risk/density ratiofunction,which we are using here,takes a point pattern (ppp)object
#with dichotomous factor-valued marks,which distinguish cases and controls.
#Therefore,we need to wrangle our data into this format first:
pitts_ppp<-ppp(newdata_proj$x,newdata_proj$y,marks=as.factor(newdata_proj$smell),window=as.owin(as_Spatial(boundary)))


smell_Cases <- subset(newdata_proj,smell == '1',select=c(x,y,smell))

smell_controls <- subset(newdata_proj,smell == '0',smell))
smell_ppp <- list()

smell_ppp$cases<-ppp(smell_Cases$x,smell_Cases$y,marks=as_vector(as.integer(smell_Cases$smell)),window=as.owin(as_Spatial(boundary)))

smell_ppp$controls<-ppp(smell_controls$x,smell_controls$y,window=as.owin(as_Spatial(boundary)))

smell_ppp_Cases <- smell_ppp$cases


hlam <- LIK.spattemp(smell_ppp_Cases)



hlam <- LIK.spattemp(fmd_case)