>.
diff --git a/NEWS.md b/NEWS.md
index 7dbbf7db..8ac21852 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -4,7 +4,7 @@
geostan now supports Poisson models with censored count data, a common problem in public health research where small area disease and mortality counts are censored below a threshold value. Model for censored outcome data can now be implemented using the `censor_point` argument found in all of the model fitting functions (stan_glm, stan_car, stan_esf, stan_icar).
-## measurement error models improved
+## Measurement error models improved
The measurement error models have been updated in three important respects:
diff --git a/R/convenience-functions.R b/R/convenience-functions.R
index b270d4e3..9cd032fd 100644
--- a/R/convenience-functions.R
+++ b/R/convenience-functions.R
@@ -328,7 +328,8 @@ lisa <- function(x, w, type = TRUE) {
#' @param shape An object of class \code{sf} or another spatial object coercible to \code{sf} with \code{sf::st_as_sf} such as \code{SpatialPolygonsDataFrame}.
#' @param name The name to use on the plot labels; default to "y" or, if \code{y} is a \code{geostan_fit} object, to "Residuals".
#' @param plot If \code{FALSE}, return a list of \code{gg} plots.
-#' @param mc Character string indicating how to plot the residual Moran coefficient: if `mc = "scatter"`, then \code{\link[geostan]{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 model parameters.
+#'
+#' @param mc_style Character string indicating how to plot the residual Moran coefficient (only used if `y` is a fitted model): if `mc = "scatter"`, then \code{\link[geostan]{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 model parameters.
#'
#' @param style Style of connectivity matrix; if `w` is not provided, `style` is passed to \code{\link[geostan]{shape2mat}} and defaults to "W" for row-standardized.
#' @param w An optional spatial connectivity matrix; if not provided, one will be created using \code{\link[geostan]{shape2mat}}.
@@ -368,7 +369,7 @@ sp_diag <- function(y,
shape,
name = "y",
plot = TRUE,
- mc = c("scatter", "hist"),
+ mc_style = c("scatter", "hist"),
style = c("W", "B"),
w = shape2mat(shape, match.arg(style)),
binwidth = function(x) 0.5 * sd(x),
@@ -393,14 +394,14 @@ sp_diag.geostan_fit <- function(y,
shape,
name = "Residual",
plot = TRUE,
- mc = c("scatter", "hist"),
+ mc_style = c("scatter", "hist"),
style = c("W", "B"),
w = shape2mat(shape, match.arg(style)),
binwidth = function(x) 0.5 * stats::sd(x),
rates = TRUE,
size = 0.15,
...) {
- mc <- match.arg(mc)
+ mc_style <- match.arg(mc_style, c("scatter", "hist"))
if (!inherits(shape, "sf")) shape <- sf::st_as_sf(shape)
outcome <- y$data[,1]
fits <- fitted(y, summary = TRUE, rates = rates)
@@ -432,13 +433,9 @@ sp_diag.geostan_fit <- function(y,
label = signs::signs) +
theme_void()
# residual autocorrelation
-
R <- residuals(y, summary = FALSE)
R.mc <- apply(R, 1, mc, w = w)
- if (length(unique(R.mc)) == 1) {
- g.mc <- moran_plot(R[1,], w, xlab = name)
- }
- if (mc == "scatter") {
+ if (mc_style == "scatter") {
g.mc <- moran_plot(marginal_residual, w, xlab = name)
} else {
R.mc.mu <- mean(R.mc)
@@ -453,6 +450,9 @@ sp_diag.geostan_fit <- function(y,
x = "Residual MC",
subtitle = paste0("MC (mean) = ", round(R.mc.mu, 2)))
}
+ if (length(unique(R.mc)) == 1) {
+ g.mc <- moran_plot(R[1,], w, xlab = name)
+ }
if (plot) {
return( gridExtra::grid.arrange(ovf, g.mc, map.y, ncol = 3) )
} else {
@@ -512,7 +512,7 @@ sp_diag.numeric <- function(y,
#' @param probs Lower and upper quantiles of the credible interval to plot.
#' @param plot If \code{FALSE}, return a list of \code{ggplot}s and a \code{data.frame} with the raw data values alongside a posterior summary of the modeled variable.
#'
-#' @param mc Character string indicating how to plot the Moran coefficient for the delta values: if `mc = "scatter"`, then \code{\link[geostan]{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.
+#' @param mc_style Character string indicating how to plot the Moran coefficient for the delta values: if `mc = "scatter"`, then \code{\link[geostan]{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.
#'
#' @param size Size of points and lines, passed to \code{geom_pointrange}.
#' @param 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.
@@ -570,7 +570,7 @@ me_diag <- function(fit,
shape,
probs = c(0.025, 0.975),
plot = TRUE,
- mc = c("scatter", "hist"),
+ mc_style = c("scatter", "hist"),
size = 0.25,
index = 0,
style = c("W", "B"),
@@ -580,7 +580,7 @@ me_diag <- function(fit,
stopifnot(length(varname) == 1)
if (!varname %in% colnames(fit$data)) stop("varname is not found in colnames(fit$data). Provide the name of the variable as it appears in the model formula")
if (!inherits(shape, "sf")) shape <- sf::st_as_sf(shape)
- mc <- match.arg(mc)
+ mc_style <- match.arg(mc_style, c("scatter", "hist"))
x.raw <- as.numeric(fit$data[,varname])
probs = sort(probs)
width = paste0(100 * (probs[2] - probs[1]), "%")
@@ -624,11 +624,11 @@ me_diag <- function(fit,
theme_classic()
delta.mat <- t(apply(x.samples, 1, .resid, y = x.raw))
df$Delta <- apply(delta.mat, 2, mean)
- if (mc == "scatter") {
+ D.mc <- apply(delta.mat, 1, mc, w = w)
+ D.mc.mu <- mean(D.mc)
+ if (mc_style == "scatter") {
g.mc <- moran_plot(df$Delta, w, xlab = bquote(hat(Delta)))
} else {
- D.mc <- apply(delta.mat, 1, mc, w = w)
- D.mc.mu <- mean(D.mc)
g.mc <- ggplot() +
geom_histogram(aes(D.mc),
binwidth = binwidth(as.numeric(D.mc)),
diff --git a/README.Rmd b/README.Rmd
index 892d836c..d995cceb 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -19,29 +19,38 @@ knitr::opts_chunk$set(
-# geostan
+## geostan: Bayesian spatial analysis
The **geostan** R package supports a complete spatial analysis
workflow with hierarchical Bayesian models (HBMs) for areal
-data and a variety of functions for visualizing spatial data and model results.
+data, including a variety of functions for visualizing spatial data and model results.
+
+The package is designed primarily to support public health research with spatial data;
+see the [**surveil**](https://connordonegan.github.io/surveil) R package for time series analysis of public health surveillance data.
+
+**geostan** is an interface to [**Stan**](https://mc-stan.org), a state-of-the-art platform for Bayesian inference.
### Disease mapping and spatial regression
-Model small-area incidence rates with mortality or disease data recorded across areal units like counties or census tracts.
+Model small-area incidence rates with mortality or disease data recorded across areal units like states, counties, or census tracts.
### Observational uncertainty
-Incorporate information on data reliability into any **geostan** model. Built specifically for American Community Survey (ACS) data.
+Incorporate information on data reliability, such as standard errors of American Community Survey estimates, into any **geostan** model.
+
+### Censored observations
+
+Vital statistics and disease surveillance systems like CDC Wonder censor case counts that fall below a threshold number; **geostan** can provide probability distributions for disease or mortality risk across all areas, censored or not.
### Spatial analysis tools
-Tools for visualizing and measuring spatial autocorrelation and map patterns, for exploratory analysis and model diagnostics.
+Tools for visualizing and measuring spatial autocorrelation and map patterns, for exploratory analysis and model diagnostics. Visual diagnostics also support the evaluation of survey data quality and observational error models.
### The RStan ecosystem
Compatible with a suite of high-quality R packages for Bayesian inference and model evaluation.
-### Custom Stan models
+### Custom spatial models
Tools for building custom spatial models in [Stan](https://mc-stan.org/).
@@ -54,26 +63,3 @@ if (!require(drat)) install.packages("drat")
drat::addRepo("connordonegan")
install.packages("geostan")
```
-
-## Resources
-
-For demonstration analyses and some additional discussion, see the vignettes on the package [website](https://connordonegan.github.io/geostan/) and the package help pages (e.g., run `?stan_car` in R).
-
-## Citation
-
- * Donegan, Connor (2021). geostan: Bayesian Spatial Analysis. R package Version 0.1.1 https://connordonegan.github.io/geostan/
-
- * Donegan, Connor, Yongwan Chun, and Daniel A. Griffith. Modeling community health with areal data: Bayesian inference with survey standard errors and spatial structure. International Journal of Environmental Research and Public Health 18.13 (2021): 6856. DOI: 10.3390/ijerph18136856
-
-
-**geostan** is an interface to **Stan**:
-
- * Carpenter B., Gelman A., Hoffman M. D., Lee D., Goodrich B., Betancourt M., Brubaker M., Guo J., Li P., and Riddell A. (2017). Stan: A probabilistic programming language. Journal of Statistical Software. 76(1). DOI: 10.18637/jss.v076.i01
-
-## Credit
-
-The **geostan** package was built with the help of **rstantools**:
-
- * Gabry, Jonah, Ben Goodrich, and Martin Lysy (2021). rstantools: Tools for Developing R Packages Interfacing with 'Stan'. R package version 2.1.1 https://mc-stan.org/rstantools/index.html
-
-
diff --git a/README.html b/README.html
index 16f72f33..c972fc14 100644
--- a/README.html
+++ b/README.html
@@ -602,41 +602,29 @@
-
+
-geostan
-The geostan R package supports a complete spatial analysis workflow with hierarchical Bayesian models (HBMs) for areal data and a variety of functions for visualizing spatial data and model results.
+geostan: Bayesian spatial analysis
+The geostan R package supports a complete spatial analysis workflow with hierarchical Bayesian models (HBMs) for areal data, including a variety of functions for visualizing spatial data and model results.
+The package is designed primarily to support public health research with spatial data; see the surveil R package for time series analysis of public health surveillance data.
+geostan is an interface to Stan, a state-of-the-art platform for Bayesian inference.
Disease mapping and spatial regression
-Model small-area incidence rates with mortality or disease data recorded across areal units like counties or census tracts.
+Model small-area incidence rates with mortality or disease data recorded across areal units like states, counties, or census tracts.
Observational uncertainty
-Incorporate information on data reliability into any geostan model. Built specifically for American Community Survey (ACS) data.
+Incorporate information on data reliability, such as standard errors of American Community Survey estimates, into any geostan model.
+Censored observations
+Vital statistics and disease surveillance systems like CDC Wonder censor case counts that fall below a threshold number; geostan can provide probability distributions for disease or mortality risk across all areas, censored or not.
-Tools for visualizing and measuring spatial autocorrelation and map patterns, for exploratory analysis and model diagnostics.
+Tools for visualizing and measuring spatial autocorrelation and map patterns, for exploratory analysis and model diagnostics. Visual diagnostics also support the evaluation of survey data quality and observational error models.
The RStan ecosystem
Compatible with a suite of high-quality R packages for Bayesian inference and model evaluation.
-Custom Stan models
+Custom spatial models
Tools for building custom spatial models in Stan.
Installation
Install geostan using:
-Resources
-For demonstration analyses and some additional discussion, see the vignettes on the package website and the package help pages (e.g., run ?stan_car
in R).
-Citation
-
-Donegan, Connor (2021). geostan: Bayesian Spatial Analysis. R package Version 0.1.1 https://connordonegan.github.io/geostan/
-Donegan, Connor, Yongwan Chun, and Daniel A. Griffith. Modeling community health with areal data: Bayesian inference with survey standard errors and spatial structure. International Journal of Environmental Research and Public Health 18.13 (2021): 6856. DOI: 10.3390/ijerph18136856
-
-geostan is an interface to Stan:
-
-- Carpenter B., Gelman A., Hoffman M. D., Lee D., Goodrich B., Betancourt M., Brubaker M., Guo J., Li P., and Riddell A. (2017). Stan: A probabilistic programming language. Journal of Statistical Software. 76(1). DOI: 10.18637/jss.v076.i01
-
-Credit
-The geostan package was built with the help of rstantools:
-