plot.modgam {MapGAM} | R Documentation |
Maps Predicted Values and Clusters for modgam
Objects
Description
Displays a color image map, including a legend, scale bar, and optional North arrow, showing crude or adjusted odds ratios (or linear predictors) for a grid of points. Irregular grids are allowed. Also draws contour lines for regions of signficantly increased or decreased values of the outcome variable ("clusters"), if permutation ranks are provided. Designed to display modgam
objects but can be used with other model results if the modgamobj list contains the correct elements.
Usage
## S3 method for class 'modgam'
plot(x, map = NULL, exp = FALSE, add = FALSE, intervals=TRUE,
mapmin = NULL, mapmax = NULL, col.seq = diverge_hsv(201), anchor=FALSE,
border.gray = 0.3, contours=c("none","response","permrank","interval"),
contours.drawlabels=FALSE, contours.lty=1, contours.lwd=1,
contours.levels, contours.labcex=0.7, arrow=TRUE, axes=FALSE, ptsize=0.9,
alpha=0.05, mai, legend.name = "predicted values", legend.cex=1, ...)
Arguments
x |
(required) an object of class |
map |
can be used to map predicted values on a base map from the |
exp |
if |
add |
use |
intervals |
if the |
mapmin |
the minimum value for the color scale legend. |
mapmax |
the maximum value for the color scale legend. |
col.seq |
The color sequence (palette) used to display the predicted values on the map. |
anchor |
Use |
border.gray |
gray scale for the border of |
contours |
use |
contours.drawlabels |
use |
contours.lty |
the line type for contour lines. |
contours.lwd |
the width for contour lines. |
contours.levels |
the levels for contour lines. When |
contours.labcex |
cex for contour labelling. This is an absolute size, not a multiple of |
arrow |
use |
axes |
use |
ptsize |
the size of the points used to fill in colors on the map. Increase to remove white space inside the map or decrease to remove color outside the map boundaries. NOTE: white space can also be eliminated by increasing the grid size in |
alpha |
the nominal pointwise type I error rate; only used when |
mai |
the margins of the plot. Details see par. |
legend.name |
the name of displayed for the legend bar. |
legend.cex |
a numerical value giving the amount by which legend text should be magnified relative to the default. |
... |
other arguments to be passed to colormap function. |
Value
Produces an image map showing crude or adjusted linear predictors (or odds ratios). If the base map is in readShapePoly
format a scale bar is included. The scale bar assumes that the X and Y coordinates are provided in meters.
Warning
Note that the contour lines use a pointwise nominal type I error rate of alpha; the chance of a type I error occurring for at least one point on the map is much higher, typically approaching 100% at alpha=0.05, because a spatial prediction grid generally contains many points.
Author(s)
Scott Bartell, Lu Bai, Robin Bliss, and Veronica Vieira
Send bug reports to sbartell@uci.edu.
See Also
trimdata
,
predgrid
,
optspan
,
modgam
,
colormap
.
Examples
data(MAmap)
data(MAdata)
# Create a grid on the base map
MAgrid <- predgrid(MAdata, map=MAmap)
# fit crude GAM model to the MA data using span size of 50%
fit1 <- modgam(data=MAdata, rgrid=MAgrid, m="crude", sp=0.5)
# Plot a map showing crude odds ratios
plot(fit1, MAmap)
#### A detailed example including map projections and data trimming
# NOTE: this example requires the maps and mapproj packages
# Convert base map and beer tweet data locations to US Albers projection
# projected coords yield better distance estimates than (lat,long)
if(require(maps) & require(mapproj)) {
USmap <- map("state",projection="albers",parameters=c(29.5,45.5),
plot=FALSE,fill=TRUE,col="transparent")
data(beertweets)
case <- beertweets$beer
# Reuse last map projection to convert data coordinates
XY <- mapproject(beertweets$longitude,beertweets$latitude)[1:2]
beerproj <- data.frame(case, XY[1], XY[2])
# Generate grid on the US map, trimmed to range of beer data
USgrid <- predgrid(beerproj, map=USmap)
# Fit unadjusted model--geolocation only
fit2 <- modgam(data=beerproj, rgrid=USgrid, m="unadjusted", sp=0.05)
dev.new(width=7,height=5)
plot(fit2, USmap)
title(main="Beer Tweet Odds Ratios")
}