diff --git a/NAMESPACE b/NAMESPACE index fd701aa..be4ce1d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -38,6 +38,7 @@ S3method(cov_initial_search,cubic) S3method(cov_initial_search,exponential) S3method(cov_initial_search,gaussian) S3method(cov_initial_search,gravity) +S3method(cov_initial_search,ie) S3method(cov_initial_search,jbessel) S3method(cov_initial_search,magnetic) S3method(cov_initial_search,matern) @@ -57,6 +58,7 @@ S3method(cov_initial_search_glm,cubic) S3method(cov_initial_search_glm,exponential) S3method(cov_initial_search_glm,gaussian) S3method(cov_initial_search_glm,gravity) +S3method(cov_initial_search_glm,ie) S3method(cov_initial_search_glm,jbessel) S3method(cov_initial_search_glm,magnetic) S3method(cov_initial_search_glm,matern) @@ -95,6 +97,7 @@ S3method(get_initial_range,cubic) S3method(get_initial_range,exponential) S3method(get_initial_range,gaussian) S3method(get_initial_range,gravity) +S3method(get_initial_range,ie) S3method(get_initial_range,jbessel) S3method(get_initial_range,magnetic) S3method(get_initial_range,matern) @@ -125,6 +128,7 @@ S3method(gloglik_products,cubic) S3method(gloglik_products,exponential) S3method(gloglik_products,gaussian) S3method(gloglik_products,gravity) +S3method(gloglik_products,ie) S3method(gloglik_products,jbessel) S3method(gloglik_products,magnetic) S3method(gloglik_products,matern) @@ -156,6 +160,7 @@ S3method(laploglik_products,cubic) S3method(laploglik_products,exponential) S3method(laploglik_products,gaussian) S3method(laploglik_products,gravity) +S3method(laploglik_products,ie) S3method(laploglik_products,jbessel) S3method(laploglik_products,magnetic) S3method(laploglik_products,matern) @@ -236,6 +241,7 @@ S3method(spcov_matrix,cubic) S3method(spcov_matrix,exponential) S3method(spcov_matrix,gaussian) S3method(spcov_matrix,gravity) +S3method(spcov_matrix,ie) S3method(spcov_matrix,jbessel) S3method(spcov_matrix,magnetic) S3method(spcov_matrix,matern) @@ -257,6 +263,7 @@ S3method(spcov_optim2orig,cubic) S3method(spcov_optim2orig,exponential) S3method(spcov_optim2orig,gaussian) S3method(spcov_optim2orig,gravity) +S3method(spcov_optim2orig,ie) S3method(spcov_optim2orig,jbessel) S3method(spcov_optim2orig,magnetic) S3method(spcov_optim2orig,matern) @@ -276,6 +283,7 @@ S3method(spcov_orig2optim,cubic) S3method(spcov_orig2optim,exponential) S3method(spcov_orig2optim,gaussian) S3method(spcov_orig2optim,gravity) +S3method(spcov_orig2optim,ie) S3method(spcov_orig2optim,jbessel) S3method(spcov_orig2optim,magnetic) S3method(spcov_orig2optim,matern) @@ -294,6 +302,7 @@ S3method(spcov_vector,cubic) S3method(spcov_vector,exponential) S3method(spcov_vector,gaussian) S3method(spcov_vector,gravity) +S3method(spcov_vector,ie) S3method(spcov_vector,jbessel) S3method(spcov_vector,magnetic) S3method(spcov_vector,matern) @@ -312,6 +321,7 @@ S3method(sprnorm,cubic) S3method(sprnorm,exponential) S3method(sprnorm,gaussian) S3method(sprnorm,gravity) +S3method(sprnorm,ie) S3method(sprnorm,jbessel) S3method(sprnorm,magnetic) S3method(sprnorm,matern) @@ -423,6 +433,7 @@ importFrom(stats,model.frame) importFrom(stats,model.matrix) importFrom(stats,model.offset) importFrom(stats,model.response) +importFrom(stats,na.fail) importFrom(stats,na.omit) importFrom(stats,na.pass) importFrom(stats,pchisq) diff --git a/NEWS.md b/NEWS.md index a76a8be..b793531 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,20 @@ ## Major Updates -* Added the `range_constrain` argument to `splm()` and `spglm()` to contrain the range parameter to enhance numerical stability. +* 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. +* 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). + +## Minor Updates + +* 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. +* 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`. +* Added the `na.action` argument to `predict.spmodel()` functions to clarify that missing values in `newdata` return an error. +* Minor documentation updates. + +## Bug Fixes + +* Fixed a bug that caused incorrect degrees of freedom for the likelihood ratio test (`anova(model1, model2)`) when `estmethod` is `"ml"` for both models. +* Fixed a bug that caused an error in `anova(object1, object2)` when the name of `object1` had special characters (e.g., `$`). # spmodel 0.8.0 @@ -149,7 +162,7 @@ * Fixed a bug in `spautor()` that prevented an error from occurring when a partition factor was not categorical or not a factor * Fixed a bug in `covmatrix(object, newdata)` that returned a matrix with improper dimensions when `spcov_type` was `"none"`. * 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")`. -* Fixed a bug in `cooks.distance()` that used the Pearson residuals instead of the standarized residuals. +* Fixed a bug in `cooks.distance()` that used the Pearson residuals instead of the standardized residuals. # spmodel 0.3.0 diff --git a/R/anova.R b/R/anova.R index 28e755c..cf1d467 100644 --- a/R/anova.R +++ b/R/anova.R @@ -81,7 +81,6 @@ #' tidy(anova(spmod, lmod)) anova.splm <- function(object, ..., test = TRUE, Terms, L) { - # see if one or two models object2_list <- list(...) @@ -139,13 +138,19 @@ anova.splm <- function(object, ..., test = TRUE, Terms, L) { 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) } Chi2_stat <- abs(-2 * (logLik(object2) - logLik(object))) - df_diff <- abs(object2$npar - object$npar) + + # df for ml vs reml + df1 <- object$npar + df2 <- object2$npar + if (object$estmethod == "ml") df1 <- df1 + object$p + if (object2$estmethod == "ml") df2 <- df2 + object2$p + df_diff <- abs(df1 - df2) p_value <- pchisq(Chi2_stat, df_diff, lower.tail = FALSE) if (object2$npar < object$npar) { - full_name <- as.character(substitute(object)) + full_name <- deparse(substitute(object)) # replace as.character with deparse reduced_name <- as.character(as.list(substitute(list(...)))[-1]) } else { - reduced_name <- as.character(substitute(object)) + reduced_name <- deparse(substitute(object)) # replace as.character with deparse full_name <- as.character(as.list(substitute(list(...)))[-1]) } if (test) { diff --git a/R/cov_betahat_adjust.R b/R/cov_betahat_adjust.R index 70cc98e..8debc05 100644 --- a/R/cov_betahat_adjust.R +++ b/R/cov_betahat_adjust.R @@ -18,7 +18,7 @@ cov_betahat_adjust <- function(invcov_betahat_list, betahat_list, randcov_params, cov_betahat_noadjust, var_adjust) { P <- length(betahat_list) # reset var_adjust if only one partition - if (P == 1 || inherits(spcov_params, "none")) { + if (P == 1 || inherits(spcov_params, c("none", "ie"))) { var_adjust <- "none" } # reset var_adjust if partitioning used but no local option used diff --git a/R/cov_estimate_gloglik.R b/R/cov_estimate_gloglik.R index 721393a..dccb175 100644 --- a/R/cov_estimate_gloglik.R +++ b/R/cov_estimate_gloglik.R @@ -19,7 +19,7 @@ cov_estimate_gloglik_splm <- function(data_object, formula, spcov_initial, estme if (data_object$anisotropy) { dist_matrix_list <- NULL } else { - if (inherits(spcov_initial, "none") && is.null(data_object$randcov_initial)) { + if (inherits(spcov_initial, c("none", "ie")) && is.null(data_object$randcov_initial)) { dist_matrix_list <- NULL } else { dist_matrix_list <- lapply(data_object$obdata_list, function(x) spdist(x, data_object$xcoord, data_object$ycoord)) diff --git a/R/cov_initial_search.R b/R/cov_initial_search.R index b38775d..35aedd5 100644 --- a/R/cov_initial_search.R +++ b/R/cov_initial_search.R @@ -585,6 +585,9 @@ cov_initial_search.none <- function(spcov_initial_NA, estmethod, data_object, best_params } +#' @export +cov_initial_search.ie <- cov_initial_search.none + #' @export cov_initial_search.matern <- function(spcov_initial_NA, estmethod, data_object, dist_matrix_list, weights, diff --git a/R/cov_initial_search_glm.R b/R/cov_initial_search_glm.R index 93fc645..76bc6b8 100644 --- a/R/cov_initial_search_glm.R +++ b/R/cov_initial_search_glm.R @@ -461,6 +461,9 @@ cov_initial_search_glm.none <- function(spcov_initial_NA, dispersion_initial_NA, best_params } +#' @export +cov_initial_search_glm.ie <- cov_initial_search_glm.none + #' @export cov_initial_search_glm.matern <- function(spcov_initial_NA, dispersion_initial_NA, estmethod, data_object, dist_matrix_list, weights, diff --git a/R/data.R b/R/data.R index 657679c..5ee5143 100644 --- a/R/data.R +++ b/R/data.R @@ -62,9 +62,12 @@ #' #' @description Estimated harbor-seal trends from abundance data in southeast Alaska, USA. #' -#' @format A \code{sf} object with 62 rows and 2 columns: +#' @format A \code{sf} object with 149 rows and 2 columns: #' \itemize{ #' \item log_trend: The log of the estimated harbor-seal trends from abundance data. +#' \item stock: A seal stock factor with two levels: 8 and 10. The factor levels indicate the +#' type of seal stock (i.e., type of seal). Stocks 8 and 10 are two distinct stocks +#' (out of 13 total stocks) in southeast Alaska. #' \item geometry: \code{POLYGON} geometry representing polygons in an Alaska #' Albers projection (EPSG: 3338). #' } @@ -124,7 +127,7 @@ #' \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}). +#' (value \code{1}). #' \item geometry: \code{POINT} geometry representing coordinates in an Alaska #' Albers projection (EPSG: 3338). Distances between points are in meters. #' } diff --git a/R/get_data_object.R b/R/get_data_object.R index f3bad45..f19f5b8 100644 --- a/R/get_data_object.R +++ b/R/get_data_object.R @@ -31,7 +31,7 @@ get_data_object_splm <- function(formula, data, spcov_initial, xcoord, ycoord, e data_sf <- NULL } - if (!is_sf && missing(xcoord) && !inherits(spcov_initial, "none")) { + if (!is_sf && missing(xcoord) && !inherits(spcov_initial, c("none", "ie"))) { stop("The xcoord argument must be specified.", call. = FALSE) } @@ -52,7 +52,7 @@ get_data_object_splm <- function(formula, data, spcov_initial, xcoord, ycoord, e ycoord_orig_name <- NULL ycoord_orig_val <- NULL # find coordinate dimension and set defaults - if (inherits(spcov_initial, "none") && estmethod %in% c("reml", "ml")) { + if (inherits(spcov_initial, c("none", "ie")) && estmethod %in% c("reml", "ml")) { dim_coords <- 0 if (missing(xcoord)) { xcoord <- ".xcoord" @@ -213,7 +213,7 @@ get_data_object_splm <- function(formula, data, spcov_initial, xcoord, ycoord, e # } # range constrain - max_range_scale <- 5 + max_range_scale <- 4 range_constrain_value <- 2 * max_halfdist * max_range_scale if ("range" %in% names(spcov_initial$is_known)) { if (spcov_initial$is_known[["range"]] || (spcov_initial$initial[["range"]] > range_constrain_value)) { @@ -221,7 +221,7 @@ get_data_object_splm <- function(formula, data, spcov_initial, xcoord, ycoord, e } } - if (inherits(spcov_initial, "none")) { + if (inherits(spcov_initial, c("none", "ie"))) { range_constrain <- FALSE } diff --git a/R/get_data_object_glm.R b/R/get_data_object_glm.R index 223cd0f..bae24a0 100644 --- a/R/get_data_object_glm.R +++ b/R/get_data_object_glm.R @@ -32,7 +32,7 @@ get_data_object_spglm <- function(formula, family, data, spcov_initial, xcoord, data_sf <- NULL } - if (!is_sf && missing(xcoord) && !inherits(spcov_initial, "none")) { + if (!is_sf && missing(xcoord) && !inherits(spcov_initial, c("none", "ie"))) { stop("The xcoord argument must be specified.", call. = FALSE) } @@ -53,7 +53,7 @@ get_data_object_spglm <- function(formula, family, data, spcov_initial, xcoord, ycoord_orig_name <- NULL ycoord_orig_val <- NULL # find coordinate dimension and set defaults - if (inherits(spcov_initial, "none") && estmethod %in% c("reml", "ml")) { + if (inherits(spcov_initial, c("none", "ie")) && estmethod %in% c("reml", "ml")) { dim_coords <- 0 if (missing(xcoord)) { xcoord <- ".xcoord" @@ -222,8 +222,8 @@ get_data_object_spglm <- function(formula, family, data, spcov_initial, xcoord, betahat <- backsolve(R_val, qr.qty(qr_val, y_trans)) resid <- y_trans - X %*% betahat s2 <- sum(resid^2) / (n - p) - # diagtol <- 1e-4 - diagtol <- min(1e-4, 1e-4 * s2) + diagtol <- 1e-4 + # diagtol <- min(1e-4, 1e-4 * s2) @@ -233,7 +233,7 @@ get_data_object_spglm <- function(formula, family, data, spcov_initial, xcoord, max_halfdist <- sqrt((max(x_range) - min(x_range))^2 + (max(y_range) - min(y_range))^2) / 2 # range constrain - max_range_scale <- 5 + max_range_scale <- 4 range_constrain_value <- 2 * max_halfdist * max_range_scale if ("range" %in% names(spcov_initial$is_known)) { if (spcov_initial$is_known[["range"]] || (spcov_initial$initial[["range"]] > range_constrain_value)) { @@ -241,7 +241,7 @@ get_data_object_spglm <- function(formula, family, data, spcov_initial, xcoord, } } - if (inherits(spcov_initial, "none")) { + if (inherits(spcov_initial, c("none", "ie"))) { range_constrain <- FALSE } diff --git a/R/get_initial_range.R b/R/get_initial_range.R index de38f0e..c2f877c 100644 --- a/R/get_initial_range.R +++ b/R/get_initial_range.R @@ -33,6 +33,10 @@ get_initial_range.circular <- function(spcov_type, max_halfdist, ...) { get_initial_range.none <- function(spcov_type, max_halfdist, ...) { Inf } + +#' @export +get_initial_range.ie <- get_initial_range.none + #' @export get_initial_range.cubic <- function(spcov_type, max_halfdist, ...) { max_halfdist diff --git a/R/get_spcov_params.R b/R/get_spcov_params.R index 0cd1239..29c0084 100644 --- a/R/get_spcov_params.R +++ b/R/get_spcov_params.R @@ -7,7 +7,7 @@ #' #' @noRd get_spcov_params <- function(spcov_type, spcov_orig_val) { - if (spcov_type %in% c("exponential", "spherical", "gaussian", "triangular", "circular", "none", "cubic", "pentaspherical", "cosine", "wave", "jbessel", "gravity", "rquad", "magnetic")) { + if (spcov_type %in% c("exponential", "spherical", "gaussian", "triangular", "circular", "none", "ie", "cubic", "pentaspherical", "cosine", "wave", "jbessel", "gravity", "rquad", "magnetic")) { spcov_params_val <- spcov_params( spcov_type = spcov_type, de = spcov_orig_val[["de"]], diff --git a/R/gloglik_products.R b/R/gloglik_products.R index 9b61b20..ab0abb1 100644 --- a/R/gloglik_products.R +++ b/R/gloglik_products.R @@ -85,6 +85,8 @@ gloglik_products.circular <- gloglik_products.exponential #' @export gloglik_products.none <- gloglik_products.exponential #' @export +gloglik_products.ie <- gloglik_products.none +#' @export gloglik_products.cubic <- gloglik_products.exponential #' @export gloglik_products.pentaspherical <- gloglik_products.exponential diff --git a/R/laploglik_products.R b/R/laploglik_products.R index 7e7ebaa..ba23289 100644 --- a/R/laploglik_products.R +++ b/R/laploglik_products.R @@ -121,6 +121,8 @@ laploglik_products.circular <- laploglik_products.exponential #' @export laploglik_products.none <- laploglik_products.exponential #' @export +laploglik_products.ie <- laploglik_products.none +#' @export laploglik_products.cubic <- laploglik_products.exponential #' @export laploglik_products.pentaspherical <- laploglik_products.exponential diff --git a/R/loocv.R b/R/loocv.R index 52bb312..2b3136f 100644 --- a/R/loocv.R +++ b/R/loocv.R @@ -64,7 +64,7 @@ loocv.splm <- function(object, cv_predict = FALSE, se.fit = FALSE, local, ...) { } # iid if relevant otherwise pass - if (inherits(coef(object, type = "spcov"), "none") && is.null(object$random)) { + if (inherits(coef(object, type = "spcov"), c("none", "ie")) && is.null(object$random)) { return(loocv_iid(object, cv_predict, se.fit, local)) } diff --git a/R/predict.R b/R/predict.R index 54b9d28..20ad711 100644 --- a/R/predict.R +++ b/R/predict.R @@ -21,7 +21,13 @@ #' (ignored if \code{scale} is not specified). The default is \code{Inf}. #' @param interval Type of interval calculation. The default is \code{"none"}. #' Other options are \code{"confidence"} (for confidence intervals) and -#' \code{"prediction"} (for prediction intervals). +#' \code{"prediction"} (for prediction intervals). When \code{interval} +#' is \code{"none"} or \code{"prediction"}, predictions are returned (and when +#' requested, their corresponding uncertainties). When \code{interval} +#' is \code{"confidence"}, mean estimates are returned (and when +#' requested, their corresponding uncertainties). This \code{"none"} behavior +#' differs from that of \code{lm()}, as \code{lm()} returns confidence +#' uncertainties (in \code{.$se.fit}). #' @param level Tolerance/confidence level. The default is \code{0.95}. #' @param type The prediction type, either on the response scale, link scale (only for #' \code{spglm()} or \code{spgautor()} model objects), or terms scale. @@ -65,6 +71,8 @@ #' \code{list(size = 100, method = "covariance", parallel = FALSE)}. #' @param terms If \code{type} is \code{"terms"}, the type of terms to be returned, #' specified via either numeric position or name. The default is all terms are included. +#' @param na.action Missing (\code{NA}) values in \code{newdata} will return an error and should +#' be removed before proceeding. #' @param ... Other arguments. Only used for models fit using \code{splmRF()} #' or \code{spautorRF()} where \code{...} indicates other #' arguments to \code{ranger::predict.ranger()}. @@ -114,7 +122,7 @@ #' predict(spmod, sulfate_preds, interval = "prediction") #' augment(spmod, newdata = sulfate_preds, interval = "prediction") predict.splm <- function(object, newdata, se.fit = FALSE, scale = NULL, df = Inf, interval = c("none", "confidence", "prediction"), - level = 0.95, type = c("response", "terms"), local, terms = NULL, ...) { + level = 0.95, type = c("response", "terms"), local, terms = NULL, na.action = na.fail, ...) { # match interval argument so the three display interval <- match.arg(interval) @@ -232,6 +240,12 @@ predict.splm <- function(object, newdata, se.fit = FALSE, scale = NULL, df = Inf attr(newdata_model, "assign") <- attr_assign[keep_cols] attr(newdata_model, "contrasts") <- attr_contrasts + # finding rows w/out NA + ob_predictors <- complete.cases(newdata_model) + if (any(!ob_predictors)) { + stop("Cannot have NA values in predictors.", call. = FALSE) + } + # call terms if needed if (type == "terms") { return(predict_terms(object, newdata_model, se.fit, scale, df, interval, level, add_newdata_rows, terms, ...)) @@ -380,7 +394,7 @@ predict.splm <- function(object, newdata, se.fit = FALSE, scale = NULL, df = Inf # ) cov_matrix_val <- covmatrix(object) # handling closed form of none covariance - if (inherits(spcov_params_val, "none") && is.null(randcov_params_val)) { + if (inherits(spcov_params_val, c("none", "ie")) && is.null(randcov_params_val)) { cov_lowchol <- cov_matrix_val diag(cov_lowchol) <- sqrt(diag(cov_lowchol)) # already diagonal don't need transpose } else { @@ -538,7 +552,7 @@ predict.splm <- function(object, newdata, se.fit = FALSE, scale = NULL, df = Inf #' @order 2 #' @export predict.spautor <- function(object, newdata, se.fit = FALSE, scale = NULL, df = Inf, interval = c("none", "confidence", "prediction"), - level = 0.95, type = c("response", "terms"), local, terms = NULL, ...) { + level = 0.95, type = c("response", "terms"), local, terms = NULL, na.action = na.fail, ...) { # match interval argument so the three display interval <- match.arg(interval) @@ -603,6 +617,15 @@ predict.spautor <- function(object, newdata, se.fit = FALSE, scale = NULL, df = attr(newdata_model, "assign") <- attr_assign[keep_cols] attr(newdata_model, "contrasts") <- attr_contrasts + # finding rows w/out NA + # this isn't really needed, because the error should come on model building + # but someone could accidentally write over their newdata object after fitting + # so it is good to keep for completeness + ob_predictors <- complete.cases(newdata_model) + if (any(!ob_predictors)) { + stop("Cannot have NA values in predictors.", call. = FALSE) + } + # call terms if needed if (type == "terms") { # may want to add add_newdata_rows if we allow spautor prediction for the observed model matrix @@ -906,8 +929,10 @@ get_pred_spautor_parallel <- function(cluster_list, cov_matrix_lowchol, betahat, #' @method predict splm_list #' @order 3 #' @export -predict.splm_list <- function(object, newdata, se.fit = FALSE, interval = c("none", "confidence", "prediction"), - level = 0.95, local, ...) { +predict.splm_list <- function(object, newdata, se.fit = FALSE, scale = NULL, + df = Inf, interval = c("none", "confidence", "prediction"), + level = 0.95, type = c("response", "terms"), local, + terms = NULL, na.action = na.fail, ...) { # match interval argument so the three display interval <- match.arg(interval) @@ -918,11 +943,34 @@ predict.splm_list <- function(object, newdata, se.fit = FALSE, interval = c("non if (missing(newdata)) { preds <- lapply(object, function(x) { - predict(x, se.fit = se.fit, interval = interval, level = level, local = local, ...) + predict( + x, + se.fit = se.fit, + scale = scale, + df = df, + interval = interval, + level = level, + type = type, + local = local, + terms = terms, # don't need na.action as it is fixed in predict + ... + ) }) } else { preds <- lapply(object, function(x) { - predict(x, newdata = newdata, se.fit = se.fit, interval = interval, level = level, local = local, ...) + predict( + x, + newdata = newdata, + se.fit = se.fit, + scale = scale, + df = df, + interval = interval, + level = level, + type = type, + local = local, + terms = terms, # don't need na.action as it is fixed in predict + ... + ) }) } names(preds) <- names(object) diff --git a/R/predict_glm.R b/R/predict_glm.R index b3f6edf..57ec0a4 100644 --- a/R/predict_glm.R +++ b/R/predict_glm.R @@ -23,7 +23,7 @@ #' augment(spgmod, newdata = moose_preds, interval = "prediction") #' } predict.spglm <- function(object, newdata, type = c("link", "response", "terms"), se.fit = FALSE, interval = c("none", "confidence", "prediction"), - level = 0.95, dispersion = NULL, terms = NULL, local, var_correct = TRUE, newdata_size, ...) { + level = 0.95, dispersion = NULL, terms = NULL, local, var_correct = TRUE, newdata_size, na.action = na.fail, ...) { @@ -154,6 +154,12 @@ predict.spglm <- function(object, newdata, type = c("link", "response", "terms") attr(newdata_model, "assign") <- attr_assign[keep_cols] attr(newdata_model, "contrasts") <- attr_contrasts + # finding rows w/out NA + ob_predictors <- complete.cases(newdata_model) + if (any(!ob_predictors)) { + stop("Cannot have NA values in predictors.", call. = FALSE) + } + # call terms if needed if (type == "terms") { # glm supports standard errors for terms objects but not intervals (no interval argument) @@ -616,7 +622,7 @@ get_pred_spglm <- function(newdata_list, se.fit, interval, formula, obdata, xcoo #' @export predict.spgautor <- function(object, newdata, type = c("link", "response", "terms"), se.fit = FALSE, interval = c("none", "confidence", "prediction"), - level = 0.95, dispersion = NULL, terms = NULL, local, var_correct = TRUE, newdata_size, ...) { + level = 0.95, dispersion = NULL, terms = NULL, local, var_correct = TRUE, newdata_size, na.action = na.fail, ...) { # match type argument so the two display type <- match.arg(type) @@ -697,6 +703,15 @@ predict.spgautor <- function(object, newdata, type = c("link", "response", "term attr(newdata_model, "assign") <- attr_assign[keep_cols] attr(newdata_model, "contrasts") <- attr_contrasts + # finding rows w/out NA + # this isn't really needed, because the error should come on model building + # but someone could accidentally write over their newdata object after fitting + # so it is good to keep for completeness + ob_predictors <- complete.cases(newdata_model) + if (any(!ob_predictors)) { + stop("Cannot have NA values in predictors.", call. = FALSE) + } + # call terms if needed if (type == "terms") { # scale df not used for glms @@ -923,8 +938,10 @@ get_pred_spgautor_parallel <- function(cluster_list, cov_matrix_lowchol, betahat #' @method predict spglm_list #' @order 11 #' @export -predict.spglm_list <- function(object, newdata, type = c("link", "response"), se.fit = FALSE, interval = c("none", "confidence", "prediction"), - newdata_size, level = 0.95, local, var_correct = TRUE, ...) { +predict.spglm_list <- function(object, newdata, type = c("link", "response", "terms"), se.fit = FALSE, + interval = c("none", "confidence", "prediction"), level = 0.95, + dispersion = NULL, terms = NULL, local, var_correct = TRUE, newdata_size, + na.action = na.fail, ...) { type <- match.arg(type) # match interval argument so the three display interval <- match.arg(interval) @@ -941,11 +958,36 @@ predict.spglm_list <- function(object, newdata, type = c("link", "response"), se if (missing(newdata)) { preds <- lapply(object, function(x) { - predict(x, type = type, se.fit = se.fit, interval = interval, newdata_size = newdata_size, level = level, local = local, var_correct = var_correct, ...) + predict( + x, + type = type, + se.fit = se.fit, + interval = interval, + level = level, + dispersion = dispersion, + terms = terms, + local = local, + var_correct = var_correct, + newdata_size = newdata_size, # don't need na.action as it is fixed in predict + ... + ) }) } else { preds <- lapply(object, function(x) { - predict(x, newdata = newdata, type = type, se.fit = se.fit, interval = interval, newdata_size = newdata_size, level = level, local = local, var_correct = var_correct, ...) + predict( + x, + newdata = newdata, + type = type, + se.fit = se.fit, + interval = interval, + level = level, + dispersion = dispersion, + terms = terms, + local = local, + var_correct = var_correct, + newdata_size = newdata_size, # don't need na.action as it is fixed in predict + ... + ) }) } names(preds) <- names(object) diff --git a/R/print.R b/R/print.R index 9047711..7bec939 100644 --- a/R/print.R +++ b/R/print.R @@ -45,7 +45,7 @@ print.splm <- function(x, digits = max(3L, getOption("digits") - 3L), if (!x$anisotropy) { spcoef <- spcoef[-which(names(spcoef) %in% c("rotate", "scale"))] } - if (inherits(coef(x, type = "spcov"), "none")) { + if (inherits(coef(x, type = "spcov"), c("none", "ie"))) { spcoef <- spcoef["ie"] } @@ -165,7 +165,7 @@ print.summary.splm <- function(x, if (!x$anisotropy) { spcoef <- spcoef[-which(names(spcoef) %in% c("rotate", "scale"))] } - if (inherits(x$coefficients$spcov, "none")) { + if (inherits(x$coefficients$spcov, c("none", "ie"))) { spcoef <- spcoef["ie"] } diff --git a/R/print_glm.R b/R/print_glm.R index fa919d0..47017f9 100644 --- a/R/print_glm.R +++ b/R/print_glm.R @@ -24,7 +24,7 @@ print.spglm <- function(x, digits = max(3L, getOption("digits") - 3L), if (!x$anisotropy) { spcoef <- spcoef[-which(names(spcoef) %in% c("rotate", "scale"))] } - if (inherits(coef(x, type = "spcov"), "none")) { + if (inherits(coef(x, type = "spcov"), c("none", "ie"))) { spcoef <- spcoef["ie"] } @@ -160,7 +160,7 @@ print.summary.spglm <- function(x, if (!x$anisotropy) { spcoef <- spcoef[-which(names(spcoef) %in% c("rotate", "scale"))] } - if (inherits(x$coefficients$spcov, "none")) { + if (inherits(x$coefficients$spcov, c("none", "ie"))) { spcoef <- spcoef["ie"] } diff --git a/R/spautor.R b/R/spautor.R index 4619ede..6251e00 100644 --- a/R/spautor.R +++ b/R/spautor.R @@ -47,7 +47,7 @@ #' specifying the partition factor. The partition factor assumes observations #' from different levels of the partition factor are uncorrelated. #' @param W Weight matrix specifying the neighboring structure used. -#' Not required if \code{data} is an \code{sf} object wtih \code{POLYGON} geometry, +#' Not required if \code{data} is an \code{sf} object with \code{POLYGON} geometry, #' as \code{W} is calculated internally using queen contiguity. If calculated internally, #' \code{W} is computed using \code{sf::st_intersects()}. Also not required if \code{data} #' is an \code{sf} object with \code{POINT} geometry as long as \code{cutoff} is specified. diff --git a/R/spautor_checks.R b/R/spautor_checks.R index 24cfdc1..aa43ea3 100644 --- a/R/spautor_checks.R +++ b/R/spautor_checks.R @@ -12,7 +12,7 @@ spautor_checks <- function(spcov_type, W_given, data, estmethod) { "exponential", "spherical", "gaussian", "triangular", "circular", "cubic", "pentaspherical", "cosine", "wave", "jbessel", "gravity", "rquad", "magnetic", - "matern", "cauchy", "pexponential", "none" + "matern", "cauchy", "pexponential", "none", "ie" )) { stop("Invalid spatial covariance type for spautor(). To fit models for point-referenced data, use splm().", call. = FALSE) } diff --git a/R/spcov_initial.R b/R/spcov_initial.R index 13ee39a..86cf524 100644 --- a/R/spcov_initial.R +++ b/R/spcov_initial.R @@ -71,7 +71,7 @@ #' #' All spatial covariance functions are valid in one spatial dimension. All #' spatial covariance functions except \code{triangular} and \code{cosine} are -#' valid in two dimensions. +#' valid in two dimensions. An alias for \code{none} is \code{ie}. #' #' When the spatial covariance function is \code{car} or \code{sar}, \code{extra} #' represents the variance parameter for the observations in \code{W} without @@ -100,7 +100,7 @@ spcov_initial <- function(spcov_type, de, ie, range, extra, rotate, scale, known stop("spcov_type must be specified", call. = FALSE) } else if (!spcov_type %in% c( "exponential", "spherical", "gaussian", "triangular", "circular", - "none", "cubic", "pentaspherical", "cosine", "wave", "matern", "car", "sar", "jbessel", + "none", "ie", "cubic", "pentaspherical", "cosine", "wave", "matern", "car", "sar", "jbessel", "gravity", "rquad", "magnetic", "cauchy", "pexponential" )) { stop(paste(spcov_type, "is not a valid spatial covariance function", sep = " "), call. = FALSE) diff --git a/R/spcov_initial_NA.R b/R/spcov_initial_NA.R index 89d9b5e..abe4739 100644 --- a/R/spcov_initial_NA.R +++ b/R/spcov_initial_NA.R @@ -36,7 +36,7 @@ spcov_initial_NA <- function(spcov_initial, anisotropy = FALSE, is_W_connected = spcov_val_default <- c(de = NA, ie = 0, range = NA, extra = NA) spcov_known_default <- c(de = FALSE, ie = TRUE, range = FALSE, extra = FALSE) } - } else if (inherits(spcov_initial, "none")) { + } else if (inherits(spcov_initial, c("none", "ie"))) { spcov_names <- c("de", "ie", "range", "rotate", "scale") spcov_val_default <- c(de = 0, ie = NA, range = Inf, rotate = 0, scale = 1) spcov_known_default <- c(de = TRUE, ie = FALSE, range = TRUE, rotate = TRUE, scale = TRUE) @@ -50,7 +50,7 @@ spcov_initial_NA <- function(spcov_initial, anisotropy = FALSE, is_W_connected = # put in is_known not in initial spcov_initial$is_known[spcov_out] <- spcov_known_default[spcov_out] # reorder names - if (inherits(spcov_initial, "none")) { + if (inherits(spcov_initial, c("none", "ie"))) { # reset if none covariance spcov_initial$initial[c("de", "range", "rotate", "scale")] <- spcov_val_default[c("de", "range", "rotate", "scale")] # put in is_known not in initial diff --git a/R/spcov_initial_NA_glm.R b/R/spcov_initial_NA_glm.R index 9272a7c..b3cb051 100644 --- a/R/spcov_initial_NA_glm.R +++ b/R/spcov_initial_NA_glm.R @@ -2,6 +2,11 @@ spcov_initial_NA_glm <- function(family, spcov_initial, anisotropy = FALSE, is_W spcov_initial_NA_val <- spcov_initial_NA(spcov_initial, anisotropy, is_W_connected) spcov_initial_NA_glm_val <- spcov_initial_NA_val + if (inherits(spcov_initial_NA_glm_val, "none")) { + spcov_initial_NA_glm_val$initial["ie"] <- 0 + spcov_initial_NA_glm_val$is_known["ie"] <- TRUE + } + # fix ie can be confounded with dispersion (problems with ie error) # if (family %in% c("nbinomial", "Gamma", "inverse.gaussian", "beta")) { # if (is.na(spcov_initial_NA_glm_val$initial[["ie"]])) { diff --git a/R/spcov_matrix.R b/R/spcov_matrix.R index d365487..4e7dbd5 100644 --- a/R/spcov_matrix.R +++ b/R/spcov_matrix.R @@ -70,6 +70,10 @@ spcov_matrix.none <- function(spcov_params, dist_matrix, diagtol = 0, ...) { spcov_matrix_val } +# spcov_matrix ie +#' @export +spcov_matrix.ie <- spcov_matrix.none + # spcov_matrix cubic #' @export spcov_matrix.cubic <- function(spcov_params, dist_matrix, diagtol = 0, ...) { diff --git a/R/spcov_optim2orig.R b/R/spcov_optim2orig.R index 5e7d516..3ade2b5 100644 --- a/R/spcov_optim2orig.R +++ b/R/spcov_optim2orig.R @@ -48,6 +48,8 @@ spcov_optim2orig.circular <- spcov_optim2orig.exponential #' @export spcov_optim2orig.none <- spcov_optim2orig.exponential #' @export +spcov_optim2orig.ie <- spcov_optim2orig.none +#' @export spcov_optim2orig.cubic <- spcov_optim2orig.exponential #' @export spcov_optim2orig.pentaspherical <- spcov_optim2orig.exponential diff --git a/R/spcov_orig2optim.R b/R/spcov_orig2optim.R index 2f693a0..492cddf 100644 --- a/R/spcov_orig2optim.R +++ b/R/spcov_orig2optim.R @@ -92,6 +92,8 @@ spcov_orig2optim.circular <- spcov_orig2optim.exponential #' @export spcov_orig2optim.none <- spcov_orig2optim.exponential #' @export +spcov_orig2optim.ie <- spcov_orig2optim.none +#' @export spcov_orig2optim.cubic <- spcov_orig2optim.exponential #' @export spcov_orig2optim.pentaspherical <- spcov_orig2optim.exponential diff --git a/R/spcov_params.R b/R/spcov_params.R index bc635f7..da857ba 100644 --- a/R/spcov_params.R +++ b/R/spcov_params.R @@ -9,7 +9,7 @@ #' \code{"pentaspherical"}, \code{"cosine"}, \code{"wave"}, #' \code{"jbessel"}, \code{"gravity"}, \code{"rquad"}, #' \code{"magnetic"}, \code{"matern"}, \code{"cauchy"}, \code{"pexponential"}, -#' \code{"car"}, \code{"sar"}, and \code{"none"}. +#' \code{"car"}, \code{"sar"}, \code{"none"}, and \code{"ie"} (an alias for \code{"none"}). #' @param de The spatially dependent (correlated) random error variance. Commonly referred to as #' a partial sill. #' @param ie The spatially independent (uncorrelated) random error variance. Commonly referred to as @@ -44,7 +44,7 @@ spcov_params <- function(spcov_type, de, ie, range, extra, rotate = 0, scale = 1 stop("spcov_type must be specified", call. = FALSE) } else if (!spcov_type %in% c( "exponential", "spherical", "gaussian", "triangular", "circular", - "none", "cubic", "pentaspherical", "cosine", "wave", "matern", "car", "sar", "jbessel", + "none", "ie", "cubic", "pentaspherical", "cosine", "wave", "matern", "car", "sar", "jbessel", "gravity", "rquad", "magnetic", "cauchy", "pexponential" )) { stop(paste(spcov_type), "is not a valid spatial covariance function.") @@ -54,7 +54,7 @@ spcov_params <- function(spcov_type, de, ie, range, extra, rotate = 0, scale = 1 stop("spcov_type must be specified.", call. = FALSE) } - if (spcov_type == "none") { + if (spcov_type %in% c("none", "ie")) { de <- 0 range <- Inf } @@ -69,11 +69,11 @@ spcov_params <- function(spcov_type, de, ie, range, extra, rotate = 0, scale = 1 } # some parameter specification checks - if (spcov_type != "none" && any(missing(de), missing(ie), missing(range))) { + if ((!spcov_type %in% c("none", "ie")) && any(missing(de), missing(ie), missing(range))) { stop("de, ie, and range must be specified.", call. = FALSE) } - if (spcov_type == "none" && missing(ie)) { + if (spcov_type %in% c("none", "ie") && missing(ie)) { stop("ie must be specified.", call. = FALSE) } @@ -117,7 +117,7 @@ spcov_params <- function(spcov_type, de, ie, range, extra, rotate = 0, scale = 1 stop("extra must be positive and no larger than 2.", call. = FALSE) } - if (spcov_type %in% c("exponential", "spherical", "gaussian", "triangular", "circular", "none", "cubic", "pentaspherical", "cosine", "wave", "jbessel", "gravity", "rquad", "magnetic")) { + if (spcov_type %in% c("exponential", "spherical", "gaussian", "triangular", "circular", "none", "ie", "cubic", "pentaspherical", "cosine", "wave", "jbessel", "gravity", "rquad", "magnetic")) { extra <- NULL } if (spcov_type %in% c("car", "sar")) { diff --git a/R/spcov_vector.R b/R/spcov_vector.R index eb60c81..9eb941a 100644 --- a/R/spcov_vector.R +++ b/R/spcov_vector.R @@ -59,6 +59,10 @@ spcov_vector.none <- function(spcov_params, dist_vector) { spcov_vector_val } +# spcov_vector ie +#' @export +spcov_vector.ie <- spcov_vector.none + # spcov_vector cubic #' @export spcov_vector.cubic <- function(spcov_params, dist_vector) { diff --git a/R/spgautor_checks.R b/R/spgautor_checks.R index 0873dfd..d33acf3 100644 --- a/R/spgautor_checks.R +++ b/R/spgautor_checks.R @@ -12,7 +12,7 @@ spgautor_checks <- function(family, spcov_type, W_given, data, estmethod) { "exponential", "spherical", "gaussian", "triangular", "circular", "cubic", "pentaspherical", "cosine", "wave", "jbessel", "gravity", "rquad", "magnetic", - "matern", "cauchy", "pexponential", "none" + "matern", "cauchy", "pexponential", "none", "ie" )) { stop("Invalid spatial covariance type for spautor(). To fit models for point-referenced data, use splm().", call. = FALSE) } diff --git a/R/spglm.R b/R/spglm.R index 6bf9098..c7ebf0e 100644 --- a/R/spglm.R +++ b/R/spglm.R @@ -28,7 +28,7 @@ #' \code{"pentaspherical"}, \code{"cosine"}, \code{"wave"}, #' \code{"jbessel"}, \code{"gravity"}, \code{"rquad"}, #' \code{"magnetic"}, \code{"matern"}, \code{"cauchy"}, \code{"pexponential"}, -#' and \code{"none"}. Parameterizations of each spatial covariance type are +#' \code{"ie"}, and \code{"none"}. Parameterizations of each spatial covariance type are #' available in Details. Multiple spatial covariance types can be provided as #' a character vector, and then \code{spglm()} is called iteratively for each #' element and a list is returned for each model fit. The default for @@ -123,7 +123,7 @@ #' \code{list(size = 100, method = "kmeans", var_adjust = "theoretical", parallel = FALSE)}. #' @param range_constrain An optional logical that indicates whether the range #' should be constrained to enhance numerical stability. If \code{range_constrain = TRUE}, -#' the maximum possible range value is 5 times the maximum distance in the domain. +#' the maximum possible range value is 4 times the maximum distance in the domain. #' If \code{range_constrain = FALSE}, then maximum possible range is unbounded. #' The default is \code{FALSE}. #' Note that if \code{range_constrain = TRUE} and the value of \code{range} in \code{spcov_initial} @@ -225,8 +225,19 @@ #' \item cauchy: \eqn{(1 + \eta^2)^{-extra}}, \eqn{extra > 0} #' \item pexponential: \eqn{exp(h^{extra}/range)}, \eqn{0 < extra \le 2} #' \item none: \eqn{0} +#' \item ie: \eqn{0} (see below for differences compared to none) #' } #' +#' There is a slight difference between \code{none} and \code{ie} (the \code{spcov_type}) from above. \code{none} +#' fixes the \code{"ie"} covariance parameter at zero, which should yield a model that has very similar +#' parameter estimates as one from [stats::glm]. Note that \code{spglm()} uses +#' a different likelihood, so direct likelihood-based comparisons (e.g., \code{AIC}) +#' should not be made to compare an \code{spglm()} model to a \code{glm()} one +#' (though deviance can be used). \code{ie} allows the \code{"ie"} covariance +#' parameter to vary. If the \code{"ie"} covariance parameter is estimated near +#' zero, then \code{none} and \code{ie} yield similar models. +#' +#' #' All spatial covariance functions are valid in one spatial dimension. All #' spatial covariance functions except \code{triangular} and \code{cosine} are #' valid in two dimensions. diff --git a/R/splm.R b/R/splm.R index d513284..0133ee4 100644 --- a/R/splm.R +++ b/R/splm.R @@ -120,7 +120,7 @@ #' \code{list(size = 100, method = "kmeans", var_adjust = "theoretical", parallel = FALSE)}. #' @param range_constrain An optional logical that indicates whether the range #' should be constrained to enhance numerical stability. If \code{range_constrain = TRUE}, -#' the maximum possible range value is 5 times the maximum distance in the domain. +#' the maximum possible range value is 4 times the maximum distance in the domain. #' If \code{range_constrain = FALSE}, then maximum possible range is unbounded. #' The default is \code{FALSE}. #' Note that if \code{range_constrain = TRUE} and the value of \code{range} in \code{spcov_initial} @@ -164,7 +164,7 @@ #' #' All spatial covariance functions are valid in one spatial dimension. All #' spatial covariance functions except \code{triangular} and \code{cosine} are -#' valid in two dimensions. +#' valid in two dimensions. An alias for \code{none} is \code{ie}. #' #' \code{estmethod} Details: The various estimation methods are #' \itemize{ @@ -304,7 +304,7 @@ splm <- function(formula, data, spcov_type, xcoord, ycoord, spcov_initial, } # set local explicitly to FALSE if iid - if (inherits(spcov_initial, "none") && is.null(random)) { + if (inherits(spcov_initial, c("none", "ie")) && is.null(random)) { local <- FALSE } @@ -355,7 +355,7 @@ splm <- function(formula, data, spcov_type, xcoord, ycoord, spcov_initial, - if (inherits(cov_est_object$spcov_params_val, "none") && is.null(random)) { + if (inherits(cov_est_object$spcov_params_val, c("none", "ie")) && is.null(random)) { model_stats <- get_model_stats_splm_iid(cov_est_object, data_object, estmethod) } else { model_stats <- get_model_stats_splm(cov_est_object, data_object, estmethod) diff --git a/R/spmodel-package.R b/R/spmodel-package.R index 1ab19e7..b39e4be 100644 --- a/R/spmodel-package.R +++ b/R/spmodel-package.R @@ -9,7 +9,7 @@ #' @importFrom stats AIC anova BIC coef coefficients complete.cases confint cooks.distance cor #' dbeta dbinom dgamma dnbinom dpois #' delete.response deviance dist fitted fitted.values formula .getXlevels hatvalues -#' influence kmeans lm logLik model.frame model.matrix model.offset model.response na.omit na.pass pchisq +#' influence kmeans lm logLik model.frame model.matrix model.offset model.response na.fail na.omit na.pass pchisq #' pnorm predict printCoefmat pt qnorm qqnorm qqline qt quantile #' rbeta rbinom rgamma rnbinom rpois resid #' residuals reformulate rnorm rstandard terms var vcov diff --git a/R/sprnorm.R b/R/sprnorm.R index 942cf25..d04f60b 100644 --- a/R/sprnorm.R +++ b/R/sprnorm.R @@ -266,6 +266,12 @@ sprnorm.none <- function(spcov_params, mean = 0, samples = 1, data, randcov_para sprnorm_val } + +#' @rdname sprnorm +#' @method sprnorm ie +#' @export +sprnorm.ie <- sprnorm.none + #' @rdname sprnorm #' @method sprnorm car #' @export diff --git a/R/tidy.R b/R/tidy.R index 58377c9..4019eaa 100644 --- a/R/tidy.R +++ b/R/tidy.R @@ -69,7 +69,7 @@ tidy.splm <- function(x, conf.int = FALSE, which_scale <- which(result$term == "scale") result <- result[-c(which_rotate, which_scale), , drop = FALSE] } - if (inherits(spcoef, "none")) { + if (inherits(spcoef, c("none", "ie"))) { which_ie <- which(result$term == "ie") result <- result[which_ie, , drop = FALSE] } diff --git a/R/tidy_glm.R b/R/tidy_glm.R index 6b4e0d6..312019d 100644 --- a/R/tidy_glm.R +++ b/R/tidy_glm.R @@ -41,7 +41,7 @@ tidy.spglm <- function(x, conf.int = FALSE, which_scale <- which(result$term == "scale") result <- result[-c(which_rotate, which_scale), , drop = FALSE] } - if (inherits(spcoef, "none")) { + if (inherits(spcoef, c("none", "ie"))) { which_ie <- which(result$term == "ie") result <- result[which_ie, , drop = FALSE] } diff --git a/data/seal.rda b/data/seal.rda index ded3457..5d0cbf1 100644 Binary files a/data/seal.rda and b/data/seal.rda differ diff --git a/docs/articles/SPGLMs.html b/docs/articles/SPGLMs.html index f1304c3..d515f05 100644 --- a/docs/articles/SPGLMs.html +++ b/docs/articles/SPGLMs.html @@ -789,7 +789,7 @@
In the next two sections we to show how to use spmodel
to analyze data collected on moose in the Togiak region of Alaska, USA.
@@ -883,7 +883,7 @@
AIC(bin_mod, bin_spmod, bin_spmod_anis)
#> df AIC
-#> bin_mod 1 719.1628
+#> bin_mod 0 717.1627
#> bin_spmod 3 686.9031
#> bin_spmod_anis 5 677.9403
The spatial models (, ) have a much lower AIC than the non-spatial @@ -996,7 +996,7 @@
The function augments the data with model diagnostics:
@@ -1206,7 +1206,7 @@An application to count data
Estimated mean moose counts for the data (obtained via ) and predicted mean moose counts for the data (obtained via or ) share -similiar patterns and are overlain by running
+similar patterns and are overlain by running+#> 0.04936 0.56167 0.01750aug_mod <- augment(count_mod_nb) aug_pred <- augment(count_mod_nb, newdata = moose_preds, type.predict = "response") diff --git a/docs/articles/guide.html b/docs/articles/guide.html index bffbb2f..ccb9462 100644 --- a/docs/articles/guide.html +++ b/docs/articles/guide.html @@ -753,25 +753,25 @@
by runningAn Areal Data Exampleseal
-seal
#> Simple feature collection with 62 features and 1 field +
+#> # A tibble: 149 × 3 +#> log_trend stock geometry +#> * <dbl> <fct> <POLYGON [m]> +#> 1 NA 8 ((1035002 1054710, 1035002 1054542, 1035002 1053542, 1035002… +#> 2 -0.282 8 ((1037002 1039492, 1037006 1039490, 1037017 1039492, 1037035… +#> 3 -0.00121 8 ((1070158 1030216, 1070185 1030207, 1070187 1030207, 1070211… +#> 4 0.0354 8 ((1054906 1034826, 1054931 1034821, 1054936 1034822, 1055001… +#> 5 -0.0160 8 ((1025142 1056940, 1025184 1056889, 1025222 1056836, 1025256… +#> 6 0.0872 8 ((1026035 1044623, 1026037 1044605, 1026072 1044610, 1026083… +#> 7 -0.266 8 ((1100345 1060709, 1100287 1060706, 1100228 1060706, 1100170… +#> 8 0.0743 8 ((1030247 1029637, 1030248 1029637, 1030265 1029642, 1030328… +#> 9 NA 8 ((1043093 1020553, 1043097 1020550, 1043101 1020550, 1043166… +#> 10 -0.00961 8 ((1116002 1024542, 1116002 1023542, 1116002 1022542, 1116002… +#> # ℹ 139 more rows#> Simple feature collection with 149 features and 2 fields #> Geometry type: POLYGON #> Dimension: XY -#> Bounding box: xmin: 913618.8 ymin: 1007542 xmax: 1116002 ymax: 1145054 +#> Bounding box: xmin: 913618.8 ymin: 855730.2 xmax: 1221859 ymax: 1145054 #> Projected CRS: NAD83 / Alaska Albers -#> # A tibble: 62 × 2 -#> log_trend geometry -#> <dbl> <POLYGON [m]> -#> 1 NA ((1035002 1054710, 1035002 1054542, 1035002 1053542, 1035002 10525… -#> 2 -0.282 ((1037002 1039492, 1037006 1039490, 1037017 1039492, 1037035 10394… -#> 3 -0.00121 ((1070158 1030216, 1070185 1030207, 1070187 1030207, 1070211 10302… -#> 4 0.0354 ((1054906 1034826, 1054931 1034821, 1054936 1034822, 1055001 10348… -#> 5 -0.0160 ((1025142 1056940, 1025184 1056889, 1025222 1056836, 1025256 10567… -#> 6 0.0872 ((1026035 1044623, 1026037 1044605, 1026072 1044610, 1026083 10446… -#> 7 -0.266 ((1100345 1060709, 1100287 1060706, 1100228 1060706, 1100170 10607… -#> 8 0.0743 ((1030247 1029637, 1030248 1029637, 1030265 1029642, 1030328 10296… -#> 9 NA ((1043093 1020553, 1043097 1020550, 1043101 1020550, 1043166 10205… -#> 10 -0.00961 ((1116002 1024542, 1116002 1023542, 1116002 1022542, 1116002 10215… -#> # ℹ 52 more rows
We can learn more about the data by running
help("seal", "spmodel")
.We can visualize the distribution of log seal trends in the @@ -817,51 +817,50 @@
An Areal Data Example#> spautor(formula = log_trend ~ 1, data = seal, spcov_type = "car") #> #> Residuals: -#> Min 1Q Median 3Q Max -#> -0.34455 -0.10417 0.04410 0.07338 0.20475 +#> Min 1Q Median 3Q Max +#> -0.402385 -0.073439 0.004368 0.073465 0.848290 #> #> Coefficients (fixed): -#> Estimate Std. Error z value Pr(>|z|) -#> (Intercept) -0.07090 0.02497 -2.839 0.00452 ** -#> --- -#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 +#> Estimate Std. Error z value Pr(>|z|) +#> (Intercept) -0.01306 0.02004 -0.652 0.514 #> #> Coefficients (car spatial covariance): #> de range extra -#> 0.03252 0.42037 0.02177
tidy(sealmod)
+#> 1 (Intercept) -0.0131 0.0200 -0.652 0.514#> # A tibble: 1 × 5 #> term estimate std.error statistic p.value #> <chr> <dbl> <dbl> <dbl> <dbl> -#> 1 (Intercept) -0.0709 0.0250 -2.84 0.00452
glance(sealmod)
+#> 1 94 1 3 -74.5 -68.5 -68.3 -60.9 37.3 92.9 0#> # A tibble: 1 × 10 #> n p npar value AIC AICc BIC logLik deviance pseudo.r.squared #> <int> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 34 1 3 -36.9 -30.9 -30.1 -26.3 18.4 33.1 0
-augment(sealmod)
#> Simple feature collection with 34 features and 6 fields +
+#> # A tibble: 94 × 7 +#> log_trend .fitted .resid .hat .cooksd .std.resid +#> * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> +#> 1 -0.282 -0.0131 -0.269 0.00579 0.00705 -1.10 +#> 2 -0.00121 -0.0131 0.0118 0.0156 0.000527 0.182 +#> 3 0.0354 -0.0131 0.0485 0.0103 0.00100 0.310 +#> 4 -0.0160 -0.0131 -0.00295 0.00749 0.0000640 -0.0921 +#> 5 0.0872 -0.0131 0.100 0.00939 0.00361 0.617 +#> 6 -0.266 -0.0131 -0.253 0.0229 0.0877 -1.93 +#> 7 0.0743 -0.0131 0.0873 0.0171 0.00620 0.597 +#> 8 -0.00961 -0.0131 0.00345 0.00909 0.000254 0.166 +#> 9 -0.182 -0.0131 -0.169 0.00785 0.00916 -1.08 +#> 10 0.00351 -0.0131 0.0166 0.0111 0.000144 0.113 +#> # ℹ 84 more rows +#> # ℹ 1 more variable: geometry <POLYGON [m]>#> Simple feature collection with 94 features and 6 fields #> Geometry type: POLYGON #> Dimension: XY -#> Bounding box: xmin: 980001.5 ymin: 1010815 xmax: 1116002 ymax: 1145054 +#> Bounding box: xmin: 980001.5 ymin: 855730.2 xmax: 1221859 ymax: 1145054 #> Projected CRS: NAD83 / Alaska Albers -#> # A tibble: 34 × 7 -#> log_trend .fitted .resid .hat .cooksd .std.resid geometry -#> * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <POLYGON [m]> -#> 1 -0.282 -0.0709 -0.211 0.0161 0.0209 -1.13 ((1037002 1039492, 10370… -#> 2 -0.00121 -0.0709 0.0697 0.0473 0.0256 0.718 ((1070158 1030216, 10701… -#> 3 0.0354 -0.0709 0.106 0.0290 0.0183 0.782 ((1054906 1034826, 10549… -#> 4 -0.0160 -0.0709 0.0549 0.0228 0.00157 0.260 ((1025142 1056940, 10251… -#> 5 0.0872 -0.0709 0.158 0.0276 0.0383 1.16 ((1026035 1044623, 10260… -#> 6 -0.266 -0.0709 -0.195 0.0287 0.0530 -1.34 ((1100345 1060709, 11002… -#> 7 0.0743 -0.0709 0.145 0.0491 0.0901 1.32 ((1030247 1029637, 10302… -#> 8 -0.00961 -0.0709 0.0613 0.0122 0.00242 0.442 ((1116002 1024542, 11160… -#> 9 -0.182 -0.0709 -0.111 0.0225 0.0224 -0.986 ((1079864 1025088, 10798… -#> 10 0.00351 -0.0709 0.0744 0.0316 0.0100 0.555 ((1110363 1037056, 11103… -#> # ℹ 24 more rows
Note that for
spautor()
models, theie
spatial covariance parameter is assumed zero by default (and omitted from thesummary()
output). This default behavior can be @@ -1063,25 +1062,25 @@Predictionaugment() to make the predictions:
-augment(sealmod, newdata = sealmod$newdata)
#> Simple feature collection with 28 features and 2 fields +
+#> # A tibble: 55 × 4 +#> log_trend stock .fitted geometry +#> * <dbl> <fct> <dbl> <POLYGON [m]> +#> 1 NA 8 -0.106 ((1035002 1054710, 1035002 1054542, 1035002 1053542… +#> 2 NA 8 0.0359 ((1043093 1020553, 1043097 1020550, 1043101 1020550… +#> 3 NA 8 -0.0303 ((1099737 1054310, 1099752 1054262, 1099788 1054278… +#> 4 NA 8 0.00167 ((1099002 1036542, 1099134 1036462, 1099139 1036431… +#> 5 NA 8 -0.0360 ((1076902 1053189, 1076912 1053179, 1076931 1053179… +#> 6 NA 8 -0.0133 ((1070501 1046969, 1070317 1046598, 1070308 1046542… +#> 7 NA 8 -0.0704 ((1072995 1054942, 1072996 1054910, 1072997 1054878… +#> 8 NA 8 -0.0159 ((960001.5 1127667, 960110.8 1127542, 960144.1 1127… +#> 9 NA 8 -0.0558 ((1031308 1079817, 1031293 1079754, 1031289 1079741… +#> 10 NA 8 -0.0296 ((998923.7 1053647, 998922.5 1053609, 998950 105363… +#> # ℹ 45 more rows#> Simple feature collection with 55 features and 3 fields #> Geometry type: POLYGON #> Dimension: XY -#> Bounding box: xmin: 913618.8 ymin: 1007542 xmax: 1115097 ymax: 1132682 +#> Bounding box: xmin: 913618.8 ymin: 866541.5 xmax: 1214641 ymax: 1132682 #> Projected CRS: NAD83 / Alaska Albers -#> # A tibble: 28 × 3 -#> log_trend .fitted geometry -#> * <dbl> <dbl> <POLYGON [m]> -#> 1 NA -0.115 ((1035002 1054710, 1035002 1054542, 1035002 1053542, 1035… -#> 2 NA -0.00908 ((1043093 1020553, 1043097 1020550, 1043101 1020550, 1043… -#> 3 NA -0.0602 ((1099737 1054310, 1099752 1054262, 1099788 1054278, 1099… -#> 4 NA -0.0359 ((1099002 1036542, 1099134 1036462, 1099139 1036431, 1099… -#> 5 NA -0.0723 ((1076902 1053189, 1076912 1053179, 1076931 1053179, 1076… -#> 6 NA -0.0548 ((1070501 1046969, 1070317 1046598, 1070308 1046542, 1070… -#> 7 NA -0.0976 ((1072995 1054942, 1072996 1054910, 1072997 1054878, 1072… -#> 8 NA -0.0714 ((960001.5 1127667, 960110.8 1127542, 960144.1 1127495, 9… -#> 9 NA -0.0825 ((1031308 1079817, 1031293 1079754, 1031289 1079741, 1031… -#> 10 NA -0.0592 ((998923.7 1053647, 998922.5 1053609, 998950 1053631, 999… -#> # ℹ 18 more rows
@@ -2756,7 +2760,9 @@Advanced Features diff --git a/docs/articles/guide_files/figure-html/log_trend-1.png b/docs/articles/guide_files/figure-html/log_trend-1.png index a0875f8..1148459 100644 Binary files a/docs/articles/guide_files/figure-html/log_trend-1.png and b/docs/articles/guide_files/figure-html/log_trend-1.png differ diff --git a/docs/articles/introduction.html b/docs/articles/introduction.html index fd400a7..6b48dfe 100644 --- a/docs/articles/introduction.html +++ b/docs/articles/introduction.html @@ -862,7 +862,7 @@
Model Summaries#> model n p npar value AIC AICc BIC logLik deviance #> <chr> <int> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 binmod 218 2 3 692. 698. 698. 708. -346. 190. -#> 2 glmod 218 2 1 715. 717. 717. 721. -358. 302. +#> 2 glmod 218 2 0 715. 715. 715. 715. -358. 302. #> # ℹ 1 more variable: pseudo.r.squared <dbl>
The lower AIC and AICc for the spatial binomial regression model indicates it is a much better fit to the data.
diff --git a/docs/articles/technical.html b/docs/articles/technical.html index 61263d7..bc27fac 100644 --- a/docs/articles/technical.html +++ b/docs/articles/technical.html @@ -1248,7 +1248,7 @@
The forms of R for each spatial covariance type available in splm(). All spatial covariance functions are valid in two dimensions except the triangular and cosine functions, which are only valid in one -dimension. +dimension. An alias for none is ie.@@ -1345,6 +1345,10 @@
\(\texttt{"none"}\) \(0\) ++ \(\texttt{"ie"}\) +\(0\) +
spglm()
Spatial Covariance FunctionsCovariance functions for
+covariance functions forspglm()
are defined the same as -covariance functions forsplm()
.splm()
except that for +"none"
, theie
parameter is also set to zero +(analogous toglm()
models).
spmodel
+v\(\le 0.8.0\)), \(d = \text{min}(1/10^4, s^2/10^4)\), where
+\(s^2\) is the sample variance of a
+linear regression of \(\ln(\mathbf{y} +
+1)\) on \(\mathbf{X}\). This
+value of \(\sigma^2_{ie, up}\) is also
+added to the diagonal of \(\mathbf{X}^\top
\boldsymbol{\Sigma}^{-1} \mathbf{X} + \mathbf{X}^\top
\boldsymbol{\Sigma}^{-1} (\mathbf{D} - \boldsymbol{\Sigma}^{-1})^{-1}
\boldsymbol{\Sigma}^{-1} \mathbf{X}\), used via the
diff --git a/docs/news/index.html b/docs/news/index.html
index 53764ad..9ff01dc 100644
--- a/docs/news/index.html
+++ b/docs/news/index.html
@@ -70,10 +70,23 @@ range_constrain
argument to splm()
and spglm()
to contrain the range parameter to enhance numerical stability.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.seal
data with additional polygons and a factor variable, stock
, with two levels (8
and 10
) that indicates seal stock (i.e., seal type).spglm()
and spgautor()
model objects. See this link for details."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
.na.action
argument to predict.spmodel()
functions to clarify that missing values in newdata
return an error.covmatrix(object, newdata)
that returned a matrix with improper dimensions when spcov_type
was "none"
.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")
.cooks.distance()
that used the Pearson residuals instead of the standarized residuals.cooks.distance()
that used the Pearson residuals instead of the standardized residuals.strat: A factor representing strata (used for sampling). Can take values L
and M
.
count: The count (number) of moose observed.
presence: A binary factor representing whether no moose were observed (value 0
) or at least one moose was observed
-(va ue 1
).
1
).
geometry: POINT
geometry representing coordinates in an Alaska
Albers projection (EPSG: 3338). Distances between points are in meters.
Type of interval calculation. The default is "none"
.
Other options are "confidence"
(for confidence intervals) and
-"prediction"
(for prediction intervals).
"prediction"
(for prediction intervals). When interval
+is "none"
or "prediction"
, predictions are returned (and when
+requested, their corresponding uncertainties). When interval
+is "confidence"
, mean estimates are returned (and when
+requested, their corresponding uncertainties). This "none"
behavior
+differs from that of lm()
, as lm()
returns confidence
+uncertainties (in .$se.fit
).
Missing (NA
) values in newdata
will return an error and should
+be removed before proceeding.
Other arguments. Only used for models fit using splmRF()
or spautorRF()
where ...
indicates other
diff --git a/docs/reference/seal.html b/docs/reference/seal.html
index fa98c07..c7142e8 100644
--- a/docs/reference/seal.html
+++ b/docs/reference/seal.html
@@ -80,7 +80,10 @@
A sf
object with 62 rows and 2 columns:
log_trend: The log of the estimated harbor-seal trends from abundance data.
A sf
object with 149 rows and 2 columns:
log_trend: The log of the estimated harbor-seal trends from abundance data.
stock: A seal stock factor with two levels: 8 and 10. The factor levels indicate the +type of seal stock (i.e., type of seal). Stocks 8 and 10 are two distinct stocks +(out of 13 total stocks) in southeast Alaska.
geometry: POLYGON
geometry representing polygons in an Alaska
Albers projection (EPSG: 3338).
Weight matrix specifying the neighboring structure used.
-Not required if data
is an sf
object wtih POLYGON
geometry,
+Not required if data
is an sf
object with POLYGON
geometry,
as W
is calculated internally using queen contiguity. If calculated internally,
W
is computed using sf::st_intersects()
. Also not required if data
is an sf
object with POINT
geometry as long as cutoff
is specified.
none: \(0\)
All spatial covariance functions are valid in one spatial dimension. All
spatial covariance functions except triangular
and cosine
are
-valid in two dimensions.
none
is ie
.
When the spatial covariance function is car
or sar
, extra
represents the variance parameter for the observations in W
without
at least one neighbor (other than itself) -- these are called unconnected
diff --git a/docs/reference/spcov_params.html b/docs/reference/spcov_params.html
index 5b793aa..165d4af 100644
--- a/docs/reference/spcov_params.html
+++ b/docs/reference/spcov_params.html
@@ -89,7 +89,7 @@
"pentaspherical"
, "cosine"
, "wave"
,
"jbessel"
, "gravity"
, "rquad"
,
"magnetic"
, "matern"
, "cauchy"
, "pexponential"
,
-"car"
, "sar"
, and "none"
."car"
, "sar"
, "none"
, and "ie"
(an alias for "none"
).
"pentaspherical"
, "cosine"
, "wave"
,
"jbessel"
, "gravity"
, "rquad"
,
"magnetic"
, "matern"
, "cauchy"
, "pexponential"
,
-and "none"
. Parameterizations of each spatial covariance type are
+"ie"
, and "none"
. Parameterizations of each spatial covariance type are
available in Details. Multiple spatial covariance types can be provided as
a character vector, and then spglm()
is called iteratively for each
element and a list is returned for each model fit. The default for
@@ -261,7 +261,7 @@ An optional logical that indicates whether the range
should be constrained to enhance numerical stability. If range_constrain = TRUE
,
-the maximum possible range value is 5 times the maximum distance in the domain.
+the maximum possible range value is 4 times the maximum distance in the domain.
If range_constrain = FALSE
, then maximum possible range is unbounded.
The default is FALSE
.
Note that if range_constrain = TRUE
and the value of range
in spcov_initial
@@ -374,7 +374,16 @@
cauchy: \((1 + \eta^2)^{-extra}\), \(extra > 0\)
pexponential: \(exp(h^{extra}/range)\), \(0 < extra \le 2\)
none: \(0\)
All spatial covariance functions are valid in one spatial dimension. All +
ie: \(0\) (see below for differences compared to none)
There is a slight difference between none
and ie
(the spcov_type
) from above. none
+fixes the "ie"
covariance parameter at zero, which should yield a model that has very similar
+parameter estimates as one from stats::glm. Note that spglm()
uses
+a different likelihood, so direct likelihood-based comparisons (e.g., AIC
)
+should not be made to compare an spglm()
model to a glm()
one
+(though deviance can be used). ie
allows the "ie"
covariance
+parameter to vary. If the "ie"
covariance parameter is estimated near
+zero, then none
and ie
yield similar models.
All spatial covariance functions are valid in one spatial dimension. All
spatial covariance functions except triangular
and cosine
are
valid in two dimensions.
estmethod
Details: The various estimation methods are
reml
: Maximize the restricted log-likelihood.
An optional logical that indicates whether the range
should be constrained to enhance numerical stability. If range_constrain = TRUE
,
-the maximum possible range value is 5 times the maximum distance in the domain.
+the maximum possible range value is 4 times the maximum distance in the domain.
If range_constrain = FALSE
, then maximum possible range is unbounded.
The default is FALSE
.
Note that if range_constrain = TRUE
and the value of range
in spcov_initial
@@ -321,7 +321,7 @@
none: \(0\)
All spatial covariance functions are valid in one spatial dimension. All
spatial covariance functions except triangular
and cosine
are
-valid in two dimensions.
none
is ie
.
estmethod
Details: The various estimation methods are
reml
: Maximize the restricted log-likelihood.
ml
: Maximize the log-likelihood.
sv-wls
: Minimize the semivariogram weighted least squares loss.
spcov_params_val <- spcov_params("exponential", de = 0.2, ie = 0.1, range = 1)
sprbeta(spcov_params_val, data = caribou, xcoord = x, ycoord = y)
-#> [1] 0.05978670 0.95126057 0.07057026 0.36632930 0.90359435 0.13881493
-#> [7] 0.34909613 0.02995588 0.23990902 0.58547407 0.03147747 0.94308815
-#> [13] 0.58846837 0.01175391 0.12576057 0.99993991 0.64791853 0.78341448
-#> [19] 0.24783729 0.01160805 0.69107090 0.30751840 0.24645671 0.47340799
-#> [25] 0.24134403 0.79293742 0.46548023 0.98837206 0.57042907 0.93855070
+#> [1] 0.298921561 0.863224388 0.150588107 0.191437699 0.197762703 0.077908609
+#> [7] 0.889664682 0.074241709 0.812568993 0.995565338 0.007594357 0.001378291
+#> [13] 0.020987877 0.147117093 0.656609785 0.160276106 0.997662612 0.003922659
+#> [19] 0.190645066 0.362420019 0.795007720 0.654272679 0.839332027 0.004982284
+#> [25] 0.001119526 0.369104178 0.383245702 0.023917907 0.007404098 0.254007213
sprbeta(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
-#> 1 2 3 4 5
-#> [1,] 0.093176209 0.007523947 0.8609063701 0.4427733018 0.0001980756
-#> [2,] 0.974532680 0.091895925 0.2134198774 0.0447781776 0.1575990786
-#> [3,] 0.931337743 0.399287758 0.9017696088 0.0009843637 0.8626576087
-#> [4,] 0.022169398 0.459171809 0.9991964431 0.1967562732 0.9989868371
-#> [5,] 0.719558813 0.662574171 0.9224842679 0.0849879397 0.4741002841
-#> [6,] 0.037888063 0.984969789 0.7668424547 0.2413206722 0.0052402675
-#> [7,] 0.765330440 0.915672592 0.9999000000 0.6089034126 0.1211268728
-#> [8,] 0.010271835 0.948251696 0.9264256601 0.2549196205 0.4638325422
-#> [9,] 0.871180077 0.340503845 0.5882159000 0.5209320840 0.5171820295
-#> [10,] 0.994171048 0.855536838 0.0336828745 0.1806492642 0.3916788909
-#> [11,] 0.814941756 0.769755743 0.0166521089 0.3190989048 0.7931871223
-#> [12,] 0.999900000 0.908138605 0.9918873887 0.0256620880 0.0001000000
-#> [13,] 0.002727135 0.008665640 0.5515522339 0.6149095603 0.2276884013
-#> [14,] 0.575293119 0.764235030 0.8800792219 0.7479022219 0.0389900774
-#> [15,] 0.619202775 0.655958326 0.2555876280 0.3866657423 0.5300097429
-#> [16,] 0.018051909 0.853745054 0.5804006829 0.1997137448 0.1391051625
-#> [17,] 0.990478080 0.001183336 0.9074015149 0.9894557858 0.5633435298
-#> [18,] 0.014209015 0.971435436 0.0092389894 0.4583434236 0.2862562676
-#> [19,] 0.087403727 0.425863006 0.2433159072 0.5843460346 0.4055156784
-#> [20,] 0.398247354 0.205361507 0.8109834743 0.7714763753 0.0005205123
-#> [21,] 0.833176887 0.250520264 0.0659641970 0.0163931212 0.4343727457
-#> [22,] 0.214054992 0.973184428 0.0011127723 0.8272135918 0.3512310945
-#> [23,] 0.576089810 0.529687783 0.3147302953 0.3185523297 0.0927090430
-#> [24,] 0.589656278 0.690046256 0.9729940595 0.2539433347 0.7872442269
-#> [25,] 0.894747369 0.046846449 0.0010901081 0.0056100588 0.9189562762
-#> [26,] 0.299064552 0.157101387 0.0003867956 0.1983074808 0.7829296560
-#> [27,] 0.013442258 0.013232949 0.6141590750 0.7353648995 0.8511758470
-#> [28,] 0.493913069 0.915715392 0.0024869390 0.4498898497 0.9224820044
-#> [29,] 0.117590608 0.967016423 0.1862031942 0.9240646469 0.0343413478
-#> [30,] 0.415301197 0.937249459 0.9371240746 0.1828049750 0.5910659189
+#> 1 2 3 4 5
+#> [1,] 0.115431398 0.616688944 0.1641359723 0.8912529292 0.07915277
+#> [2,] 0.130438686 0.001089285 0.0110756879 0.2118023935 0.29692096
+#> [3,] 0.217993563 0.749579184 0.5128503526 0.9159847690 0.92179973
+#> [4,] 0.792226632 0.940076341 0.9205019395 0.7796577131 0.11678359
+#> [5,] 0.000100000 0.608027601 0.1814309967 0.8418308407 0.32382245
+#> [6,] 0.975295415 0.966593397 0.0001000000 0.0958329617 0.58440038
+#> [7,] 0.733295784 0.003261746 0.1581691145 0.9622233375 0.70175967
+#> [8,] 0.839885924 0.171419417 0.1327302975 0.6961117713 0.99990000
+#> [9,] 0.998502940 0.933019972 0.9954530808 0.8194676808 0.99564028
+#> [10,] 0.018954917 0.759435243 0.4877494252 0.0448579561 0.97240557
+#> [11,] 0.952348533 0.608581529 0.9792337694 0.0001000000 0.99453941
+#> [12,] 0.467773693 0.245854606 0.0388147400 0.9942323611 0.64204103
+#> [13,] 0.959627045 0.412916500 0.3770488814 0.8910610518 0.99990000
+#> [14,] 0.008998400 0.837555047 0.4016761796 0.9430282090 0.27462551
+#> [15,] 0.998577569 0.684946613 0.4189750853 0.0277346551 0.59787397
+#> [16,] 0.538580557 0.939297726 0.9301995425 0.1316371840 0.13268957
+#> [17,] 0.881849920 0.378552632 0.2115328495 0.5427226920 0.91450616
+#> [18,] 0.271702217 0.713810392 0.9999000000 0.1965341751 0.34559322
+#> [19,] 0.573162401 0.219419487 0.6555941836 0.9313336490 0.20145115
+#> [20,] 0.007815161 0.154066700 0.0660841628 0.0107903860 0.36708609
+#> [21,] 0.007957369 0.081593293 0.9896823472 0.9939858552 0.09496256
+#> [22,] 0.248332645 0.527132546 0.4482353240 0.9956808269 0.81838880
+#> [23,] 0.302730280 0.385316744 0.9877766377 0.5590530916 0.23958657
+#> [24,] 0.088256115 0.153042520 0.8797892422 0.0025217671 0.07662302
+#> [25,] 0.998322753 0.055039876 0.5123833333 0.3828355639 0.40177961
+#> [26,] 0.682700405 0.921108137 0.2886173210 0.9040182491 0.94852028
+#> [27,] 0.007120252 0.215883350 0.3924556527 0.9363071010 0.98658825
+#> [28,] 0.973290325 0.320793578 0.0003009108 0.5756982168 0.16136908
+#> [29,] 0.011092143 0.234603507 0.5082550895 0.9965227583 0.57130800
+#> [30,] 0.001854224 0.996093425 0.3659396466 0.0007264242 0.98794974
spcov_params_val <- spcov_params("exponential", de = 0.2, ie = 0.1, range = 1)
sprbinom(spcov_params_val, data = caribou, xcoord = x, ycoord = y)
-#> [1] 1 0 0 1 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 1 0 0 1 1 1 0 1 1 1
+#> [1] 0 0 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 0 0 1 0 0 0 1 1 0 1 1 1 1
sprbinom(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
#> 1 2 3 4 5
-#> [1,] 1 1 0 0 1
-#> [2,] 0 0 1 0 0
-#> [3,] 0 0 1 0 1
-#> [4,] 0 0 1 1 1
-#> [5,] 1 0 1 1 1
-#> [6,] 0 1 1 0 0
-#> [7,] 1 0 1 1 0
-#> [8,] 0 0 0 0 0
-#> [9,] 1 1 1 0 0
-#> [10,] 0 1 0 0 1
-#> [11,] 1 1 1 1 0
-#> [12,] 1 1 1 1 1
-#> [13,] 0 1 1 1 0
-#> [14,] 1 0 1 1 0
-#> [15,] 1 1 1 1 1
-#> [16,] 0 1 0 0 0
-#> [17,] 1 1 0 0 1
-#> [18,] 1 0 0 0 0
-#> [19,] 0 1 0 1 1
-#> [20,] 0 1 0 1 0
-#> [21,] 0 1 0 0 0
-#> [22,] 1 0 1 1 0
-#> [23,] 0 1 0 1 1
-#> [24,] 0 1 0 1 1
-#> [25,] 0 1 1 1 0
-#> [26,] 0 1 0 0 0
-#> [27,] 0 1 1 1 0
-#> [28,] 0 1 1 0 0
-#> [29,] 1 0 1 0 0
-#> [30,] 1 0 0 1 0
+#> [1,] 0 0 1 1 0
+#> [2,] 0 0 1 1 1
+#> [3,] 1 0 1 0 0
+#> [4,] 1 1 0 1 0
+#> [5,] 0 0 1 0 1
+#> [6,] 0 0 0 0 1
+#> [7,] 0 1 0 1 1
+#> [8,] 0 1 1 0 0
+#> [9,] 0 1 1 0 1
+#> [10,] 0 1 0 1 1
+#> [11,] 1 1 0 1 0
+#> [12,] 1 0 1 1 1
+#> [13,] 0 1 0 0 1
+#> [14,] 1 1 1 1 1
+#> [15,] 0 1 0 0 0
+#> [16,] 1 1 1 1 0
+#> [17,] 0 0 1 1 0
+#> [18,] 1 0 1 0 1
+#> [19,] 0 1 1 1 1
+#> [20,] 0 1 0 0 1
+#> [21,] 0 1 1 0 1
+#> [22,] 0 1 0 1 0
+#> [23,] 1 1 0 1 0
+#> [24,] 1 0 1 0 1
+#> [25,] 0 1 0 1 0
+#> [26,] 0 0 1 0 1
+#> [27,] 0 0 0 1 1
+#> [28,] 1 1 1 1 0
+#> [29,] 1 1 1 0 0
+#> [30,] 1 0 1 1 0
spcov_params_val <- spcov_params("exponential", de = 0.2, ie = 0.1, range = 1)
sprgamma(spcov_params_val, data = caribou, xcoord = x, ycoord = y)
-#> [1] 1.36169322 0.70176158 0.11085374 0.19902637 1.38575003 1.08003713
-#> [7] 0.50588835 3.12294138 0.56903055 0.24403798 3.08404827 6.07676214
-#> [13] 0.37097471 0.87651747 1.05804970 0.35871580 0.19295990 3.58802950
-#> [19] 0.97432670 0.44108731 1.64333540 0.53914936 4.35831855 1.38866946
-#> [25] 0.19242884 0.71853667 2.98070481 0.33956468 0.21261274 0.03733033
+#> [1] 0.75280447 0.38594517 3.65978446 1.95807057 1.65274919 1.25209439
+#> [7] 0.03943941 3.11983258 0.84666827 0.29061374 1.51102930 0.19039697
+#> [13] 0.67176796 1.39945414 0.82289422 0.42245213 0.64567331 1.06746015
+#> [19] 3.30860468 0.50481614 0.64595885 0.02451031 0.22405899 0.06002885
+#> [25] 0.16554357 0.04184807 0.33747198 0.61130810 1.22320369 0.43600759
sprgamma(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
-#> 1 2 3 4 5
-#> [1,] 1.65960149 0.06859476 0.63206876 0.91860882 2.17900892
-#> [2,] 1.16544083 0.45232992 2.64953162 0.43181296 6.79229005
-#> [3,] 0.69982103 0.34714763 0.88728603 10.79459398 0.10874263
-#> [4,] 0.85177148 0.19833268 0.94058248 0.51213187 0.12047310
-#> [5,] 1.19372988 1.89261324 0.66739880 0.22876843 0.62839535
-#> [6,] 0.40213711 1.47340586 0.29800680 0.29114546 0.74378419
-#> [7,] 0.08992688 0.47748523 0.58979506 1.51029704 0.47626262
-#> [8,] 0.04212040 0.09114111 1.57222946 0.55941031 0.25240568
-#> [9,] 0.93463310 1.42131746 2.92909930 1.44856954 1.01526684
-#> [10,] 1.42562641 0.77996857 1.59364101 0.09833515 1.61272155
-#> [11,] 0.11525274 0.75778400 0.20871735 1.34145626 0.74160239
-#> [12,] 0.37142467 0.14619573 0.35712169 0.85521718 2.41508926
-#> [13,] 0.13790102 2.02314068 3.22712591 0.18242588 0.25491548
-#> [14,] 0.93454760 0.61458333 0.76842899 0.33845787 0.44094035
-#> [15,] 0.91726401 11.65350493 0.10909168 0.23128564 0.18093767
-#> [16,] 0.20886922 2.00042668 0.55837310 0.88162639 0.96286667
-#> [17,] 0.05663288 0.80527901 0.02177123 0.25396722 0.07757135
-#> [18,] 0.48880116 2.52963134 0.90013776 0.20161640 1.08933549
-#> [19,] 0.45990148 2.40294352 0.68716639 0.32127837 1.66839052
-#> [20,] 1.48489451 2.58231885 3.04624828 0.42115744 0.19894999
-#> [21,] 0.75789719 0.07048620 0.55764007 0.40127587 3.09175631
-#> [22,] 0.60491713 0.77157153 0.39810478 0.68907420 1.18563417
-#> [23,] 0.80301554 0.59316645 0.54667718 0.25510524 0.92593693
-#> [24,] 0.05086169 0.33792585 1.73055432 0.32773326 1.04465020
-#> [25,] 0.62566255 0.23824178 0.39058477 1.87306660 2.11030832
-#> [26,] 0.43430739 1.76127128 0.04652649 0.75268568 0.38475621
-#> [27,] 0.30325790 3.87528687 0.12625823 0.71888510 0.74735895
-#> [28,] 0.80836076 0.02207119 6.90324794 0.13444120 0.13624736
-#> [29,] 0.73392238 0.40521513 0.87362080 0.74365464 0.48307691
-#> [30,] 0.14406440 0.26472290 0.69967431 0.32042970 0.38251750
+#> 1 2 3 4 5
+#> [1,] 1.01160006 0.76768002 0.7146641 1.19692535 0.37906964
+#> [2,] 1.16150090 0.02699926 0.8945328 0.16169799 0.78611375
+#> [3,] 3.96866661 0.18970004 0.5400695 0.62948241 1.12062116
+#> [4,] 1.35188653 9.37625082 0.1336606 0.29015804 0.22347443
+#> [5,] 4.17563139 1.64834705 0.4339255 0.11702445 0.87745582
+#> [6,] 0.23147224 1.16491348 0.5223104 0.39070655 0.73756924
+#> [7,] 1.47769653 1.72124453 3.4877920 3.07198132 0.16274737
+#> [8,] 3.97394865 0.11112337 5.8638050 0.29272855 0.89341586
+#> [9,] 0.97679781 2.77875196 0.1657846 1.62061743 0.21738573
+#> [10,] 1.09826786 0.91814099 0.2435776 1.23684664 0.94554324
+#> [11,] 0.46880580 0.14036372 1.0937906 0.24638476 0.07953849
+#> [12,] 0.94183728 0.63347394 2.3471394 0.28712331 0.02541582
+#> [13,] 0.62512279 1.07764049 1.6698897 0.07345519 1.07166132
+#> [14,] 1.09141752 0.63971546 0.4111601 1.48828898 0.14491959
+#> [15,] 4.50736005 4.01070453 1.2277185 0.59501756 1.19238386
+#> [16,] 0.32336355 0.10766847 1.9484982 0.49317266 0.61397317
+#> [17,] 0.24005798 2.21499830 1.4055560 1.11490925 0.10558722
+#> [18,] 0.36399426 1.17176556 2.4605372 0.76474288 2.82892057
+#> [19,] 3.74301935 0.30036465 1.3835480 1.08032389 0.26777267
+#> [20,] 0.43688672 2.15599572 1.2003288 0.17384957 2.25756906
+#> [21,] 0.01092240 0.63291578 0.4788034 1.38771640 1.48309401
+#> [22,] 0.31875788 1.07820428 1.0445484 0.94069500 1.56552447
+#> [23,] 0.01156632 0.47951011 0.1752193 2.41377704 0.16262056
+#> [24,] 0.34452728 0.36167865 1.2233904 0.16707112 3.16395959
+#> [25,] 0.61885066 0.47271573 1.2862121 1.53926220 0.68826229
+#> [26,] 5.58493023 0.96207878 0.3455525 0.60596376 6.06407935
+#> [27,] 0.21694470 1.98896297 3.7823486 0.48705370 0.19653064
+#> [28,] 0.17201868 1.52065932 1.1446676 0.05084512 2.77270149
+#> [29,] 1.19292624 0.48022934 1.2521601 1.66135129 3.70636043
+#> [30,] 2.40672184 0.35430804 0.8776703 2.10433002 0.69159080
spcov_params_val <- spcov_params("exponential", de = 0.2, ie = 0.1, range = 1)
sprinvgauss(spcov_params_val, data = caribou, xcoord = x, ycoord = y)
-#> [1] 0.4207435 0.8533214 0.2859779 0.4762297 6.1262449 1.4156841 1.5051686
-#> [8] 0.9538068 0.5496691 0.3410388 0.6410030 0.7567253 0.2934669 0.4878489
-#> [15] 0.4767287 0.7955248 0.1501103 0.6613469 0.3620646 0.2191450 3.4435467
-#> [22] 0.5456843 0.6722380 1.8707435 1.0112860 2.1591179 0.5705515 0.2617513
-#> [29] 1.3891783 0.6637879
+#> [1] 2.29527151 3.42017655 0.26392787 1.81500823 1.15248489 0.42154704
+#> [7] 0.56851168 0.96893835 0.39006233 0.97578811 0.46590499 1.25937157
+#> [13] 0.92796729 0.22387811 1.62881399 1.42456882 0.53965477 0.22130707
+#> [19] 1.64131833 0.16933350 0.62248858 2.67488082 0.63707453 0.37870944
+#> [25] 0.25971596 0.41523593 0.48299128 0.06967475 0.86433751 0.91504695
sprinvgauss(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
-#> 1 2 3 4 5
-#> [1,] 1.02164082 0.46185343 0.5177241 0.47405950 0.38859891
-#> [2,] 0.22509503 0.26596970 1.0482205 0.93094120 1.30648447
-#> [3,] 2.35333576 1.66543827 0.9960295 1.31082719 0.59935277
-#> [4,] 0.46391983 0.47710394 0.9633077 0.14816358 2.69377508
-#> [5,] 0.66484101 1.73918691 2.4197094 0.56825644 1.08115149
-#> [6,] 2.02631159 0.17666438 0.1154068 1.31921870 0.08195667
-#> [7,] 0.51274572 0.36076097 0.1694624 0.52927104 0.93111125
-#> [8,] 0.16337708 0.45890371 0.1082550 1.32012981 0.26970876
-#> [9,] 0.07022525 0.29488480 0.2021009 0.47947007 0.32462432
-#> [10,] 2.70209908 0.46591263 0.8245193 1.99131820 0.85424977
-#> [11,] 1.41828734 0.32531231 0.4662664 1.14174915 0.95468985
-#> [12,] 0.54184093 0.49779877 0.2535843 0.74313414 4.90361218
-#> [13,] 0.58923101 0.91157507 0.6083902 0.56585513 0.82942163
-#> [14,] 0.15173213 0.59048767 1.7858689 0.54187278 0.45678555
-#> [15,] 0.79442915 2.10123680 3.4430502 0.12497483 5.21225599
-#> [16,] 1.04161613 0.09216654 0.2192895 0.03698559 1.28022580
-#> [17,] 0.35974793 1.43836282 1.7691188 0.95983191 0.09501384
-#> [18,] 1.88974547 1.73348644 0.2045394 1.04606319 0.08497635
-#> [19,] 2.68831592 4.48624737 5.8301683 1.30859231 1.24602352
-#> [20,] 0.75223010 0.12086001 0.1054593 2.94774646 4.62973287
-#> [21,] 1.35559249 0.64711521 1.1134819 0.14054328 2.94434887
-#> [22,] 6.32251726 0.33522364 0.3867091 0.59312641 0.68806043
-#> [23,] 1.80334976 4.23317214 0.4169324 1.70665552 0.87775995
-#> [24,] 4.93760331 1.15711376 2.4383709 1.17532570 0.50935727
-#> [25,] 1.67446498 1.62959924 1.1228281 0.40638667 1.85100110
-#> [26,] 0.45987012 3.16002484 0.7502684 0.46765100 2.08569246
-#> [27,] 8.88002815 1.42993479 1.1511051 0.35652112 1.64211362
-#> [28,] 1.03782194 0.18958868 6.0510341 0.79521281 2.74707094
-#> [29,] 2.68793352 1.87884132 0.8625188 0.78497848 0.68545575
-#> [30,] 0.88555909 0.27488441 0.2018894 1.72069945 1.55611643
+#> 1 2 3 4 5
+#> [1,] 0.90702198 0.12478166 5.17678684 3.8246364 0.24014591
+#> [2,] 0.74990838 0.37713127 1.40714446 0.2049181 0.23260188
+#> [3,] 0.13568819 0.09872632 0.26812237 1.0342868 0.31159586
+#> [4,] 13.79049030 2.41638960 1.31160395 0.5346617 0.10785454
+#> [5,] 0.17673935 0.52258663 0.85749331 0.4367147 0.82346956
+#> [6,] 0.18325457 0.36587525 0.59718967 0.4895160 0.24979700
+#> [7,] 1.05523847 0.62383793 0.34865687 0.7214000 0.18181517
+#> [8,] 3.34316449 0.69953108 0.30689922 1.2350775 1.71730321
+#> [9,] 4.53974216 0.62779339 5.60463915 0.3144129 2.24850014
+#> [10,] 1.17362528 0.39001266 1.77595105 0.9879465 1.16348333
+#> [11,] 0.57480769 0.49074157 0.25033458 1.9290429 0.15157354
+#> [12,] 0.14220886 0.30955293 0.08492373 0.8024948 1.22702755
+#> [13,] 0.03789491 0.08006891 0.51361351 0.5270878 0.70460296
+#> [14,] 0.24070672 0.51731746 2.35131491 0.2092567 2.81573817
+#> [15,] 0.42226525 0.56209333 8.75641016 0.7587990 1.66220667
+#> [16,] 0.41172838 1.34011319 0.77193989 1.3456426 0.03972086
+#> [17,] 0.07389561 0.27342752 4.33797623 1.5459361 0.29971181
+#> [18,] 0.39798220 0.66284255 0.78725722 0.1934175 0.24243293
+#> [19,] 0.29986267 0.59298921 1.67232998 1.4456993 0.64967047
+#> [20,] 0.71000253 0.44869924 1.59906386 1.7142245 0.75320452
+#> [21,] 1.56983078 1.28375325 0.16219949 0.3151651 0.40983853
+#> [22,] 1.05421884 0.45740162 1.35163816 0.1963264 0.41892017
+#> [23,] 0.64748823 2.10795879 0.39695548 0.4569626 1.51279067
+#> [24,] 1.20232572 7.88639617 1.82371168 0.3385905 0.43286725
+#> [25,] 0.74129734 3.79598023 1.98101116 0.3869401 0.36532360
+#> [26,] 1.01680109 0.70565647 0.61094644 2.0223846 0.47120317
+#> [27,] 0.49490524 1.23089353 0.78096321 3.1666603 0.81707950
+#> [28,] 1.52462339 0.48893240 1.14640290 0.7062196 1.24399237
+#> [29,] 0.52245283 6.41000414 0.46330554 0.3237940 1.23896506
+#> [30,] 0.33402727 0.30682418 1.74957371 0.2246852 0.30006437
spcov_params_val <- spcov_params("exponential", de = 0.2, ie = 0.1, range = 1)
sprnbinom(spcov_params_val, data = caribou, xcoord = x, ycoord = y)
-#> [1] 1 0 0 0 0 0 2 0 1 0 0 4 0 0 4 0 1 1 0 2 4 4 0 0 0 1 0 4 0 0
+#> [1] 0 5 0 0 1 0 0 0 0 0 2 1 1 1 0 0 2 0 0 4 1 0 0 0 0 2 1 1 0 1
sprnbinom(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
#> 1 2 3 4 5
-#> [1,] 1 2 0 4 1
-#> [2,] 1 0 0 0 5
-#> [3,] 4 0 1 2 6
-#> [4,] 3 0 0 3 3
-#> [5,] 0 1 1 1 0
-#> [6,] 1 3 0 0 1
-#> [7,] 0 0 0 2 0
-#> [8,] 0 0 0 0 0
-#> [9,] 1 1 2 0 1
-#> [10,] 0 0 0 1 0
-#> [11,] 0 0 2 0 1
-#> [12,] 0 0 1 0 1
-#> [13,] 1 0 1 0 0
-#> [14,] 3 0 0 0 3
-#> [15,] 0 5 0 0 0
-#> [16,] 0 1 1 1 1
-#> [17,] 0 1 0 3 0
-#> [18,] 0 4 1 1 1
-#> [19,] 1 0 2 3 2
-#> [20,] 0 0 0 4 0
-#> [21,] 0 0 3 4 2
-#> [22,] 0 1 2 3 1
-#> [23,] 0 1 0 0 0
-#> [24,] 4 1 0 0 0
-#> [25,] 0 0 3 0 1
-#> [26,] 1 1 0 0 1
-#> [27,] 0 1 0 0 0
-#> [28,] 0 0 0 1 0
-#> [29,] 1 5 1 0 0
-#> [30,] 1 0 1 2 1
+#> [1,] 0 6 4 0 0
+#> [2,] 0 4 0 0 2
+#> [3,] 1 0 1 0 1
+#> [4,] 1 0 0 1 0
+#> [5,] 0 4 0 0 0
+#> [6,] 2 2 0 0 0
+#> [7,] 6 0 0 0 0
+#> [8,] 0 0 0 1 1
+#> [9,] 8 0 0 0 1
+#> [10,] 0 0 1 2 0
+#> [11,] 0 9 1 0 3
+#> [12,] 0 0 3 0 1
+#> [13,] 0 2 3 0 2
+#> [14,] 0 2 0 5 1
+#> [15,] 1 1 1 0 1
+#> [16,] 0 0 2 0 3
+#> [17,] 0 1 3 1 1
+#> [18,] 0 0 2 0 0
+#> [19,] 3 1 6 0 4
+#> [20,] 0 1 1 6 1
+#> [21,] 3 0 1 0 5
+#> [22,] 2 0 0 1 0
+#> [23,] 1 1 2 0 4
+#> [24,] 0 0 1 1 1
+#> [25,] 0 0 0 0 2
+#> [26,] 1 2 4 4 0
+#> [27,] 0 3 0 0 1
+#> [28,] 1 1 0 0 0
+#> [29,] 1 3 2 0 0
+#> [30,] 0 4 1 2 2
spcov_params_val <- spcov_params("exponential", de = 1, ie = 1, range = 1)
sprnorm(spcov_params_val, data = caribou, xcoord = x, ycoord = y)
-#> [1] -0.06980081 -0.68020627 -0.56886464 -0.26815128 -1.01535060 2.33551655
-#> [7] -0.44967057 -1.92889316 -1.63504814 -2.32871896 1.93289443 1.85437674
-#> [13] -1.55763216 -1.20003818 -2.16023906 -0.28367420 1.60990348 0.30700052
-#> [19] -1.05285940 -3.05679064 -0.19894495 4.34957221 0.15534697 -0.78244287
-#> [25] -2.39471474 2.95632391 0.94821654 0.43928418 -1.57004380 0.89329132
+#> [1] 0.7295330 -0.1464557 -0.6440707 0.6846085 -1.0265109 1.0855714
+#> [7] 0.4864720 -0.6086310 -0.6648226 1.2126239 1.1669871 1.3339350
+#> [13] 0.5193776 1.3132474 -0.2588738 0.7270756 -0.2675173 2.4908294
+#> [19] 1.1697255 -0.4819587 0.1402007 -0.6007224 2.6260628 2.3593206
+#> [25] -1.2412009 -0.3532930 -2.0020151 0.3291695 -1.1167337 0.5067219
sprnorm(spcov_params_val, mean = 1:30, samples = 5, data = caribou, xcoord = x, ycoord = y)
-#> [,1] [,2] [,3] [,4] [,5]
-#> [1,] 2.078090 1.3147187 1.441157 2.124264 0.5462837
-#> [2,] 2.840552 0.2225271 1.685848 2.586706 4.0892017
-#> [3,] 6.115456 4.5206299 5.159078 4.402004 1.1861009
-#> [4,] 2.783873 3.1979665 5.672752 3.679482 2.3481716
-#> [5,] 5.190463 3.6040938 6.630187 5.375776 4.4039315
-#> [6,] 8.025303 6.6460794 4.857592 5.557943 5.1827048
-#> [7,] 4.890117 7.3494126 6.591105 9.463003 7.6571161
-#> [8,] 9.603237 6.6343564 6.693872 9.185765 8.4138987
-#> [9,] 9.388534 7.8719517 8.660903 8.534503 7.9407269
-#> [10,] 10.928985 7.4975513 11.436805 9.949048 10.3371819
-#> [11,] 12.374689 8.9616718 12.231921 10.300568 10.2829292
-#> [12,] 12.195869 11.5621364 12.928044 14.589577 13.3807373
-#> [13,] 15.608122 12.8850120 13.926398 15.352861 12.4245765
-#> [14,] 14.198620 13.0868805 14.133952 12.762481 11.3430095
-#> [15,] 14.799059 15.0785857 13.979685 14.438695 13.1587026
-#> [16,] 16.307745 17.8768995 12.218104 13.984914 13.8725352
-#> [17,] 14.574256 15.6592328 18.465883 17.309888 18.2788915
-#> [18,] 16.288000 17.9217261 18.870794 16.868634 17.5694213
-#> [19,] 17.119627 19.3590533 17.479299 19.474120 19.7600068
-#> [20,] 18.946611 20.4888340 20.398798 21.530128 18.7400504
-#> [21,] 21.124212 20.0470900 20.281633 18.049198 20.0074259
-#> [22,] 21.046118 22.6511808 21.296460 20.258446 22.6361451
-#> [23,] 21.080317 23.1293510 23.742695 24.728682 25.4201797
-#> [24,] 21.584540 24.3182510 22.871521 23.912125 26.0899007
-#> [25,] 24.717717 24.4614129 25.786639 23.123184 24.4012597
-#> [26,] 26.026392 27.1471721 26.111566 23.031574 27.7883921
-#> [27,] 27.592915 31.8283411 26.266823 26.528206 26.4244062
-#> [28,] 30.205454 30.5862874 27.328975 28.569603 27.8954187
-#> [29,] 30.003495 29.5748153 30.263001 30.023616 29.4048819
-#> [30,] 28.712228 29.4849548 31.163288 30.137724 32.0432562
+#> [,1] [,2] [,3] [,4] [,5]
+#> [1,] 2.6826043 0.03645854 0.5418698 -0.9583461 -0.9407780
+#> [2,] -0.3475714 1.07867458 2.8647890 1.2259798 0.2757822
+#> [3,] 1.4192099 3.57972869 1.8585750 3.8140107 1.5220003
+#> [4,] 5.7859837 6.46258424 2.0783939 3.6029321 2.3611136
+#> [5,] 4.8314165 7.28339629 5.2239981 4.1732668 4.8750043
+#> [6,] 3.9052040 5.02831125 4.9407409 5.2405835 7.1770119
+#> [7,] 4.0811976 8.62503780 6.2341917 7.5103071 5.2324641
+#> [8,] 7.6099946 7.38567557 8.1745419 8.0192062 7.1591082
+#> [9,] 9.6443881 8.93477189 9.9143297 7.2800348 8.0556939
+#> [10,] 11.1737062 10.54551342 9.5474115 9.4969713 10.4015801
+#> [11,] 10.6457242 12.91474090 10.5644616 10.0171602 10.3333953
+#> [12,] 10.9550519 11.30757591 12.4383081 11.2161272 12.2723014
+#> [13,] 14.7887060 12.89027226 14.4906696 13.4813033 13.3166775
+#> [14,] 12.2561885 12.81773362 15.4710743 12.5490735 14.0731488
+#> [15,] 13.6222303 14.41096493 13.3685912 12.4559545 13.4177200
+#> [16,] 15.5565348 15.28052745 16.7505130 15.7552921 16.7151686
+#> [17,] 15.9511689 18.18521355 17.1905893 16.2667766 16.2584423
+#> [18,] 18.5378461 17.70817096 18.7072022 20.3020913 18.3316137
+#> [19,] 19.4339331 17.23963728 18.9809522 19.4549497 18.7934473
+#> [20,] 19.0473645 20.16644781 20.6129162 20.5602634 19.9818491
+#> [21,] 21.5359177 22.25259498 20.1363655 20.6932762 20.3953194
+#> [22,] 21.3121090 22.64364461 21.9117288 21.5527441 20.9678691
+#> [23,] 24.3641973 21.91184919 25.8638034 23.3035162 24.2698395
+#> [24,] 23.4176948 22.74474825 26.0934353 24.5857354 24.6562789
+#> [25,] 22.3106568 24.03093980 23.8808282 24.0220256 25.8209420
+#> [26,] 24.6157656 27.58248741 23.7597144 26.4362438 26.5329806
+#> [27,] 24.7461919 28.53420016 27.8781392 27.5560128 25.3986703
+#> [28,] 29.2483577 26.81614702 29.8974594 29.0680694 28.8898464
+#> [29,] 28.5834952 28.22743999 28.6159507 29.8020352 27.9987930
+#> [30,] 30.8567576 30.57729558 27.5115180 31.2970567 30.3425222
spcov_params_val <- spcov_params("exponential", de = 0.2, ie = 0.1, range = 1)
sprpois(spcov_params_val, data = caribou, xcoord = x, ycoord = y)
-#> [1] 1 0 1 0 1 0 0 0 1 1 1 0 1 2 1 1 1 0 0 0 1 0 2 0 2 0 0 2 0 3
+#> [1] 2 0 5 1 3 0 3 4 1 1 0 0 3 3 0 0 1 0 0 3 1 3 1 1 1 4 2 0 1 0
sprpois(spcov_params_val, samples = 5, data = caribou, xcoord = x, ycoord = y)
#> 1 2 3 4 5
-#> [1,] 2 3 1 1 0
-#> [2,] 5 3 0 0 1
-#> [3,] 0 2 0 0 0
-#> [4,] 0 4 0 0 0
-#> [5,] 0 1 2 2 1
-#> [6,] 1 1 0 2 1
-#> [7,] 1 0 5 3 0
-#> [8,] 2 0 1 3 0
-#> [9,] 0 0 0 1 1
-#> [10,] 0 0 0 0 0
-#> [11,] 1 0 0 0 1
-#> [12,] 1 1 2 2 0
-#> [13,] 0 0 2 3 1
-#> [14,] 2 0 1 2 0
-#> [15,] 2 0 1 0 3
-#> [16,] 1 1 1 4 0
-#> [17,] 2 1 2 2 0
-#> [18,] 0 0 2 2 1
-#> [19,] 1 0 1 1 4
-#> [20,] 0 4 0 4 1
-#> [21,] 0 0 0 2 1
-#> [22,] 3 3 1 1 1
-#> [23,] 1 0 0 0 0
-#> [24,] 1 1 2 1 1
-#> [25,] 0 4 2 2 0
-#> [26,] 0 0 1 4 1
-#> [27,] 3 2 2 2 0
-#> [28,] 1 1 1 0 1
-#> [29,] 1 1 1 4 4
-#> [30,] 0 0 2 0 0
+#> [1,] 3 1 1 0 0
+#> [2,] 0 0 0 1 0
+#> [3,] 0 1 1 1 2
+#> [4,] 2 0 1 1 2
+#> [5,] 2 0 3 0 2
+#> [6,] 1 0 0 3 0
+#> [7,] 1 1 1 1 3
+#> [8,] 2 1 3 0 1
+#> [9,] 0 2 3 0 0
+#> [10,] 0 2 0 1 2
+#> [11,] 0 2 1 3 1
+#> [12,] 1 1 0 1 2
+#> [13,] 0 1 0 1 0
+#> [14,] 3 4 2 0 0
+#> [15,] 3 0 3 2 7
+#> [16,] 2 1 0 2 1
+#> [17,] 0 2 0 0 3
+#> [18,] 1 1 0 2 1
+#> [19,] 2 1 1 5 2
+#> [20,] 0 3 1 1 3
+#> [21,] 1 4 1 0 1
+#> [22,] 1 0 0 2 3
+#> [23,] 1 0 1 1 0
+#> [24,] 0 1 4 1 1
+#> [25,] 2 4 3 0 1
+#> [26,] 0 1 2 3 3
+#> [27,] 1 2 1 2 0
+#> [28,] 2 2 1 1 0
+#> [29,] 1 2 3 1 1
+#> [30,] 2 1 1 0 5