Learn R Programming

spaMM (version 1.4.1)

mapMM: Colorful plots of predicted responses in two-dimensional space.

Description

These functions provide either a map of predicted response in analyzed locations, or a predicted surface. The former is a straightforward representation of the analysis of the data, while the latter cope with the fact that all predictor variables may not be known in all locations on a fine spatial grid, but may involve questionable choices as a result (see map.formula argument).

Usage

mapMM(fitobject,coordinates=NULL,xrange=NULL,yrange=NULL,
      margin=1/20,add.map= FALSE, nlevels = 20, 
      color.palette = spaMM.colors,map.asp=NULL,
      col = color.palette(length(levels) - 1), plot.title, 
      plot.axes, decorations, key.title, key.axes, xaxs = "i", 
      yaxs = "i", las = 1, axes = TRUE, frame.plot = axes, ...) 
filled.mapMM(fitobject,coordinates,xrange=NULL,yrange=NULL,
             margin=1/20,map.formula,phi=1e-05,gridSteps=41,
             add.points=quote(points(pred[,coordinates],cex=1,lwd=2)),
             add.map=FALSE,axes = TRUE, plot.axes,map.asp=NULL,...)

Arguments

fitobject
The return object of a corrHLfit call.
coordinates
The geographical coordinates. By default they are deduced from the model formula. For example if this formula is resp ~ 1 + Matern(1| x + y ) the default coordinates are c("x","y"). If this formula is resp ~ 1 + Matern(1| x + y + z )
xrange
The x range of the plot (a vector of length 2); by default defined to cover all analyzed points.
yrange
The y range of the plot (a vector of length 2); by default defined to cover all analyzed points.
margin
This controls how far (in relative terms) the plot extends beyond the x and y ranges of the analyzed points, and is overriden by explicit xrange and yrange arguments.
map.formula
Plotting a filled contour generally requires prediction in non-oberved locations, where predictor variables used in the original data analysis may be missing. In that case, the original model formula cannot be used and an alternative map.formula
phi
This controls the phi valu assumed in the interpolation step. Ideally phi would be zero, but problems with numerically singular matrices may arise when phi is too small.
gridSteps
The number of levels of the grid of x and y values
add.points
Either a boolean or an explicit expression, enclosed in quote (the default value illustrates the latter syntax). This controls whether and how analyzed locations are represented on the map.
add.map
Either a boolean or an explicit expression, enclosed in quote (see Examples). If TRUE, the map function from the maps package (which much therefore the loaded) is used to add a map from its default
levels
a set of levels which are used to partition the range of z. Must be strictly increasing (and finite). Areas with z values between consecutive levels are painted with the same color.
nlevels
if levels is not specified, the range of z, values is divided into approximately this many levels.
color.palette
a color palette function to be used to assign colors in the plot.
map.asp
the y/x aspect ratio of the 2D plot area (not of the full figure including the scale). Default is (plotted y range)/(plotted x range) (i.e., scales for x are identical).
col
an explicit set of colors to be used in the plot. This argument overrides any palette function specification. There should be one less color than levels
plot.title
statements which add titles to the main plot. If provided, further ... arguments are ignored (see Details).
plot.axes
statements which draw axes (and a box) on the main plot. Default axes are drawn by default when this argument is missing, given axes = TRUE.
decorations
Additional graphic statements (points, polygon, etc.).
key.title
statements which add titles for the plot key.
key.axes
statements which draw axes on the plot key.
xaxs
the x axis style. The default is to use internal labeling.
yaxs
the y axis style. The default is to use internal labeling.
las
the style of labeling to be used. The default is to use horizontal labeling.
axes, frame.plot
logicals indicating if axes and a box should be drawn, as in plot.default.
...
further arguments passed to or from other methods. For mapMM, currently only additional graphical parameters passed to title() (see Details). For filled.mapMM, these parameters are those that can be passed to

Value

  • No return value. Plots are produced as side-effects.

Details

If you have values for all predictor variables in all locations of a fine spatial grid, filled.mapMM may not be a good choice. Rather, use predict(,newX= ) to generate all predictions, and then either spaMM.filled.contour or some other raster functions. These functions handle some of their arguments as filled.contour does. For mapMM in particular, this means that either plot.title is missing, or ... is ignored. Thus, one can provide an optional xlab either in the plot.title argument, or in the ... plot.title is missing. filled.mapMM calls spaMM.filled.contour which behaves identically, so the ... argument of filled.mapMM should contain either a plot.title or further arguments. A side effet is that filled.mapMM, like filled.contour, does not does not provide axis labels (xlab and ylab) by default.

Examples

Run this code
data(blackcap)
bfit <- corrHLfit(migStatus ~ means+ Matern(1|longitude+latitude),data=blackcap,
                  HLmethod="ML",
                  ranFix=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)})

## showing add.map
filled.mapMM(bfit,add.map=TRUE,plot.axes={axis(1);axis(2)},
             plot.title=title(main="Inferred migration propensity of blackcaps",
                               xlab="longitude",ylab="latitude"))
## filled.mapMM takes a bit longer
filled.mapMM(bfit,nlevels=30,plot.axes={axis(1);axis(2)},
              plot.title=title(main="Inferred migration propensity of blackcaps",
                               xlab="longitude",ylab="latitude"))


## showing more involved use of add.map
data(Loaloa)  
lfit <- corrHLfit(cbind(npos,ntot-npos)~elev1+elev2+elev3+elev4+maxNDVI1+seNDVI
                    +Matern(1|longitude+latitude),HLmethod="HL(0,1)",data=Loaloa,
                    family=binomial(),ranFix=list(nu=0.5,rho=2.255197,lambda=1.075))   

if(require(maps)) {
  mapMM(lfit,add.map=quote(map(,xlim=xrange,ylim=yrange,add=TRUE)))
}


## longer computation requiring interpolation of 197 points 
filled.mapMM(lfit,add.map=TRUE,plot.axes={axis(1);axis(2)},
             add.points=quote(points(pred[,coordinates],pch=15,cex=0.3)),
             plot.title=title(main="Inferred prevalence, North Cameroon",
                                xlab="longitude",ylab="latitude"))

Run the code above in your browser using DataLab