Skip to content

Commit 40ce490

Browse files
Merge pull request #31 from USEPA/develop
CRAN v0.9.0
2 parents 1c51dd5 + cd0bc08 commit 40ce490

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+835
-496
lines changed

NAMESPACE

+11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ S3method(cov_initial_search,cubic)
3838
S3method(cov_initial_search,exponential)
3939
S3method(cov_initial_search,gaussian)
4040
S3method(cov_initial_search,gravity)
41+
S3method(cov_initial_search,ie)
4142
S3method(cov_initial_search,jbessel)
4243
S3method(cov_initial_search,magnetic)
4344
S3method(cov_initial_search,matern)
@@ -57,6 +58,7 @@ S3method(cov_initial_search_glm,cubic)
5758
S3method(cov_initial_search_glm,exponential)
5859
S3method(cov_initial_search_glm,gaussian)
5960
S3method(cov_initial_search_glm,gravity)
61+
S3method(cov_initial_search_glm,ie)
6062
S3method(cov_initial_search_glm,jbessel)
6163
S3method(cov_initial_search_glm,magnetic)
6264
S3method(cov_initial_search_glm,matern)
@@ -95,6 +97,7 @@ S3method(get_initial_range,cubic)
9597
S3method(get_initial_range,exponential)
9698
S3method(get_initial_range,gaussian)
9799
S3method(get_initial_range,gravity)
100+
S3method(get_initial_range,ie)
98101
S3method(get_initial_range,jbessel)
99102
S3method(get_initial_range,magnetic)
100103
S3method(get_initial_range,matern)
@@ -125,6 +128,7 @@ S3method(gloglik_products,cubic)
125128
S3method(gloglik_products,exponential)
126129
S3method(gloglik_products,gaussian)
127130
S3method(gloglik_products,gravity)
131+
S3method(gloglik_products,ie)
128132
S3method(gloglik_products,jbessel)
129133
S3method(gloglik_products,magnetic)
130134
S3method(gloglik_products,matern)
@@ -156,6 +160,7 @@ S3method(laploglik_products,cubic)
156160
S3method(laploglik_products,exponential)
157161
S3method(laploglik_products,gaussian)
158162
S3method(laploglik_products,gravity)
163+
S3method(laploglik_products,ie)
159164
S3method(laploglik_products,jbessel)
160165
S3method(laploglik_products,magnetic)
161166
S3method(laploglik_products,matern)
@@ -236,6 +241,7 @@ S3method(spcov_matrix,cubic)
236241
S3method(spcov_matrix,exponential)
237242
S3method(spcov_matrix,gaussian)
238243
S3method(spcov_matrix,gravity)
244+
S3method(spcov_matrix,ie)
239245
S3method(spcov_matrix,jbessel)
240246
S3method(spcov_matrix,magnetic)
241247
S3method(spcov_matrix,matern)
@@ -257,6 +263,7 @@ S3method(spcov_optim2orig,cubic)
257263
S3method(spcov_optim2orig,exponential)
258264
S3method(spcov_optim2orig,gaussian)
259265
S3method(spcov_optim2orig,gravity)
266+
S3method(spcov_optim2orig,ie)
260267
S3method(spcov_optim2orig,jbessel)
261268
S3method(spcov_optim2orig,magnetic)
262269
S3method(spcov_optim2orig,matern)
@@ -276,6 +283,7 @@ S3method(spcov_orig2optim,cubic)
276283
S3method(spcov_orig2optim,exponential)
277284
S3method(spcov_orig2optim,gaussian)
278285
S3method(spcov_orig2optim,gravity)
286+
S3method(spcov_orig2optim,ie)
279287
S3method(spcov_orig2optim,jbessel)
280288
S3method(spcov_orig2optim,magnetic)
281289
S3method(spcov_orig2optim,matern)
@@ -294,6 +302,7 @@ S3method(spcov_vector,cubic)
294302
S3method(spcov_vector,exponential)
295303
S3method(spcov_vector,gaussian)
296304
S3method(spcov_vector,gravity)
305+
S3method(spcov_vector,ie)
297306
S3method(spcov_vector,jbessel)
298307
S3method(spcov_vector,magnetic)
299308
S3method(spcov_vector,matern)
@@ -312,6 +321,7 @@ S3method(sprnorm,cubic)
312321
S3method(sprnorm,exponential)
313322
S3method(sprnorm,gaussian)
314323
S3method(sprnorm,gravity)
324+
S3method(sprnorm,ie)
315325
S3method(sprnorm,jbessel)
316326
S3method(sprnorm,magnetic)
317327
S3method(sprnorm,matern)
@@ -423,6 +433,7 @@ importFrom(stats,model.frame)
423433
importFrom(stats,model.matrix)
424434
importFrom(stats,model.offset)
425435
importFrom(stats,model.response)
436+
importFrom(stats,na.fail)
426437
importFrom(stats,na.omit)
427438
importFrom(stats,na.pass)
428439
importFrom(stats,pchisq)

