Visual diagnostics for spatial measurement error models.
Source
Donegan, Connor and Chun, Yongwan and Griffith, Daniel A. (2021). ``Modeling community health with areal data: Bayesian inference with survey standard errors and spatial structure.'' Int. J. Env. Res. and Public Health 18 (13): 6856. DOI: 10.3390/ijerph18136856 Data and code: https://github.com/ConnorDonegan/survey-HBM.
fit: A geostan_fit model object as returned from a call to one of the geostan::stan_* functions.
varname: Name of the modeled variable (a character string, as it appears in the model formula).
shape: An object of class sf or another spatial object coercible to sf with sf::st_as_sf.
probs: Lower and upper quantiles of the credible interval to plot.
plot: If FALSE, return a list of ggplots and a data.frame with the raw data values alongside a posterior summary of the modeled variable.
mc_style: Character string indicating how to plot the Moran coefficient for the delta values: if mc = "scatter", then moran_plot will be used with the marginal residuals; if mc = "hist", then a histogram of Moran coefficient values will be returned, where each plotted value represents the degree of residual autocorrelation in a draw from the join posterior distribution of delta values.
size: Size of points and lines, passed to geom_pointrange.
index: Integer value; use this if you wish to identify observations with the largest n=index absolute Delta values; data on the top n=index observations ordered by absolute Delta value will be printed to the console and the plots will be labeled with the indices of the identified observations.
style: Style of connectivity matrix; if w is not provided, style is passed to shape2mat and defaults to "W" for row-standardized.
w: An optional spatial connectivity matrix; if not provided, one will be created using shape2mat.
binwidth: A function with a single argument that will be passed to the binwidth argument in geom_histogram. The default is to set the width of bins to 0.5 * sd(x).
Returns
A grid of spatial diagnostic plots for measurement error models comparing the raw observations to the posterior distribution of the true values. Includes a point-interval plot of raw values and modeled values; a Moran scatter plot for delta = z - x where z are the survey estimates and x are the modeled values; and a map of the delta values (take at their posterior means).
Examples
library(sf)data(georgia)## binary adjacency matrixA <- shape2mat(georgia,"B")## prepare data for the CAR model, using WCAR specificationcars <- prep_car_data(A, style ="WCAR")## provide list of data for the measurement error modelME <- prep_me_data(se = data.frame(college = georgia$college.se), car_parts = cars)## sample from the prior probability model only, including the ME modelfit <- stan_glm(log(rate.male)~ college, ME = ME, data = georgia, prior_only =TRUE, iter =1e3,# for speed only chains =2,# for speed only refresh =0# silence some printing)## see ME diagnosticsme_diag(fit,"college", georgia)## see index values for the largest (absolute) delta values## (differences between raw estimate and the posterior mean)me_diag(fit,"college", georgia, index =3)