View source: R/convenience-functions.R
sp_diag | R Documentation |
Visual diagnostics for areal data and model residuals
sp_diag(y, shape, ...)
## S3 method for class 'geostan_fit'
sp_diag(
y,
shape,
name = "Residual",
plot = TRUE,
mc_style = c("scatter", "hist"),
style = c("W", "B"),
w = y$C,
rates = TRUE,
binwidth = function(x) 0.5 * stats::sd(x, na.rm = TRUE),
size = 0.1,
...
)
## S3 method for class 'numeric'
sp_diag(
y,
shape,
name = "y",
plot = TRUE,
mc_style = c("scatter", "hist"),
style = c("W", "B"),
w = shape2mat(shape, match.arg(style)),
binwidth = function(x) 0.5 * stats::sd(x, na.rm = TRUE),
...
)
y |
A numeric vector, or a fitted |
shape |
An object of class |
... |
Additional arguments passed to |
name |
The name to use on the plot labels; default to "y" or, if |
plot |
If |
mc_style |
Character string indicating how to plot the residual Moran coefficient (only used if |
style |
Style of connectivity matrix; if |
w |
An optional spatial connectivity matrix; if not provided and |
rates |
For Poisson and binomial models, convert the outcome variable to a rate before plotting fitted values and residuals. Defaults to |
binwidth |
A function with a single argument that will be passed to the |
size |
Point size and linewidth for point-interval plot of observed vs. fitted values (passed to |
When provided with a numeric vector, this function plots a histogram, Moran scatter plot, and map.
When provided with a fitted geostan
model, the function returns a point-interval plot of observed values against fitted values (mean and 95 percent credible interval), a Moran scatter plot for the model residuals, and a map of the mean posterior residuals (means of the marginal distributions). If if mc_style = 'hist'
, the Moran scatter plot is replaced by a histogram of Moran coefficient values calculated from the joint posterior distribution of the residuals.
A grid of spatial diagnostic plots. If plot = TRUE
, the ggplots
are drawn using grid.arrange; otherwise, they are returned in a list. For the geostan_fit
method, the underlying data for the Moran coefficient (as required for mc_style = "hist"
) will also be returned if plot = FALSE
.
me_diag
, mc
, moran_plot
, aple
data(georgia)
sp_diag(georgia$college, georgia)
bin_fn <- function(y) mad(y, na.rm = TRUE)
sp_diag(georgia$college, georgia, binwidth = bin_fn)
fit <- stan_glm(log(rate.male) ~ log(income),
data = georgia,
centerx = TRUE,
chains = 1, iter = 1e3) # for speed only
sp_diag(fit, georgia)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.