1-dimensional Point-Process in R (spatstat)

拈花ヽ惹草 提交于 2021-02-18 19:33:32

问题


I have asked another question, which was closed as Too Broad. Now, I will try to specify.

Again, I would like to simulate a 1-dimensional point process in R. So far, I've only been working on 2-dimensional simulations and would need a bit of help.

My goal is a simulation like in the picture

picture

But, I only need the real line with the random points on it.

I use spatstat and have already found out that I can generate random points on a 1-dim Line with:

rpoisppOnLines(lambda, L, lmax = NULL, ..., nsim=1, drop=TRUE)

Now, I would like to produce the real line, preferably with matching labeling.

Does anyone have an idea?


回答1:


Here is some crude code on getting samples from a point process.

library(spatstat)
lambda = 5
L = psp(0, 0, 3, 0, owin(c(0, 3), c(-1, 1)))
pp = rpoisppOnLines(lambda, L, lmax = NULL, nsim=1, drop=TRUE)
plot(pp$x, pp$y, pch = 4, lwd = 2, cex = 2)
abline(0, 0)

You could make your plot fancy with ggplot2




回答2:


You could use a simple linear network to represent the one dimensional line segment you want to simulate on. This also makes it possible to fit models (lppm), estimate the intensity non-parametrically (density.lpp), estimate the K-function (linearK), and a bunch of other things:

library(spatstat)
x_start <- 0
x_end <- 3
endpoints <- ppp(x=c(x_start, x_end), y=c(0,0), window = owin(c(x_start, x_end), c(-.1,.1)))
L <- linnet(endpoints, edges = matrix(c(1,2),ncol = 2))
X <- rpoislpp(lambda = 5, L = L)

However, this tool is designed for points on a complicated network and not just the real line, so the plotting method is not really adapted to this setting, and might not produce exactly what you want (too much white space):

plot(X, pch = 4, lwd = 2, main = "")
axis(1)

You can extract the coordinates of the point pattern using coords and then use the plotting method from the other answer from there:

co <- coords(X)
co$x
#> [1] 1.3306861 2.5550691 1.7776248 2.9486675 1.8571362 2.5020587 1.4843001
#> [8] 0.4371669 0.8478670

Created on 2018-12-18 by the reprex package (v0.2.1)



来源:https://stackoverflow.com/questions/53837044/1-dimensional-point-process-in-r-spatstat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!