NEWS.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22

33
## Major Updates
44

5-
* Added the `range_constrain` argument to `splm()` and `spglm()` to contrain the range parameter to enhance numerical stability.
5+
* Added the `range_constrain` argument to `splm()` and `spglm()` to constrain the range parameter to enhance numerical stability. The default for `range_constrain` is `FALSE`, implying the range is not constrained.
6+
* Updated the `seal` data with additional polygons and a factor variable, `stock`, with two levels (`8` and `10`) that indicates seal stock (i.e., seal type).
7+
8+
## Minor Updates
9+
10+
* Changed diagonal tolerance threshold for `spglm()` and `spgautor()` model objects. See [this link](https://usepa.github.io/spmodel/articles/technical.html#sec:computational) for details.
11+
* Added the `"ie"` spatial covariance type to `splm()` and `spglm()` models. For `splm()` models, `"ie"` is an alias for `"none"`. For `spglm()` models, `"none"` now fixes both the `de` and `ie` covariance parameters at zero, while `"ie"` fixes the `de` covariance parameter at zero but allows the `ie` covariance parameter to vary. Thus, `"none"` from `spmodel $\le$ v0.8.0` matches `"ie"` from `spmodel` v0.9.0 and but is different from `"none"` from `spmodel v0.9.0`.
12+
* Added the `na.action` argument to `predict.spmodel()` functions to clarify that missing values in `newdata` return an error.
13+
* Minor documentation updates.
14+
15+
## Bug Fixes
16+
17+
* Fixed a bug that caused incorrect degrees of freedom for the likelihood ratio test (`anova(model1, model2)`) when `estmethod` is `"ml"` for both models.
18+
* Fixed a bug that caused an error in `anova(object1, object2)` when the name of `object1` had special characters (e.g., `$`).
619

720
# spmodel 0.8.0
821

@@ -149,7 +162,7 @@
149162
* Fixed a bug in `spautor()` that prevented an error from occurring when a partition factor was not categorical or not a factor
150163
* Fixed a bug in `covmatrix(object, newdata)` that returned a matrix with improper dimensions when `spcov_type` was `"none"`.
151164
* Fixed a bug in `predict()` that caused an error when at least one level of a fixed effect factor was not observed within a local neighborhood (when the `local` method was `"covariance"` or `"distance")`.
152-
* Fixed a bug in `cooks.distance()` that used the Pearson residuals instead of the standarized residuals.
165+
* Fixed a bug in `cooks.distance()` that used the Pearson residuals instead of the standardized residuals.
153166

154167
# spmodel 0.3.0
155168

R/anova.R

+9-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
#' tidy(anova(spmod, lmod))
8282
anova.splm <- function(object, ..., test = TRUE, Terms, L) {
8383

84-
8584
# see if one or two models
8685
object2_list <- list(...)
8786

@@ -139,13 +138,19 @@ anova.splm <- function(object, ..., test = TRUE, Terms, L) {
139138
stop("The fixed effect coefficients must be the same when performing a likeihood ratio test using the reml estimation method. To perform the likelihood ratio tests for different fixed effect and covariance coefficients simultaneously, refit the models using the ml estimation method.", call. = FALSE)
140139
}
141140
Chi2_stat <- abs(-2 * (logLik(object2) - logLik(object)))
142-
df_diff <- abs(object2$npar - object$npar)
141+
142+
# df for ml vs reml
143+
df1 <- object$npar
144+
df2 <- object2$npar
145+
if (object$estmethod == "ml") df1 <- df1 + object$p
146+
if (object2$estmethod == "ml") df2 <- df2 + object2$p
147+
df_diff <- abs(df1 - df2)
143148
p_value <- pchisq(Chi2_stat, df_diff, lower.tail = FALSE)
144149
if (object2$npar < object$npar) {
145-
full_name <- as.character(substitute(object))
150+
full_name <- deparse(substitute(object)) # replace as.character with deparse
146151
reduced_name <- as.character(as.list(substitute(list(...)))[-1])
147152
} else {
148-
reduced_name <- as.character(substitute(object))
153+
reduced_name <- deparse(substitute(object)) # replace as.character with deparse
149154
full_name <- as.character(as.list(substitute(list(...)))[-1])
150155
}
151156
if (test) {

R/cov_betahat_adjust.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cov_betahat_adjust <- function(invcov_betahat_list, betahat_list,
1818
randcov_params, cov_betahat_noadjust, var_adjust) {
1919
P <- length(betahat_list)
2020
# reset var_adjust if only one partition
21-
if (P == 1 || inherits(spcov_params, "none")) {
21+
if (P == 1 || inherits(spcov_params, c("none", "ie"))) {
2222
var_adjust <- "none"
2323
}
2424
# reset var_adjust if partitioning used but no local option used

R/cov_estimate_gloglik.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cov_estimate_gloglik_splm <- function(data_object, formula, spcov_initial, estme
1919
if (data_object$anisotropy) {
2020
dist_matrix_list <- NULL
2121
} else {
22-
if (inherits(spcov_initial, "none") && is.null(data_object$randcov_initial)) {
22+
if (inherits(spcov_initial, c("none", "ie")) && is.null(data_object$randcov_initial)) {
2323
dist_matrix_list <- NULL
2424
} else {
2525
dist_matrix_list <- lapply(data_object$obdata_list, function(x) spdist(x, data_object$xcoord, data_object$ycoord))

R/cov_initial_search.R

+3
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,9 @@ cov_initial_search.none <- function(spcov_initial_NA, estmethod, data_object,
585585
best_params
586586
}
587587

588+
#' @export
589+
cov_initial_search.ie <- cov_initial_search.none
590+
588591
#' @export
589592
cov_initial_search.matern <- function(spcov_initial_NA, estmethod, data_object,
590593
dist_matrix_list, weights,

R/cov_initial_search_glm.R

+3
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ cov_initial_search_glm.none <- function(spcov_initial_NA, dispersion_initial_NA,
461461
best_params
462462
}
463463

464+
#' @export
465+
cov_initial_search_glm.ie <- cov_initial_search_glm.none
466+
464467
#' @export
465468
cov_initial_search_glm.matern <- function(spcov_initial_NA, dispersion_initial_NA, estmethod, data_object,
466469
dist_matrix_list, weights,

R/data.R

+5-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@
6262
#'
6363
#' @description Estimated harbor-seal trends from abundance data in southeast Alaska, USA.
6464
#'
65-
#' @format A \code{sf} object with 62 rows and 2 columns:
65+
#' @format A \code{sf} object with 149 rows and 2 columns:
6666
#' \itemize{
6767
#' \item log_trend: The log of the estimated harbor-seal trends from abundance data.
68+
#' \item stock: A seal stock factor with two levels: 8 and 10. The factor levels indicate the
69+
#' type of seal stock (i.e., type of seal). Stocks 8 and 10 are two distinct stocks
70+
#' (out of 13 total stocks) in southeast Alaska.
6871
#' \item geometry: \code{POLYGON} geometry representing polygons in an Alaska
6972
#' Albers projection (EPSG: 3338).
7073
#' }
@@ -124,7 +127,7 @@
124127
#' \item strat: A factor representing strata (used for sampling). Can take values \code{L} and \code{M}.
125128
#' \item count: The count (number) of moose observed.
126129
#' \item presence: A binary factor representing whether no moose were observed (value \code{0}) or at least one moose was observed
127-
#' (va ue \code{1}).
130+
#' (value \code{1}).
128131
#' \item geometry: \code{POINT} geometry representing coordinates in an Alaska
129132
#' Albers projection (EPSG: 3338). Distances between points are in meters.
130133
#' }

R/get_data_object.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ get_data_object_splm <- function(formula, data, spcov_initial, xcoord, ycoord, e
3131
data_sf <- NULL
3232
}
3333

34-
if (!is_sf && missing(xcoord) && !inherits(spcov_initial, "none")) {
34+
if (!is_sf && missing(xcoord) && !inherits(spcov_initial, c("none", "ie"))) {
3535
stop("The xcoord argument must be specified.", call. = FALSE)
3636
}
3737

@@ -52,7 +52,7 @@ get_data_object_splm <- function(formula, data, spcov_initial, xcoord, ycoord, e
5252
ycoord_orig_name <- NULL
5353
ycoord_orig_val <- NULL
5454
# find coordinate dimension and set defaults
55-
if (inherits(spcov_initial, "none") && estmethod %in% c("reml", "ml")) {
55+
if (inherits(spcov_initial, c("none", "ie")) && estmethod %in% c("reml", "ml")) {
5656
dim_coords <- 0
5757
if (missing(xcoord)) {
5858
xcoord <- ".xcoord"
@@ -213,15 +213,15 @@ get_data_object_splm <- function(formula, data, spcov_initial, xcoord, ycoord, e
213213
# }
214214

215215
# range constrain
216-
max_range_scale <- 5
216+
max_range_scale <- 4
217217
range_constrain_value <- 2 * max_halfdist * max_range_scale
218218
if ("range" %in% names(spcov_initial$is_known)) {
219219
if (spcov_initial$is_known[["range"]] || (spcov_initial$initial[["range"]] > range_constrain_value)) {
220220
range_constrain <- FALSE
221221
}
222222
}
223223

224-
if (inherits(spcov_initial, "none")) {
224+
if (inherits(spcov_initial, c("none", "ie"))) {
225225
range_constrain <- FALSE
226226
}
227227

R/get_data_object_glm.R

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ get_data_object_spglm <- function(formula, family, data, spcov_initial, xcoord,
3232
data_sf <- NULL
3333
}
3434

35-
if (!is_sf && missing(xcoord) && !inherits(spcov_initial, "none")) {
35+
if (!is_sf && missing(xcoord) && !inherits(spcov_initial, c("none", "ie"))) {
3636
stop("The xcoord argument must be specified.", call. = FALSE)
3737
}
3838

@@ -53,7 +53,7 @@ get_data_object_spglm <- function(formula, family, data, spcov_initial, xcoord,
5353
ycoord_orig_name <- NULL
5454
ycoord_orig_val <- NULL
5555
# find coordinate dimension and set defaults
56-
if (inherits(spcov_initial, "none") && estmethod %in% c("reml", "ml")) {
56+
if (inherits(spcov_initial, c("none", "ie")) && estmethod %in% c("reml", "ml")) {
5757
dim_coords <- 0
5858
if (missing(xcoord)) {
5959
xcoord <- ".xcoord"
@@ -222,8 +222,8 @@ get_data_object_spglm <- function(formula, family, data, spcov_initial, xcoord,
222222
betahat <- backsolve(R_val, qr.qty(qr_val, y_trans))
223223
resid <- y_trans - X %*% betahat
224224
s2 <- sum(resid^2) / (n - p)
225-
# diagtol <- 1e-4
226-
diagtol <- min(1e-4, 1e-4 * s2)
225+
diagtol <- 1e-4
226+
# diagtol <- min(1e-4, 1e-4 * s2)
227227

228228

229229

@@ -233,15 +233,15 @@ get_data_object_spglm <- function(formula, family, data, spcov_initial, xcoord,
233233
max_halfdist <- sqrt((max(x_range) - min(x_range))^2 + (max(y_range) - min(y_range))^2) / 2
234234

235235
# range constrain
236-
max_range_scale <- 5
236+
max_range_scale <- 4
237237
range_constrain_value <- 2 * max_halfdist * max_range_scale
238238
if ("range" %in% names(spcov_initial$is_known)) {
239239
if (spcov_initial$is_known[["range"]] || (spcov_initial$initial[["range"]] > range_constrain_value)) {
240240
range_constrain <- FALSE
241241
}
242242
}
243243

244-
if (inherits(spcov_initial, "none")) {
244+
if (inherits(spcov_initial, c("none", "ie"))) {
245245
range_constrain <- FALSE
246246
}
247247

R/get_initial_range.R

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ get_initial_range.circular <- function(spcov_type, max_halfdist, ...) {
3333
get_initial_range.none <- function(spcov_type, max_halfdist, ...) {
3434
Inf
3535
}
36+
37+
#' @export
38+
get_initial_range.ie <- get_initial_range.none
39+
3640
#' @export
3741
get_initial_range.cubic <- function(spcov_type, max_halfdist, ...) {
3842
max_halfdist

R/get_spcov_params.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#'
88
#' @noRd
99
get_spcov_params <- function(spcov_type, spcov_orig_val) {
10-
if (spcov_type %in% c("exponential", "spherical", "gaussian", "triangular", "circular", "none", "cubic", "pentaspherical", "cosine", "wave", "jbessel", "gravity", "rquad", "magnetic")) {
10+
if (spcov_type %in% c("exponential", "spherical", "gaussian", "triangular", "circular", "none", "ie", "cubic", "pentaspherical", "cosine", "wave", "jbessel", "gravity", "rquad", "magnetic")) {
1111
spcov_params_val <- spcov_params(
1212
spcov_type = spcov_type,
1313
de = spcov_orig_val[["de"]],

R/gloglik_products.R

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ gloglik_products.circular <- gloglik_products.exponential
8585
#' @export
8686
gloglik_products.none <- gloglik_products.exponential
8787
#' @export
88+
gloglik_products.ie <- gloglik_products.none
89+
#' @export
8890
gloglik_products.cubic <- gloglik_products.exponential
8991
#' @export
9092
gloglik_products.pentaspherical <- gloglik_products.exponential

R/laploglik_products.R

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ laploglik_products.circular <- laploglik_products.exponential
121121
#' @export
122122
laploglik_products.none <- laploglik_products.exponential
123123
#' @export
124+
laploglik_products.ie <- laploglik_products.none
125+
#' @export
124126
laploglik_products.cubic <- laploglik_products.exponential
125127
#' @export
126128
laploglik_products.pentaspherical <- laploglik_products.exponential

R/loocv.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ loocv.splm <- function(object, cv_predict = FALSE, se.fit = FALSE, local, ...) {
6464
}
6565

6666
# iid if relevant otherwise pass
67-
if (inherits(coef(object, type = "spcov"), "none") && is.null(object$random)) {
67+
if (inherits(coef(object, type = "spcov"), c("none", "ie")) && is.null(object$random)) {
6868
return(loocv_iid(object, cv_predict, se.fit, local))
6969
}
7070

0 commit comments

Comments
 (0)