data("blackcap")
bfit <- fitme(migStatus ~ means+ Matern(1|longitude+latitude),data=blackcap,
fixed=list(lambda=0.5537,phi=1.376e-05,rho=0.0544740,nu=0.6286311))
mapMM(bfit,color.palette = function(n){spaMM.colors(n,redshift=1/2)},add.map=TRUE)
map_ranef(bfit) # providing argument re.form= . ~ Matern(1|longitude+latitude)
if (spaMM.getOption("example_maxtime")>1) {
## filled.mapMM takes a bit longer
# showing 'add.map', 'nlevels', and contour lines for 'variance'
filled.mapMM(bfit, nlevels=30, add.map=TRUE, plot.axes=quote({axis(1);axis(2)}),
variance="respVar",
plot.title=title(main="Inferred migration propensity of blackcaps",
xlab="longitude",ylab="latitude"))
## Similar plots by ggplot2:
if (FALSE) {
library(rnaturalearth) # provides sea mask through 'ne_download' function
library(ggplot2)
library(sp)
# sea mask
sea <- ne_download(scale = 10, type = 'ocean', category = "physical", returnclass = "sf")
# Generation of data.frame for ggplot:
rastr <- filled.mapMM(bfit, return.="raster")
spdf <- data.frame(Long=rep(rastr$x, nc), Lat=rastr$y[gl(nr,nc)], z = as.vector(rastr$z))
ggplot(spdf) +
geom_contour_filled(aes(Long,Lat,z=z), bins = 20) +
guides(fill = "none") +
geom_sf(data = sea, fill = "black") +
coord_sf(ylim = range(rastr$y), xlim = range(rastr$x), expand = FALSE)
}
}
if (spaMM.getOption("example_maxtime")>3) {
data("Loaloa")
lfit <- fitme(cbind(npos,ntot-npos)~elev1+elev2+elev3+elev4+maxNDVI1+seNDVI
+Matern(1|longitude+latitude), method="PQL", data=Loaloa,
family=binomial(), fixed=list(nu=0.5,rho=2.255197,lambda=1.075))
## longer computation requiring interpolation of 197 points
## Also illustrating effect of 'return.' argument
res <- filled.mapMM(lfit,add.map=TRUE,plot.axes=quote({axis(1);axis(2)}),
decorations=quote(points(pred[,coordinates],pch=15,cex=0.3)),
return.="raster", # so that 'res' is a list representing a raster.
plot.title=title(main="Inferred prevalence, North Cameroon",
xlab="longitude",ylab="latitude"))
}
Run the code above in your browser using DataLab