@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)