## Fit a Poisson GLMM with adjacency (CAR) correlation model
# see ?adjacency for how to fit efficiently such model models
data(scotlip) ## loads 'scotlip' data frame, but also 'Nmatrix'
HLCor(cases~I(prop.ag/10) +adjacency(1|gridcode)+offset(log(expec)),
adjMatrix=Nmatrix,family=poisson(),data=scotlip)
if (spaMM.getOption("example_maxtime")>3) {
## Adding a Gamma random effect to fit a negative-binomial response:
HLCor(cases~I(prop.ag/10) +(1|gridcode)+adjacency(1|gridcode)
+offset(log(expec)),
data=scotlip,family=poisson(),rand.family=list(Gamma(log),gaussian()),
adjMatrix=Nmatrix)
}
<!-- % tested in test-spaMM.R -->
## Not run: ------------------------------------
# ## fit non-spatial crossed random effects with distinct families
# data(salamander)
# HLfit(cbind(Mate,1-Mate)~1+(1|Female)+(1|Male),family=binomial(),
# rand.family=list(gaussian(),Beta(logit)),data=salamander,HLmethod="ML")
## ---------------------------------------------
## Nested effects
<!-- % tested in test-spaMM.R -->
## Not run: ------------------------------------
# # lmer syntax allowing several degrees of nesting
# HLfit(cbind(Mate,1-Mate)~1+(1|Female/Male),
# family=binomial(),rand.family=Beta(logit),data=salamander,HLmethod="ML")
# # [ also allowed is cbind(Mate,1-Mate)~1+(1|Female)+(1|Male %in% Female) ]
## ---------------------------------------------
## 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.model = ~ X3+I(X3^2) ,data=wafers)
## Random-slope model (mind the output!)
if (spaMM.getOption("example_maxtime")>1.1) {
HLfit(y~X1+(X2|batch),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.model = ~ X3+I(X3^2) ,data=wafers)
## Fit of binary data using PQL/L. See ?arabidopsis
## Not run: ------------------------------------
# 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