【发布时间】:2021-09-24 12:04:56
【问题描述】:
我当前工作的目标是汇总一个包含 n 个变量的数据库: (1) 位置的纬度,(2) 位置的经度,(3...n-1) 协变量,(n) 地层。 在层变量中,我正在寻找每个点来自的隔间的数量。 但我正在努力获得地层。 我创建了两个栅格 R1 和 R2。
#'Creating the window of domaine D
D <- c(300, 300) # Square Domaine D of side 300
Win <- owin(xrange =c(0, D[1]), yrange =c(0,D[2]))
spatstat.options(npixel=c(D[1],D[2]))
# Creating Rasters
library(raster)
# First raster
ext <- extent(Win$xrange, Win$yrange)
v1 <- rnorm(n=seq(from = -10, to=50,length.out = 100), mean = 0, sd=1)
R1 <- raster(matrix(v1,byrow=T,nrow=10, ncol=10))
extent(R1) <- ext
crs(R1) <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84"
names(R1) <- 'temp sim'
R1
# Second Raster
v2 <- rnorm(n=seq(from = 100, to=2000,length.out = 100), mean = 0, sd=1)
R2 <- raster(matrix(v1,byrow=T,nrow=10, ncol=10))
extent(R2) <- ext
crs(R2) <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84"
names(R2) <- 'precip sim'
R2
# Raster List
Rasters.group <- stack(R1, R2)
完成之后,我将栅格转换为 .im 对象
#' Creating .im objects based on the previous rasters.
#' Each .im object will represent an environmental condition
library(maptools)
IM1 <- as.im.RasterLayer(R1)
IM1 <- as.im.RasterLayer(R2)
#We can plot them as well
library(fields)
par(mfrow=c(2,2))
image.plot(list(x=IM1$xcol, y=IM1$yrow, z=IM1$v), main= "temp sim", asp=1)
image.plot(list(x=IM2$xcol, y=IM2$yrow, z=IM2$v), main= "precip sim", asp=1)
现在我已经组合了 .im 对象,以便从中生成空间点。
# Combination of invironments
Com <- IM1 + IM1
image.plot(list(x=Com$xcol, y=Com$yrow, z=Com$v), main= "Global env", asp=1, col=c("green", "red", "blue", "yellow", "White", "Black"))
# Generating points Log - Gaussian Cox process
lgc.process <- rLGCP('matern', mu=Com, var=0.5, scale=0.05, nu=1)
lgc.process
xycoor <- cbind(lgc.process$x, lgc.process$y)
lgc.data <- cbind(xycoor, extract(Rasters.group, xycoor))
结果如下:
> head(lgc.data)
temp.sim precip.sim
[1,] 194.13086 169.76961 1.82615774 1.82615774
[2,] 31.07026 271.56473 0.09453324 0.09453324
[3,] 109.21386 232.53282 2.30704591 2.30704591
[4,] 27.16373 121.88652 0.83505001 0.83505001
[5,] 97.95982 105.71822 1.85318918 1.85318918
[6,] 167.63728 61.16835 1.14231913 1.14231913
现在它仍然是我希望看到每个点来自哪个兼容性(层)的最后一列。我至少需要10层。
我尝试过的所有东西都不会引导我找到我正在寻找的东西。我使用了split 函数,但没有得到结果。
我该怎么办?
【问题讨论】:
-
我不确定我是否了解这些地层的来源。您是否将 300x300 窗口细分为更小的区域,并且您想知道每个点来自哪个更小的区域?
-
是的,这就是我想做的。请帮忙
-
先生。 Ege Ruban,您的评论帮助我发现了您的一本令人惊叹的书:空间点模式:R 的方法和应用。希望这本书能教给我很多关于空间点模式的知识。