I'm running a spatial model using spatstat
. Following model fitting, I would like to compare predictions at a few distances and say whether they are significantly different from each other. In the basis of the dataset, I have a bunch of points around the 0, 0 origin. Each point has x, y coordinates, distance from the origin, and cardinal angle (as north / east / west / south).
Following the setup from the answer to this question:
library(spatstat)
library(ggplot2)
# making up some data
set.seed(42)
X <- runifdisc(2000)
plot(X)
W <- Window(X)
rad <- as.im(function(x,y){sqrt(x^2+y^2)}, W)
ang <- as.im(atan2, W)
plot(solist(rad, ang), main = "")
# assigning directions
north <- ang < 45/180*pi & ang > -45/180*pi
east <- ang > 45/180*pi & ang < 135/180*pi
west <- ang < -45/180*pi & ang > -135/180*pi
south <- ang < -135/180*pi | ang > 135/180*pi
# create and run a model
lam <- 2000*exp(-2*rad - rad*north - 3*rad*west)
set.seed(42)
X2 <- rpoispp(lam)[W]
mod2 <- ppm(X2 ~ rad*west + rad*south +rad*east)
plot(predict(mod2))
plot(X2, add = TRUE, col = rgb(.9,.9,.9,.5))
Predict on a grid for north and west points.
preds1 <- data.frame(Angle = "North", x = 0, y = seq(0.1, 1, 0.1))
preds2 <- data.frame(Angle = "West", y = 0, x = seq(-1, -0.1, 0.1))
preds <- rbind(preds1, preds2)
preds$Pred <- predict(mod2, locations = preds)
temp <- predict(mod2, locations = preds, interval = "confidence")
preds$Lower <- temp[1:nrow(preds)]
preds$Upper <- temp[(nrow(preds) + 1) : length(temp)]
preds$Distance <- ifelse(preds$x == 0, abs(preds$y), abs(preds$x))
ggplot(preds) +
geom_ribbon(aes(x = Distance, ymin = Lower, ymax = Upper, group = Angle), alpha = 0.1) +
geom_line(aes(x = Distance, y = Pred, colour = Angle), size = 0.75)
As the next step, I want to be able to say that north and west values are significantly different at distances x, y, z but not a, b, c... How do I get there?