Learn R Programming

spaMM (version 1.7.2)

HLCor: Fits a (spatially) correlated mixed model, for given correlation parameters

Description

A convenient interface for HLfit, constructing the correlation matrix of random effects from the arguments, then estimating fixed effects and dispersion parameters using HLfit.

Usage

HLCor(formula,ranPars=NULL,data,distMatrix,
      uniqueGeo=NULL,adjMatrix,
      corrMatrix,verbose=c(warn=TRUE,trace=FALSE,summary=FALSE),
      control.dist = list(),...)

Arguments

formula
A predictor, i.e. a formula with attributes (see Predictor), or possibly simply a simple formula if an offset is not required.
ranPars
A list of values for correlation parameters (some of which are mandatory), and possibly also dispersion parameters (optional, but passed to HLfit if present). For the Matérn model, the correlation parameters are rho (scale parameter(s
data
The data frame to be analyzed.
distMatrix
A distance matrix between geographic locations, forwarded to MaternCorr
uniqueGeo
A matrix of non-redundant geographic locations. This is useful if the rho parameter is a vector with different values for different geographic coordinates, in which case a scaled distance matrix has to be reconstructed from uniqueG
adjMatrix
An adjacency matrix, used if a random effect of the form y ~ adjacency(1|) is present. Its rows and columns must be ordered as increasing values of the levels of the geographic location index specifying the spatial
corrMatrix
A arbitrary (valid) correlation matrix, used if a random effect term of the form corrMatrix(1|) is present. Each row corresponds to levels of a variable . This allows to analyze non-spatial model by giving for example a mat
verbose
A vector of booleans. trace controls various diagnostic (possibly messy) messages about the iterations. summary controls whether a summary of the fit is called by HLfit. warn is for programming
control.dist
A list of arguments that control the computation of the distance argument of the correlation functions. Possible elements are [object Object],[object Object]
...
Further parameters passed to HLfit or to designL.from.corr.

Value

  • The return value of an HLfit call, with the following additional attributes:
  • HLCorcallthe HLCor call
  • info.uniqueGeoUnique geographic locations.

Details

The correlation matrix for random effects can be specified by various combination of formula terms and other arguments (see Examples): [object Object],[object Object],[object Object],[object Object]

References

Wall M.M. (2004) A close look at the spatial structure implied by the CAR and SAR models: Journal of Statistical Planning and Inference 121: 311-324. Martellosio, F. (2012) The correlation structure of spatial autoregressions, Econometric Theory 28, 1373-1391.

See Also

MaternCorr, HLfit, corrHLfit

Examples

Run this code
# Example with an adjacency matrix (autoregressive model):
# see 'adjacency' documentation page

#### Matérn correlation using only the Matern() syntax
if (spaMM.getOption("example_maxtime")>2) {
 data(Loaloa)
 HLCor(cbind(npos,ntot-npos)~elev1+elev2+elev3+elev4+maxNDVI1+seNDVI
              +Matern(1|longitude+latitude),data=Loaloa,
      family=binomial(),ranPars=list(nu=0.5,rho=1/0.7)) 
}
#### Using a corrMatrix (not necessarily Matérn)
data(blackcap) 
## Here we manually reconstruct the correlation matrix 
##  of the ML fit produced by corrHLfit:
MLcorMat <- MaternCorr(proxy::dist(blackcap[,c("latitude","longitude")]),
                        nu=0.6285603,rho=0.0544659)
# simple but easily misunderstood syntax:                        
HLCor(migStatus ~ means+ corrMatrix(1|latitude+longitude),data=blackcap,
      corrMatrix=MLcorMat,HLmethod="ML")
# An equivalent syntax worth understanding (see Details):      
bcdummy <- cbind(blackcap,dummy=sample(nrow(blackcap))) 
HLCor(migStatus ~ means+ corrMatrix(1|dummy),data=bcdummy,
      corrMatrix=MLcorMat,HLmethod="ML")
       
#### Matérn correlation using a distMatrix
MLdistMat <- as.matrix(proxy::dist(blackcap[,c("latitude","longitude")]))
HLCor(migStatus ~ means+ Matern(1|latitude+longitude),data=blackcap,
      distMatrix=MLdistMat,HLmethod="ML",ranPars=list(nu=0.6285603,rho=0.0544659))

Run the code above in your browser using DataLab