0

So I'm currently trying to perform a spatio-temporal kernel density function where I'm able to see kernel density distribution change over time. This was attempted using the sparr package. I'm running the following code:


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

smell_controls <- subset(newdata_proj, smell == '0',
                       select=c(x,y, 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)

Then get the following error: Error in checkranin(tlim, tt, "tlim") : 'tlim[1]' must be < 'tlim[2]'

markalex
  • 8,623
  • 2
  • 7
  • 32
  • Are you able to share your data? Or can you reproduce the error with a standard dataset from a package? – Ege Rubak Mar 27 '21 at 16:13
  • @EgeRubak Yeah I could share that with you. It can be found here : https://docs.google.com/spreadsheets/d/e/2PACX-1vQzIZfahDw6gCk5SKlJX-kaBAlDbjT3tlEZiqRKv7O6-wuRtYNczmKWOJEvBxEt4Dxl_b2oKpF2r9WQ/pub?output=csv – geokid_96 Apr 02 '21 at 01:58

2 Answers2

1

The error is saying the temporal window of the data you've supplied is invalid. As per the documentation at help(LIK.spattemp) (see the entries for the 'pp' and 'tt' arguments), if you do not supply the times of each observation (which you haven't done in the above function call) the function will attempt to use the 'marks' of your data object. Are the marks of your data object the observation times? At any rate, we need a MWE to help you fully.

  • The dataset can be found here: https://docs.google.com/spreadsheets/d/e/2PACX-1vQzIZfahDw6gCk5SKlJX-kaBAlDbjT3tlEZiqRKv7O6-wuRtYNczmKWOJEvBxEt4Dxl_b2oKpF2r9WQ/pub?output=csv – geokid_96 Apr 13 '21 at 01:39
0

@Tilman Davies

It is not very long:

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',
                       select=c(x,y, 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)