#----------------------------------------------------------------------Data ####world_map <- _a simplified SpatialPolygonsDataframe_
data <- _a SpatialPointsDataframe of presence points and corresponding covariates values, nrow ~20,000_cov_rst <- _a raster stack of covariates_## Format for modelcov_names <- c("tsi", "BIO16", "BIO17", "ghf") # covariates of interest (continuous variables)data <- data[c("presence", cov_names)]cov_rst <- raster::subset(cov_rst, cov_names, drop = T)cov_est <- data@data[cov_names]loc_est <- inla.mesh.map(data@coords, projection = "longlat") # convert lat/lon to 3D xyzy <- data$presence
#----------------------------------------------------------------------Mesh ###### Domain boundary
boundary <- inla.sp2segment(world_map, crs = inla.CRS("longlat"))## Mesh parametersrange <- 10max_edge <- range/10 * pi/180kCut_off <- 0.5min_angle <- 26## Build mesh(mesh <- inla.mesh.2d( boundary = boundary, cutoff = max_edge * kCut_off, max.edge = c(1, 5) * max_edge, # (inner, outer) min.angle = min_angle, crs = inla.CRS("sphere")))$n
[1] 32795
## Plot meshplot(mesh$mesh, rgl = T)
#----------------------------------------------------------Projector matrix ####A_est <- inla.spde.make.A(mesh, loc = as.matrix(loc_est))
#----------------------------------------------------------------SPDE model ###### Hyperparameter priors prior_range0 <- 10 prior_sigmau0 <- log(1.1) alpha <- 2## SPDE model spde = inla.spde2.pcmatern( mesh = mesh, alpha = alpha, prior.range = c(prior_range0 * (pi/180), 0.1), # p(spatial range < prior.range0) prior.sigma = c(prior_sigmau0, 0.01), # p(sigma > prior.sigma.u0) )
#----------------------------------------------------------Estimation stack ####stack_est <- inla.stack( data = list(y = y), effects = list(s = 1:spde$n.spde, # spatial random effect index list(b0 = 1, # intercept cov_est)), # covariates A = list(A_est, 1), tag = 'est')
#------------------------------------------------------------------Formulae ####coef_names <- stack_est$effects$names[2:length(stack_est$effects$names)]## Fixed effects onlyform_fx <- formula(paste("y ~ -1 +", paste(coef_names, collapse = "+")))## Fixed effects and spatial random effectform_full <- update.formula( form_fx, ~. + f(s, model = spde))
> form_fully ~ b0 + tsi + BIO16 + BIO17 + ghf + f(s, model = spde) - 1
#----------------------------------------------------------Estimation model ####mdl_est = inla( formula = form_full, family = "binomial", data = inla.stack.data(stack_est), control.predictor = list(A = inla.stack.A(stack_est), compute = F), control.family = list(control.link = list(model = "logit")),
control.inla = list(int.strategy = "eb", # empirical bayes (cheap computation for testing) strategy = "gaussian", # (cheap computation for testing) correct = F, # correction to improve laplace approximations for binary data correct.factor = 1), # default = 1, report uses 10 control.compute = list(dic = F, waic = F, config = T), verbose = T)
> summary(mdl_est)
Call:
c("inla(formula = form_full, family = \"binomial\", data = inla.stack.data(stack_est), ", " verbose = T, control.compute = list(dic = F, waic = F, config = T), ", " control.predictor = list(A = inla.stack.A(stack_est), compute = F), ", " control.family = list(control.link = list(model = \"logit\")), ", " control.inla = list(int.strategy = \"eb\", strategy = \"gaussian\", ", " correct = F, correct.factor = 1))")
Time used:
Pre-processing Running inla Post-processing Total
0.6667 89.6467 0.4205 90.7340
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
b0 -4.6861 0.3013 -5.2777 -4.6861 -4.0950 -4.6861 0
tsi 0.4892 0.1048 0.2834 0.4892 0.6949 0.4892 0
BIO16 0.1493 0.0506 0.0500 0.1493 0.2486 0.1493 0
BIO17 0.0627 0.0604 -0.0560 0.0627 0.1812 0.0627 0
ghf 1.4381 0.0398 1.3601 1.4381 1.5161 1.4381 0
Random effects:
Name Model
s SPDE2 model
Model hyperparameters:
mean sd 0.025quant 0.5quant 0.975quant mode
Range for s 0.2259 0.0182 0.1923 0.2251 0.2639 0.2236
Stdev for s 2.2012 0.1141 1.9881 2.1971 2.4360 2.1875
Expected number of effective parameters(std dev): 428.72(0.00)
Number of equivalent replicates : 51.96
Marginal log-Likelihood: -3683.86
> (max(mdl_est[["summary.random"]][["s"]]$mean))
[1] 7.208389
> (mean(mdl_est[["summary.random"]][["s"]]$mean))
[1] -0.3690322
> (min(mdl_est[["summary.random"]][["s"]]$mean))
[1] -4.646531
Oops, this is the Illian reference, I forgot to link.
--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion-group+unsub...@googlegroups.com.
To post to this group, send email to r-inla-discussion-group@googlegroups.com.
Visit this group at https://groups.google.com/group/r-inla-discussion-group.
For more options, visit https://groups.google.com/d/optout.
Hi Mike,This problem is not uncommon. In some cases the most useful thing for the spatial random effect to do to model the data is to select a short range and large sigma. The way I interpret this is that the data needs a very local "overdispersion" and that the spatial random effect is the only candidate to model it.To compensate then, I suggest adding a local dispersion effect, as an iid effect in the linear predictor (f( index, model="iid")), and to consider this as part of the noise model (observation likelihood).For a code example with poisson likelihood:Kind regards,Haakon Bakka
On 26 June 2018 at 19:51, <mike.bl...@gmail.com> wrote:
Oops, this is the Illian reference, I forgot to link.
--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion-group+unsub...@googlegroups.com.
To post to this group, send email to r-inla-disc...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/r-inla-discussion-group/ac607065-3404-4693-a68f-2df319fdd231n%40googlegroups.com.