if (FALSE) {
if(requireNamespace("INLA", quietly = TRUE)) {
data("Loaloa")
mesh <- INLA::inla.mesh.2d(loc = Loaloa[, c("longitude", "latitude")],
max.edge = c(3, 20))
### Fit with fixed alpha
(fit_MaternIMRF <- fitme(
cbind(npos,ntot-npos) ~ elev1 + elev2 + elev3 + elev4 + maxNDVI1 +
seNDVI + MaternIMRFa(1|longitude+latitude, mesh, fixed=c(alpha=1.05)),
family=binomial(),
data=Loaloa, verbose=c(TRACE=interactive())) )
# For data sets with a small number of locations (as here), fitting
# the Matern model as follows is faster than fitting its MaternIMRFa approximation.
# Here this appears more than twofold faster
fit_Matern <- fitme(
cbind(npos,ntot-npos) ~ elev1 + elev2 + elev3 + elev4 + maxNDVI1 +
seNDVI + Matern(1|longitude+latitude),
fixed=list(nu=0.05), # in principle similar to alpha=0.05
data=Loaloa,family=binomial())
### Same with variable alpha
(fit_MaternIMRF <- fitme(
cbind(npos,ntot-npos) ~ elev1 + elev2 + elev3 + elev4 + maxNDVI1 +
seNDVI + MaternIMRFa(1|longitude+latitude, mesh),
family=binomial(),
data=Loaloa, verbose=c(TRACE=interactive())) )
# Comparable Matern fit:
fit_Matern <- fitme(
cbind(npos,ntot-npos) ~ elev1 + elev2 + elev3 + elev4 + maxNDVI1 +
seNDVI + Matern(1|longitude+latitude),
init=list(nu=0.25), lower=list(nu=0), upper=list(nu=1),
data=Loaloa,family=binomial())
# Note that the fitted nu and alpha parameters do not quite match each other,
# and that the IMRF likelihood does not really approximate the Matern likelihood.
# Mesh design would also be seen to matter.
} else print("INLA must be installed to run this example.")
}
Run the code above in your browser using DataLab