if (require("INLA", quietly = TRUE)) {
# Load the Gorilla data
data(gorillas, package ="inlabru")
# Plot the Gorilla nests, the mesh and the survey boundary
ggplot() +
gg(gorillas$mesh) +
gg(gorillas$nests) +
gg(gorillas$boundary) +
coord_fixed()
# Define SPDE prior
matern <- inla.spde2.pcmatern(gorillas$mesh,
prior.sigma = c(0.1, 0.01),
prior.range = c(5, 0.01))
# Define domain of the LGCP as well as the model components (spatial SPDE effect and Intercept)
cmp <- coordinates ~ mySmooth(map = coordinates, model = matern) + Intercept
# Fit the model
fit <- lgcp(cmp, gorillas$nests, samplers = gorillas$boundary)
# Once we obtain a fitted model the predict function can serve various purposes.
# The most basic one is to determine posterior statistics of a univariate
# random variable in the model, e.g. the intercept
icpt <- predict(fit, NULL, ~ Intercept)
That last line yields the error
Error in samples[[i]] : subscript out of bounds
In addition: Warning message:
In inla.posterior.sample.interpret.selection(selection, result) :
Some selections are not used:
I've gotten this error with my own data and when running the gorillas example code on https://rdrr.io/cran/inlabru/man/predict.bru.html. Any idea what the problem is?
That last line yields the error