When I fit an LGCP model with a factor variable as a covariate I get the following error when predicting the model onto the results of pixels.
Error in Matrix::sparseMatrix(i = which(ok), j = val[ok], x = rep(weights, :
all(dims >= dims.min) is not TRUE
I'm able to predict using ipoints or without the factor variable in the prediction equation. Below is code to reproduce the error using the gorillas dataset.
library(inlabru)
library(INLA)
library(ggplot2)
# Load the data
data(gorillas, package = "inlabru")
# Construct latent model components
matern <- inla.spde2.pcmatern(gorillas$mesh,
prior.sigma = c(0.1, 0.01),
prior.range = c(5, 0.01))
cmp <- coordinates ~ mySmooth(main = coordinates,
model = matern) +
vegetation(main = gorillas$gcov$vegetation, model = "iid", n = 6) +
Intercept
# Fit LGCP model
fit <- lgcp(cmp,
data = gorillas$nests,
samplers = gorillas$boundary,
domain = list(coordinates = gorillas$mesh),
options = list(control.inla = list(int.strategy = "eb")))
#Predict Number of Nests
integration_points <- ipoints(gorillas$boundary, gorillas$mesh)
predict(fit, integration_points, ~ sum(weight * exp(mySmooth + Intercept + vegetation)))
#This works
# Predict Gorilla nest intensity
lambda <- predict(fit, pixels(gorillas$mesh, mask = gorillas$boundary), ~ exp(mySmooth + Intercept + vegetation))
#This doesn't
#Prediction without vegetation covariate
lambda <- predict(fit, pixels(gorillas$mesh, mask = gorillas$boundary), ~ exp(mySmooth + Intercept))
#This works
When I fit an LGCP model with a factor variable as a covariate I get the following error when predicting the model onto the results of
pixels
.I'm able to predict using
ipoints
or without the factor variable in the prediction equation. Below is code to reproduce the error using thegorillas
dataset.