Learn R Programming

spaMM (version 3.11.3)

MaternIMRFa: corrFamily constructor for Interpolated Markov Random Field (IMRF) covariance structure approximating a 2D Matern correlation model.

Description

Reimplements the IMRF correlation model approximating a Matern correlation function, through a corrFamily constructor. This allows the efficient joint estimation of the alpha parameter of the approximating Markov random field (in principle related to the smoothness parameter of the Matern correlation function) together with its kappa parameter. By contrast, random effects terms specified as IMRF(1| . , model = <INLA::inla.spde2.matern result>) assume a fixed alpha.

Using this feature requires that the not-on-CRAN package INLA (https://www.r-inla.org) is installed so that INLA::inla.spde2.matern can be called for each alpha value.

Usage

# corrFamily constructor:
MaternIMRFa(mesh, tpar = c(alpha = 1.25, kappa = 0.1), fixed = NULL)

Arguments

mesh

An inla.mesh object as produced by INLA::inla.mesh.2d.

tpar

Named numeric vector: template values of the parameters of the model. Better not modified unless you know what you are doing.

fixed

NULL or numeric vector, to fix the parameters of this model.

Value

A list suitable as input in the covStruct argument, with the following elements:

f

function returning a precision matrix for the random effect in mesh vertices;

tpar

template parameter vector (see general requirements of a corrFamily descriptor);

Af

function returning a matrix that implements the prediction of random effect values in data locations by interpolation of values in mesh locations (similarly to INLA::inla.spde.make.A);

type

specifies that the matrix returned by Cf is a precision matrix rather than a correlation matrix;

and possibly other elements which should not be considered as stable features of the return value.

References

Lindgren F., Rue H., Lindstr<U+00F6>m J. (2011) An explicit link between Gaussian fields and Gaussian Markov random fields: the stochastic partial differential equation approach Journal of the Royal Statistical Society: Series B (Statistical Methodology), 73: 423-498. 10.1111/j.1467-9868.2011.00777.x

Examples

Run this code
# NOT RUN {
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                     
corrfam <- MaternIMRFa(mesh, fixed=c(alpha=1.05))       # generate corrFamily descriptor                     

(fit_MaternIMRF <- fitme(
  cbind(npos,ntot-npos) ~ elev1 + elev2 + elev3 + elev4 + maxNDVI1 + 
        seNDVI + corrFamily(1|longitude+latitude),         # declare corrFamily term
  covStruct=list(corrFamily=corrfam),                # declare corrFamily descriptor
  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                     
corrfam <- MaternIMRFa(mesh)       # generate corrFamily descriptor                     

(fit_MaternIMRF <- fitme(
  cbind(npos,ntot-npos) ~ elev1 + elev2 + elev3 + elev4 + maxNDVI1 + 
        seNDVI + corrFamily(1|longitude+latitude),         # declare corrFamily term
  covStruct=list(corrFamily=corrfam),                # declare corrFamily descriptor
  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