## Examples with Matern correlations
## A likelihood ratio test based on the ML fits of a full and of a null model.
data("blackcap")
(fullfit <- fitme(migStatus ~ means+ Matern(1|longitude+latitude),data=blackcap) )
(nullfit <- fitme(migStatus ~ 1 + Matern(1|longitude+latitude),data=blackcap))
## p-value:
1-pchisq(2*(logLik(fullfit)-logLik(nullfit)),df=1)
## See ?spaMM for examples of conditional autoregressive model and of non-spatial models.
## Contrasting different optimization methods:
# We simulate Gamma deviates with mean mu=3 and variance=2,
# ie. phi= var/mu^2= 2/9 in the (mu, phi) parametrization of a Gamma
# GLM; and shape=9/2, scale=2/3 in the parametrisation of rgamma().
# Note that phi is not equivalent to scale:
# shape = 1/phi and scale = mu*phi.
set.seed(123)
gr <- data.frame(y=rgamma(100,shape=9/2,scale=2/3))
# Here fitme uses HLfit methods which provide cond. SE for phi by default:
fitme(y~1,data=gr,family=Gamma(log))
# To force outer optimization of phi, use the init argument:
fitme(y~1,data=gr,family=Gamma(log),init=list(phi=1))
# To obtain cond. SE for phi after outer optimization, use the 'refit' control:
fitme(y~1,data=gr,family=Gamma(log),,init=list(phi=1),
control=list(refit=list(phi=TRUE))) ## or ...refit=TRUE...
## Outer-optimization is not necessarily the best way to find a global maximum,
# particularly when there is little statistical information in the data:
if (spaMM.getOption("example_maxtime")>1.6) {
data("blackcap")
fitme(migStatus ~ means+ Matern(1|longitude+latitude),data=blackcap) # poor
# Compare with the following two ways of avoiding outer-optimization of lambda:
corrHLfit(migStatus ~ means+ Matern(1|longitude+latitude),data=blackcap,
method="ML")
fitme(migStatus ~ means+ Matern(1|longitude+latitude),data=blackcap,
init=list(lambda=NaN))
}
## see help("COMPoisson"), help("negbin"), help("Loaloa"), etc., for further examples.
Run the code above in your browser using DataLab