我正在使用spatstat
运行空间模型。在进行模型拟合之后,我想比较一些距离的预测,并说一下它们是否彼此之间存在显着差异。在数据集的基础上,我在0、0的原点周围有一堆点。每个点都有x,y坐标,到原点的距离和基角(北/东/西/南)。
按照答案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))
在一个用于北点和西点的网格上进行预测。
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)
下一步,我想说的是,北和西值在距离x,y,z处有显着差异,但在a,b,c处没有显着差异...我如何到达那里?