Skip to content

Commit

Permalink
Merge pull request #12 from USEPA/develop
Browse files Browse the repository at this point in the history
CRAN Version 0.5.0
  • Loading branch information
michaeldumelle authored Oct 25, 2023
2 parents af015e1 + 6299881 commit 097755e
Show file tree
Hide file tree
Showing 167 changed files with 9,632 additions and 3,091 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
^_pkgdown\.yml$
^docs$
^pkgdown$
^vignettes/articles$
^CRAN-SUBMISSION$
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
Expand All @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
Expand All @@ -29,9 +29,9 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v1
- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
Expand All @@ -41,22 +41,9 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: rcmdcheck

- uses: r-lib/actions/setup-tinytex@v1
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
build_args: '"--compact-vignettes=both"'

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload check results
if: always()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
upload-snapshots: true
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: spmodel
Title: Spatial Statistical Modeling and Prediction
Version: 0.4.0
Version: 0.5.0
Authors@R: c(
person(given = "Michael",
family = "Dumelle",
Expand All @@ -21,7 +21,7 @@ License: GPL-3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
Depends:
R (>= 3.5.0)
Imports:
Expand Down
24 changes: 24 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# spmodel 0.5.0

## Minor updates

* Predictions can now be made for prediction locations whose random effect levels are not present in the observed data
* When this occurs, the random-effect covariance between the observed data and these prediction locations is assumed to be zero.
* The default for `local = TRUE` in `splm()` and `spglm()` now uses the `kmeans` assignment method with group sizes approximately equal to 100.
* Previously, the `random` assignment method was used with group sizes approximately equal to 50.
* The default for `local = TRUE` in `predict()` and `augment()` now uses 100 local neighbors.
* Previously, 50 local neighbors were used.
* Moved the "A Detailed Guide to `spmodel`" and "Technical Details" vignettes to the package website.
* Added a "Spatial Generalized Linear Models in `spmodel`" vignette to the package website.
* Changed name of "An Overview of Basic Features in `spmodel`" vignette to "An Introduction to `spmodel`" and changed output type from PDF to HTML.
* Other minor vignette updates.
* Minor documentation updates.

## Bug fixes

* Fixed a bug that occurred with prediction for success/failure binomial data (e.g., Bernoulli data) when `local` in `predict()` was `TRUE`.
* Fixed a bug that could affect simulating data using `sprbinom()` when the `size` argument was different from `1`.
* Fixed a bug that could cause local prediction to fail when only one level of a random effect was present in the prediction site's local neighborhood.
* Fixed a bug that could cause an error when local estimation was used for the `"sv-wls"` estimation method.
* Fixed a bug that caused undesirable behavior from `tidy()` when `conf.level` was less than zero or greater than one.

# spmodel 0.4.0

## Major updates
Expand Down
20 changes: 10 additions & 10 deletions R/augment.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@
#'
#' @return When augmenting the original data set, a tibble with additional columns
#' \itemize{
#' \item{\code{.fitted}}{ Fitted value}
#' \item{\code{.resid}}{ Response residual (the difference between observed and fitted values)}
#' \item{\code{.hat}}{ Leverage (diagonal of the hat matrix)}
#' \item{\code{.cooksd}}{ Cook's distance}
#' \item{\code{.std.resid}}{ Standardized residuals}
#' \item{\code{.se.fit}}{ Standard error of the fitted value.}
#' \item \code{.fitted} Fitted value
#' \item \code{.resid} Response residual (the difference between observed and fitted values)
#' \item \code{.hat} Leverage (diagonal of the hat matrix)
#' \item \code{.cooksd} Cook's distance
#' \item \code{.std.resid} Standardized residuals
#' \item \code{.se.fit} Standard error of the fitted value.
#' }
#'
#' When augmenting a new data set, a tibble with additional columns
#' \itemize{
#' \item{\code{.fitted}}{ Predicted (or fitted) value}
#' \item{\code{.lower}}{ Lower bound on interval}
#' \item{\code{.upper}}{ Upper bound on interval}
#' \item{\code{.se.fit}}{ Standard error of the predicted (or fitted) value}
#' \item \code{.fitted} Predicted (or fitted) value
#' \item \code{.lower} Lower bound on interval
#' \item \code{.upper} Upper bound on interval
#' \item \code{.se.fit} Standard error of the predicted (or fitted) value
#' }
#'
#' @name augment.spmodel
Expand Down
2 changes: 1 addition & 1 deletion R/cov_estimate_sv.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param optim_dotlist The optim dotlist
#' @param esv_dotlist The empirical semivariogram dotlist
#'
#' @return
#' @return Covariance parameter estimates
#'
#' @noRd
cov_estimate_sv <- function(data_object, formula, spcov_initial, estmethod,
Expand Down
6 changes: 6 additions & 0 deletions R/cov_initial_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ cov_initial_search.exponential <- function(spcov_initial_NA, estmethod, data_obj
))
}, SIMPLIFY = FALSE)
esv_vals <- do.call("rbind", esv_vals)
esv_vals <- esv_vals[esv_vals$np > 0, , drop = FALSE]
esv_vals$bins <- droplevels(esv_vals$bins)
esv_val <- data.frame(
bins = levels(esv_vals$bins),
dist = tapply(esv_vals$dist, esv_vals$bins, function(x) mean(x, na.rm = TRUE)),
Expand Down Expand Up @@ -365,6 +367,8 @@ cov_initial_search.none <- function(spcov_initial_NA, estmethod, data_object,
))
}, SIMPLIFY = FALSE)
esv_vals <- do.call("rbind", esv_vals)
esv_vals <- esv_vals[esv_vals$np > 0, , drop = FALSE]
esv_vals$bins <- droplevels(esv_vals$bins)
esv_val <- data.frame(
bins = levels(esv_vals$bins),
dist = tapply(esv_vals$dist, esv_vals$bins, function(x) mean(x, na.rm = TRUE)),
Expand Down Expand Up @@ -637,6 +641,8 @@ cov_initial_search.matern <- function(spcov_initial_NA, estmethod, data_object,
))
}, SIMPLIFY = FALSE)
esv_vals <- do.call("rbind", esv_vals)
esv_vals <- esv_vals[esv_vals$np > 0, , drop = FALSE]
esv_vals$bins <- droplevels(esv_vals$bins)
esv_val <- data.frame(
bins = levels(esv_vals$bins),
dist = tapply(esv_vals$dist, esv_vals$bins, function(x) mean(x, na.rm = TRUE)),
Expand Down
88 changes: 44 additions & 44 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
#' @format An \code{sf} object with 365 rows and 10 columns:
#'
#' \itemize{
#' \item{sample: }{A factor with a sample identifier. Some samples were
#' \item sample: A factor with a sample identifier. Some samples were
#' replicated in the field or laboratory. As a result, there are 318 unique
#' sample identifiers.}
#' \item{field_dup: }{A factor representing field duplicate. Takes values \code{1}
#' and \code{2}.}
#' \item{lab_rep: }{A factor representing laboratory replicate. Takes values \code{1}
#' and \code{2}.}
#' \item{year: }{A factor representing year. Takes values \code{2001} and \code{2006}.}
#' \item{sideroad: }{A factor representing direction relative to the haul road.
#' sample identifiers.
#' \item field_dup: A factor representing field duplicate. Takes values \code{1}
#' and \code{2}.
#' \item lab_rep: A factor representing laboratory replicate. Takes values \code{1}
#' and \code{2}.
#' \item year: A factor representing year. Takes values \code{2001} and \code{2006}.
#' \item sideroad: A factor representing direction relative to the haul road.
#' Takes values \code{N} (north of the haul road) and \code{S} (south
#' of the haul road).}
#' \item{log_dist2road: }{The log of distance (in meters) to the haul road.}
#' \item{log_Zn: }{The log of zinc concentration in moss tissue (mg/kg).}
#' \item{geometry: }{\code{POINT} geometry representing coordinates in an Alaska
#' Albers projection (EPSG: 3338).}
#' of the haul road).
#' \item log_dist2road: The log of distance (in meters) to the haul road.
#' \item log_Zn: The log of zinc concentration in moss tissue (mg/kg).
#' \item geometry: \code{POINT} geometry representing coordinates in an Alaska
#' Albers projection (EPSG: 3338).
#' }
#' @source Data were obtained from Peter Neitlich and Linda Hasselbach of the National
#' Park Service. Data were used in the publications listed in References.
Expand All @@ -43,13 +43,13 @@
#'
#' @format A \code{tibble} with 30 rows and 5 columns:
#' \itemize{
#' \item{water: }{A factor representing whether water was added. Takes values
#' \code{N} (no water added) and \code{Y} (water added).}
#' \item{tarp: }{A factor representing tarp cover. Takes values \code{clear}
#' (a clear tarp), \code{shade} (a shade tarp), and \code{none} (no tarp).}
#' \item{z: }{The percentage of nitrogen.}
#' \item{x: }{The x-coordinate.}
#' \item{y: }{The y-coordinate.}
#' \item water: A factor representing whether water was added. Takes values
#' \code{N} (no water added) and \code{Y} (water added).
#' \item tarp: A factor representing tarp cover. Takes values \code{clear}
#' (a clear tarp), \code{shade} (a shade tarp), and \code{none} (no tarp).
#' \item z: The percentage of nitrogen.
#' \item x: The x-coordinate.
#' \item y: The y-coordinate.
#' }
#' @source These data were provided by Elizabeth Lenart of the Alaska Department
#' of Fish and Game. The data were used in the publication listed in References.
Expand All @@ -63,10 +63,10 @@
#' @description Estimated harbor-seal trends from abundance data in southeast Alaska, USA.
#'
#' @format A \code{sf} object with 62 rows and 2 columns:
#' \describe{
#' \item{log_trend: }{The log of the estimated harbor-seal trends from abundance data.}
#' \item{geometry: }{\code{POLYGON} geometry representing polygons in an Alaska
#' Albers projection (EPSG: 3338).}
#' \itemize{
#' \item log_trend: The log of the estimated harbor-seal trends from abundance data.
#' \item geometry: \code{POLYGON} geometry representing polygons in an Alaska
#' Albers projection (EPSG: 3338).
#' }
#' @source These data were collected by the Polar Ecosystem Program of the Marine
#' Mammal Laboratory of the Alaska Fisheries Science Center of NOAA Fisheries.
Expand All @@ -82,10 +82,10 @@
#' @description Sulfate atmospheric deposition in the conterminous USA.
#'
#' @format An \code{sf} object with 197 rows and 2 columns.
#' \describe{
#' \item{sulfate: }{Total wet deposition sulfate in kilograms per hectare.}
#' \item{geometry: }{\code{POINT} geometry representing coordinates in a
#' Conus Albers projection (EPSG: 5070).}
#' \itemize{
#' \item sulfate: Total wet deposition sulfate in kilograms per hectare.
#' \item geometry: \code{POINT} geometry representing coordinates in a
#' Conus Albers projection (EPSG: 5070).
#' }
#' @source
#' These data were used in the publication listed in References. Data were downloaded from the
Expand All @@ -101,9 +101,9 @@
#' @description Locations at which to predict sulfate atmospheric deposition in the conterminous USA.
#'
#' @format An \code{sf} object with 197 rows and 1 column.
#' \describe{
#' \item{geometry: }{\code{POINT} geometry representing coordinates in a
#' Conus Albers projection (EPSG: 5070).}
#' \itemize{
#' \item geometry: \code{POINT} geometry representing coordinates in a
#' Conus Albers projection (EPSG: 5070).
#' }
#' @source
#' These data were used in the publication listed in References. Data were downloaded from
Expand All @@ -119,14 +119,14 @@
#' @description Moose counts and presence in Alaska, USA.
#'
#' @format An \code{sf} object with 218 rows and 5 columns.
#' \describe{
#' \item{elev: }{The elevation.}
#' \item{strat: }{A factor representing strata (used for sampling). Can take values \code{L} and \code{M}.}
#' \item{count: }{The count (number) of moose observed.}
#' \item{presence: }{A binary factor representing whether no moose were observed (value \code{0}) or at least one moose was observed
#' (value \code{1}).}
#' \item{geometry: }{\code{POINT} geometry representing coordinates in an Alaska
#' Albers projection (EPSG: 3338).}
#' \itemize{
#' \item elev: The elevation.
#' \item strat: A factor representing strata (used for sampling). Can take values \code{L} and \code{M}.
#' \item count: The count (number) of moose observed.
#' \item presence: A binary factor representing whether no moose were observed (value \code{0}) or at least one moose was observed
#' (va ue \code{1}).
#' \item geometry: \code{POINT} geometry representing coordinates in an Alaska
#' Albers projection (EPSG: 3338).
#' }
#' @source
#' Alaska Department of Fish and Game, Division of Wildlife Conservation has released
Expand All @@ -138,11 +138,11 @@
#' @description Locations at which to predict moose counts and presence in Alaska, USA.
#'
#' @format An \code{sf} object with 100 rows and 3 columns.
#' \describe{
#' \item{elev: }{The elevation.}
#' \item{strat: }{A factor representing strata (used for sampling). Can take values \code{L} and \code{M}.}
#' \item{geometry: }{\code{POINT} geometry representing coordinates in an Alaska
#' Albers projection (EPSG: 3338).}
#' \itemize{
#' \item elev: The elevation.
#' \item strat: A factor representing strata (used for sampling). Can take values \code{L} and \code{M}.
#' \item geometry: \code{POINT} geometry representing coordinates in an Alaska
#' Albers projection (EPSG: 3338).
#' }
#' @source
#' Alaska Department of Fish and Game, Division of Wildlife Conservation has released
Expand Down
14 changes: 7 additions & 7 deletions R/dispersion_initial.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#' The variance function of an individual \eqn{y} (given \eqn{\mu})
#' for each generalized linear model family is given below:
#' \itemize{
#' \item{family: }{\eqn{Var(y)}}
#' \item{poisson: }{\eqn{\mu \phi}}
#' \item{nbinomial: }{\eqn{\mu + \mu^2 / \phi}}
#' \item{binomial: }{\eqn{n \mu (1 - \mu) \phi}}
#' \item{beta: }{\eqn{\mu (1 - \mu) / (1 + \phi)}}
#' \item{Gamma: }{\eqn{\mu^2 / \phi}}
#' \item{inverse.gaussian: }{\eqn{\mu^2 / \phi}}
#' \item family: \eqn{Var(y)}
#' \item poisson: \eqn{\mu \phi}
#' \item nbinomial: \eqn{\mu + \mu^2 / \phi}
#' \item binomial: \eqn{n \mu (1 - \mu) \phi}
#' \item beta: \eqn{\mu (1 - \mu) / (1 + \phi)}
#' \item Gamma: \eqn{\mu^2 / \phi}
#' \item inverse.gaussian: \eqn{\mu^2 / \phi}
#' }
#' The parameter \eqn{\phi} is a dispersion parameter that influences \eqn{Var(y)}.
#' For the \code{poisson} and \code{binomial} families, \eqn{\phi} is always
Expand Down
14 changes: 7 additions & 7 deletions R/dispersion_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#' @details The variance function of an individual \eqn{y} (given \eqn{\mu})
#' for each generalized linear model family is given below:
#' \itemize{
#' \item{family: }{\eqn{Var(y)}}
#' \item{poisson: }{\eqn{\mu \phi}}
#' \item{nbinomial: }{\eqn{\mu + \mu^2 / \phi}}
#' \item{binomial: }{\eqn{n \mu (1 - \mu) \phi}}
#' \item{beta: }{\eqn{\mu (1 - \mu) / (1 + \phi)}}
#' \item{Gamma: }{\eqn{\mu^2 / \phi}}
#' \item{inverse.gaussian: }{\eqn{\mu^2 / \phi}}
#' \item family: \eqn{Var(y)}
#' \item poisson: \eqn{\mu \phi}
#' \item nbinomial: \eqn{\mu + \mu^2 / \phi}
#' \item binomial: \eqn{n \mu (1 - \mu) \phi}
#' \item beta: \eqn{\mu (1 - \mu) / (1 + \phi)}
#' \item Gamma: \eqn{\mu^2 / \phi}
#' \item inverse.gaussian: \eqn{\mu^2 / \phi}
#' }
#' The parameter \eqn{\phi} is a dispersion parameter that influences \eqn{Var(y)}.
#' For the \code{poisson} and \code{binomial} families, \eqn{\phi} is always
Expand Down
3 changes: 2 additions & 1 deletion R/fitted.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#' @param object A fitted model object from [splm()], [spautor()], [spglm()], or [spgautor()].
#' @param type \code{"response"} for fitted values of the response, \code{"spcov"}
#' for fitted values of the spatial random errors, or \code{"randcov"} for
#' fitted values of the random effects. The default is \code{"response"}.
#' fitted values of the random effects. If from \code{spglm()} or \code{spgautor()},
#' \code{"link"} for fitted values on the link scale. The default is \code{"response"}.
#' @param ... Other arguments. Not used (needed for generic consistency).
#'
#' @details When \code{type} is \code{"response"}, the fitted values
Expand Down
8 changes: 4 additions & 4 deletions R/get_local_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ get_local_list_estimation <- function(local, data, xcoord, ycoord, n, partition_
if ("groups" %in% names_local) {
local$size <- ceiling(n / local$groups)
} else {
local$size <- 50
local$size <- 100
local$groups <- ceiling(n / local$size)
}
} else {
local$groups <- ceiling(n / local$size)
}
if (!"method" %in% names_local) {
local$method <- "random"
local$method <- "kmeans"
}
local$index <- get_local_estimation_index(local, data, xcoord, ycoord, n)
}
Expand Down Expand Up @@ -105,7 +105,7 @@ get_local_list_prediction <- function(local) {

if (is.logical(local)) {
if (local) {
local <- list(method = "covariance", size = 50)
local <- list(method = "covariance", size = 100)
} else {
local <- list(method = "all")
}
Expand All @@ -127,7 +127,7 @@ get_local_list_prediction <- function(local) {
}

if (local$method %in% c("distance", "covariance") && !"size" %in% names_local) {
local$size <- 50
local$size <- 100
}

if (!"parallel" %in% names_local) {
Expand Down
Loading

0 comments on commit 097755e

Please sign in to comment.