Skip to content

Commit

Permalink
Merge pull request #7 from USEPA/develop
Browse files Browse the repository at this point in the history
CRAN 0.3.0
  • Loading branch information
michaeldumelle authored Mar 10, 2023
2 parents 5d789ea + 17f78fd commit c4e4724
Show file tree
Hide file tree
Showing 173 changed files with 6,584 additions and 1,348 deletions.
6 changes: 3 additions & 3 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.2.0
Version: 0.3.0
Authors@R: c(
person(given = "Michael",
family = "Dumelle",
Expand All @@ -19,9 +19,9 @@ Authors@R: c(
Description: Fit, summarize, and predict for a variety of spatial statistical models
applied to point-referenced and areal (lattice) data. Parameters
are estimated using various methods. Additional modeling features include anisotropy,
random effects, partition factors, big data approaches, and more. Model-fit statistics are
non-spatial random effects, partition factors, big data approaches, and more. Model-fit statistics are
used to summarize, visualize, and compare models. Predictions at unobserved locations are
readily obtainable.
readily obtainable. For additional details, see Dumelle et al. (2023) <doi:10.1371/journal.pone.0282524>.
License: GPL-3
Encoding: UTF-8
LazyData: true
Expand Down
120 changes: 81 additions & 39 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# Generated by roxygen2: do not edit by hand

S3method(AIC,spmod)
S3method(AICc,spmod)
S3method(anova,spmod)
S3method(augment,spmod)
S3method(coef,spmod)
S3method(coefficients,spmod)
S3method(confint,spmod)
S3method(cooks.distance,spmod)
S3method(AIC,spautor)
S3method(AIC,splm)
S3method(AICc,spautor)
S3method(AICc,splm)
S3method(anova,spautor)
S3method(anova,splm)
S3method(augment,spautor)
S3method(augment,splm)
S3method(coef,spautor)
S3method(coef,splm)
S3method(coefficients,spautor)
S3method(coefficients,splm)
S3method(confint,spautor)
S3method(confint,splm)
S3method(cooks.distance,spautor)
S3method(cooks.distance,splm)
S3method(cov_initial_search,car)
S3method(cov_initial_search,cauchy)
S3method(cov_initial_search,circular)
Expand All @@ -27,11 +35,16 @@ S3method(cov_initial_search,sar)
S3method(cov_initial_search,spherical)
S3method(cov_initial_search,triangular)
S3method(cov_initial_search,wave)
S3method(covmatrix,spmod)
S3method(deviance,spmod)
S3method(fitted,spmod)
S3method(fitted.values,spmod)
S3method(formula,spmod)
S3method(covmatrix,spautor)
S3method(covmatrix,splm)
S3method(deviance,spautor)
S3method(deviance,splm)
S3method(fitted,spautor)
S3method(fitted,splm)
S3method(fitted.values,spautor)
S3method(fitted.values,splm)
S3method(formula,spautor)
S3method(formula,splm)
S3method(get_initial_range,cauchy)
S3method(get_initial_range,circular)
S3method(get_initial_range,cosine)
Expand All @@ -49,9 +62,12 @@ S3method(get_initial_range,rquad)
S3method(get_initial_range,spherical)
S3method(get_initial_range,triangular)
S3method(get_initial_range,wave)
S3method(glance,spmod)
S3method(glances,default)
S3method(glances,spmod_list)
S3method(glance,spautor)
S3method(glance,splm)
S3method(glances,spautor)
S3method(glances,spautor_list)
S3method(glances,splm)
S3method(glances,splm_list)
S3method(gloglik_products,car)
S3method(gloglik_products,cauchy)
S3method(gloglik_products,circular)
Expand All @@ -71,25 +87,44 @@ S3method(gloglik_products,sar)
S3method(gloglik_products,spherical)
S3method(gloglik_products,triangular)
S3method(gloglik_products,wave)
S3method(hatvalues,spmod)
S3method(influence,spmod)
S3method(labels,spmod)
S3method(logLik,spmod)
S3method(loocv,spmod)
S3method(model.frame,spmod)
S3method(model.matrix,spmod)
S3method(plot,spmod)
S3method(predict,spmod)
S3method(predict,spmodRF)
S3method(predict,spmodRF_list)
S3method(predict,spmod_list)
S3method(print,anova.spmod)
S3method(print,spmod)
S3method(print,summary.spmod)
S3method(pseudoR2,spmod)
S3method(resid,spmod)
S3method(residuals,spmod)
S3method(rstandard,spmod)
S3method(hatvalues,spautor)
S3method(hatvalues,splm)
S3method(influence,spautor)
S3method(influence,splm)
S3method(labels,spautor)
S3method(labels,splm)
S3method(logLik,spautor)
S3method(logLik,splm)
S3method(loocv,spautor)
S3method(loocv,splm)
S3method(model.frame,spautor)
S3method(model.frame,splm)
S3method(model.matrix,spautor)
S3method(model.matrix,splm)
S3method(plot,spautor)
S3method(plot,splm)
S3method(predict,spautor)
S3method(predict,spautorRF)
S3method(predict,spautorRF_list)
S3method(predict,spautor_list)
S3method(predict,splm)
S3method(predict,splmRF)
S3method(predict,splmRF_list)
S3method(predict,splm_list)
S3method(print,anova.spautor)
S3method(print,anova.splm)
S3method(print,spautor)
S3method(print,splm)
S3method(print,summary.spautor)
S3method(print,summary.splm)
S3method(pseudoR2,spautor)
S3method(pseudoR2,splm)
S3method(resid,spautor)
S3method(resid,splm)
S3method(residuals,spautor)
S3method(residuals,splm)
S3method(rstandard,spautor)
S3method(rstandard,splm)
S3method(spcov_matrix,car)
S3method(spcov_matrix,cauchy)
S3method(spcov_matrix,circular)
Expand Down Expand Up @@ -185,10 +220,16 @@ S3method(sprnorm,sar)
S3method(sprnorm,spherical)
S3method(sprnorm,triangular)
S3method(sprnorm,wave)
S3method(summary,spmod)
S3method(tidy,anova.spmod)
S3method(tidy,spmod)
S3method(vcov,spmod)
S3method(summary,spautor)
S3method(summary,splm)
S3method(tidy,anova.spautor)
S3method(tidy,anova.splm)
S3method(tidy,spautor)
S3method(tidy,splm)
S3method(varcomp,spautor)
S3method(varcomp,splm)
S3method(vcov,spautor)
S3method(vcov,splm)
export(AICc)
export(augment)
export(covmatrix)
Expand All @@ -207,6 +248,7 @@ export(splm)
export(splmRF)
export(sprnorm)
export(tidy)
export(varcomp)
import(Matrix)
importFrom(generics,augment)
importFrom(generics,glance)
Expand Down
35 changes: 34 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# spmodel 0.3.0

## Minor updates

* Added the `varcomp` function to compare variance components.
* Added an error message when there are `NA` values in predictors.
* Added an error message when the design (model) matrix is not invertible (i.e., perfect collinearities are detected).
* Added support for plotting anisotropic level curves of equal correlation when the `which` argument to `plot()` contains `8`.
* Renamed `residuals()` type `raw` to `response` to match `stats::lm()`.
* Changed class of `splm()` output to `"splm"` from `"spmod"` or `"splm_list"` from `"spmod_list"`.
* Changed class of `spautor()` output to `"spautor"` from `"spmod"` or `"spautor_list"` from `"spautor_list"`.
* Changed class of `splmRF()` output to `"splmRF"` from `"spmodRF"` or `"splmRF_list"` from `"spmodRF_list"`.
* Changed class of `spautorRF()` output to `"spautorRF"` from `"spmodRF"` or `"spautorRF_list"` from `"spmodRF_list"`.
* Methods corresponding to a generic function defined outside of `spmodel` are now all documented using
an `.spmodel` suffix, making it easier to find documentation of a particular
`spmodel` method for the generic function of interest.
* Added an error when random effect grouping variables or partition factors are numeric.
* Added an error when random effect or partition factor levels in `newdata` are not also in `data`.
* Updated citation information.

## Bug fixes

* Fixed a bug that produced irregular spacing in an error message for `spcov_initial()`.
* Fixed a bug that prevented proper display of row names when calling `predict()`
with `interval = "confidence"`.
* Fixed a bug that sometimes caused miscalculations in model-fitting and prediction
when random effect or partition factor variables were improperly coerced to a different type.
* Fixed bugs that sometimes caused miscalculations in certain model diagnostics.
* Fixed inconsistencies in several non-exported generic functions.
* Fixed a bug that prevented names from appearing with output from certain model diagnostics.

# spmodel 0.2.0

* `spmodel` v0.3.0 changed the names of `spmod`, `spmodRF`, `spmod_list`, and `spmodRF_list` objects.

## Minor updates

* `splm()` and `spautor()` allow multiple models to be fit when the `spcov_type` argument is a vector of length greater than one or the `spcov_initial` argument is a list (with length greater than one) of `spcov_initial` objects.
Expand All @@ -13,7 +46,7 @@
* Minor vignette updates.
* Minor documentation updates.

## Bug Fixes
## Bug fixes

* Fixed a bug that prevents display of spatial covariance type in summary of `spmod` objects.
* Fixed a bug that prevented prediction of factor variables when all levels of all factor variables did not appear in `newdata`.
Expand Down
24 changes: 17 additions & 7 deletions R/AIC.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#' to the objects and columns representing the number of parameters estimated
#' (\code{df}) and the AIC or AICc.
#'
#'
#' @method AIC spmod
#' @name AIC.spmodel
#' @method AIC splm
#' @order 1
#' @export
#'
Expand All @@ -49,7 +49,7 @@
#' )
#' AIC(spmod)
#' AICc(spmod)
AIC.spmod <- function(object, ..., k = 2) {
AIC.splm <- function(object, ..., k = 2) {

# set k as 2
k <- 2
Expand Down Expand Up @@ -126,17 +126,22 @@ AIC.spmod <- function(object, ..., k = 2) {
AIC_val
}

#' @rdname AIC.spmod
#' @rdname AIC.spmodel
#' @method AIC spautor
#' @export
AIC.spautor <- AIC.splm

#' @rdname AIC.spmodel
#' @export
AICc <- function(object, ..., k = 2) {
# method dispatch
UseMethod("AICc", object)
}

#' @rdname AIC.spmod
#' @method AICc spmod
#' @rdname AIC.spmodel
#' @method AICc splm
#' @export
AICc.spmod <- function(object, ..., k = 2) {
AICc.splm <- function(object, ..., k = 2) {

# set k as 2
k <- 2
Expand Down Expand Up @@ -211,3 +216,8 @@ AICc.spmod <- function(object, ..., k = 2) {
# return AICc value
AICc_val
}

#' @rdname AIC.spmodel
#' @method AICc spautor
#' @export
AICc.spautor <- AICc.splm
10 changes: 8 additions & 2 deletions R/PseudoR2.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
pseudoR2 <- function(object, ...) {
UseMethod("pseudoR2", object)
}

#' @rdname pseudoR2
#' @method pseudoR2 spmod
#' @method pseudoR2 splm
#' @export
pseudoR2.spmod <- function(object, adjust = FALSE, ...) {
pseudoR2.splm <- function(object, adjust = FALSE, ...) {
if (adjust) {
has_intercept <- "(Intercept)" %in% tidy(object)$term
pr2 <- object$pseudoR2
Expand All @@ -42,3 +43,8 @@ pseudoR2.spmod <- function(object, adjust = FALSE, ...) {
return(object$pseudoR2)
}
}

#' @rdname pseudoR2
#' @method pseudoR2 spautor
#' @export
pseudoR2.spautor <- pseudoR2.splm
23 changes: 16 additions & 7 deletions R/anova.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#' Then separate hypothesis tests are conducted. The easiest
#' way to obtain all possible coefficients is to run \code{tidy(object)$term}.
#'
#'
#' @details When one fitted model object is present, \code{anova()}
#' performs a general linear hypothesis test corresponding to some hypothesis
#' specified by a matrix of constraints. If \code{Terms} and \code{L} are not specified,
Expand Down Expand Up @@ -57,8 +56,8 @@
#' \code{tidy()} can be used
#' to obtain tidy tibbles of the \code{anova(object)} output.
#'
#'
#' @method anova spmod
#' @name anova.spmodel
#' @method anova splm
#' @order 1
#' @export
#'
Expand All @@ -81,7 +80,7 @@
#' spcov_type = "none"
#' )
#' tidy(anova(spmod, lmod))
anova.spmod <- function(object, ..., test = TRUE, Terms, L) {
anova.splm <- function(object, ..., test = TRUE, Terms, L) {


# see if one or two models
Expand Down Expand Up @@ -174,6 +173,11 @@ anova.spmod <- function(object, ..., test = TRUE, Terms, L) {
structure(anova_val, class = c(paste("anova", class(object), sep = "."), "data.frame"))
}

#' @rdname anova.spmodel
#' @method anova spautor
#' @export
anova.spautor <- anova.splm

get_marginal_Chi2 <- function(L, object) {
# make matrix if a numeric vector
if (!is.matrix(L)) {
Expand All @@ -198,12 +202,12 @@ get_marginal_Chi2 <- function(L, object) {
Chi2_df
}

#' @rdname anova.spmod
#' @rdname anova.spmodel
#' @param x An object from \code{anova(object)}.
#'
#' @method tidy anova.spmod
#' @method tidy anova.splm
#' @export
tidy.anova.spmod <- function(x, ...) {
tidy.anova.splm <- function(x, ...) {
if (!is.null(attr(x, "full")) && !is.null(attr(x, "reduced"))) {
result <- tibble::tibble(full = attr(x, "full"), reduced = attr(x, "reduced"), df = x$Df, statistic = x$Chi2)
} else {
Expand All @@ -214,3 +218,8 @@ tidy.anova.spmod <- function(x, ...) {
}
result
}

#' @rdname anova.spmodel
#' @method tidy anova.spautor
#' @export
tidy.anova.spautor <- tidy.anova.splm
Loading

0 comments on commit c4e4724

Please sign in to comment.