Learn R Programming

spaMM (version 1.1)

spaMM: Inference in spatial GLMMs (and other non-spatial mixed models)

Description

spaMM has been designed to fit spatial mixed models. This package can fit a wider class of non-spatial mixed models (see Examples), but has not been optimized for that purpose. The random effects are either Gaussian (which defines GLMMs), or other distributions (which defines the wider class of hierarchical GLMs), or simply absent (which makes a GLM).

Arguments

Details

The models are fit via Laplace approximations to compute (1) the marginal likelihood with respect to random effects and (2) the restricted likelihoods (as in REML), i.e conditional likelihoods with respect to fixed effect estimates. The package has been thoroughly tested mainly for analysis of spatial GLMMs, where the random effects are Gaussian. The alternative of Beta-distributed, Gamma and inverse-Gamma distributed random effects have been implemented as detailed in the HLfit documentation and checked against literature results, but they are not recommended for spatial models. The variance of random effects is denoted $\lambda$ and that of residual error is denoted $\phi$. A fixed-effects linear predictor for $\phi$, modeling heteroskedasticity, can be considered (see Examples). Fixed effects are described in the standard form X$\beta$ where X is the design matrix of fixed effects and $\beta$ a vector of fixed effect parameters. The high-level functions of the package make it easy to incorporate spatial correlations in the model, following either a Matérn correlation model or an adjacency matrix model. For more complex applications, the structure of the random effects can be described by the following steps. First, independent and identically distributed (iid) random effects $u$ are drawn from some distribution; second, a transformation v$=f$(u) is applied (v elements are still iid); third, correlated random effects are obtained as Mv, where M can describe spatial correlation between observed locations, block effects (or repeated observations in given locations), and correlations involving unobserved locations. See Details in Predictor for further details.

References

Lee, Y., Nelder, J. A. and Pawitan, Y. (2006). Generalised linear models with random effects: unified analysis via h-likelihood. Chapman & Hall: London.

See Also

spaMM is designed to be used through the high-level functions corrHLfit, HLCor, HLfit, Predictor, fixedLRT

Examples

Run this code
## Fit a Poisson GLMM with adjacency correlation model

data(scotlip) ## loads scotlip data frame, and Nmatrix
corrHLfit(cases~I(prop.ag/10) +adjacency(1|gridcode)+offset(log(scotlip$expec)),
          data=scotlip,family=poisson(),
          adjMatrix=Nmatrix,lower=list(rho=0),upper=list(rho=0.1745))

## fit a non-spatial, Beta-binomial model:
data(Loaloa)
idx  <-as.factor(seq(nrow(Loaloa)))
fLoaloa <- cbind(Loaloa,idx)
HLfit(cbind(npos,ntot-npos)~elev1+elev2+elev3+elev4+maxNDVI1+seNDVI
                   +(1|idx),HLmethod="HL(1,1)",
            data=fLoaloa,family=binomial(),rand.family=Beta()) 

## fit a non-spatial, Gamma GLMM:
data(wafers)
HLfit(y ~X1*X3+X2*X3+I(X2^2)+(1|batch),family=Gamma(log),
          data=wafers)

## Same with fixed-effects predictor for residual variance 
## ( = structured-dispersion model):
HLfit(y ~X1*X3+X2*X3+I(X2^2)+(1|batch),family=Gamma(log),
          resid.formula = ~ X3+I(X3^2) ,data=wafers)

## fit a GLM (not mixed) with structured dispersion:
HLfit( y ~X1+X2+X1*X3+X2*X3+I(X2^2),family=Gamma(log),
      resid.formula = ~ X3+I(X3^2) ,data=wafers)

## Fit of binary data using PQL/L. See ?arabidopsis
data(arabidopsis)
HLCor(cbind(pos1046738,1-pos1046738)~seasonal+Matern(1|LAT+LONG),
                   ranPars=list(rho=0.129,lambda=4.28,nu=0.291),
                   family=binomial(),HLmethod="PQL/L",data=arabidopsis)

Run the code above in your browser using DataLab