inlabru-org / inlabru

inlabru
https://inlabru-org.github.io/inlabru/
78 stars 21 forks source link

1D samplers? #111

Closed jdselwyn closed 2 years ago

jdselwyn commented 3 years ago

This is probably a fairly straightforward question, I hope. I'm trying to create an lgcp model in one dimension where I have gaps in the observations because of sampling, not because of anything related to the point process. Basically I surveyed from 0-5 and from 10-20 but don't have observations from 5-10 because they were unobserved. My understanding is that in the 2D case I would use the samplers argument in lgcp to specify this. How should I specify the 1D sampler given that a SpatialPolygonsDataFrame doesn't make sense? Thanks and sorry if this is answered in the docs somewhere, I haven't been able to find it!

finnlindgren commented 3 years ago

1D interval samplers can be specified as 2-column matrices, with one interval per row:

library(INLA)
library(inlabru)

mesh <- inla.mesh.1d(loc <- seq(0, 20, length.out = 30))
sampler <- rbind(c(0, 5), c(10, 20))
ips <- ipoints(samplers = sampler, domain = mesh)
plot(ips)

However, due to a namespace issue this might not work in the 2.3.1 version; if you get an error message Error in colSums(A_w) : 'x' must be an array of at least two dimensions it might work if you first do library(Matrix). Otherwise you'll need to install the current devel version, where I've fixed it (78c65f4). Instead of explicitly calling ipoints(), you should be able to supply the samplers and domain information directly to like()/lgcp(), just as for 2D models.

finnlindgren commented 3 years ago

The documentation for this is in the ipoints function help.

jdselwyn commented 3 years ago

That works perfectly. Thank you so much.