Skip to content

Commit

Permalink
allow normal residual for spatial mmrm
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkliming committed May 8, 2023
1 parent 8e316e2 commit 1e8c18b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions R/tmb-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ print.mmrm_tmb <- function(x,
#' - \insertRef{galecki2013linear}{mmrm}
residuals.mmrm_tmb <- function(object, type = c("response", "pearson", "normalized"), ...) {
type <- match.arg(type)
if (identical(object$tmb_data$is_spatial, 1L) && !identical(type, "response")) {
stop("Only 'respons'residuals are available for models with spatial covariance structures.")
if (identical(object$tmb_data$is_spatial, 1L) && identical(type, "pearson")) {
stop("'pearson' residuals is not available for models with spatial covariance structures.")
}
switch(type,
"response" = h_residuals_response(object),
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-tmb-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ test_that("residuals works as expected with a model using spatial covariance str
result_resp <- expect_silent(residuals(object, type = "response"))
expect_double(result_resp, len = length(object$tmb_data$y_vector))
expect_equal(head(result_resp, 5), c(-4.5428, -24.0301, -8.8329, -3.4092, 8.5200), tolerance = 1e-4)

result_normal <- residuals(object, type = "normalized")
expect_equal(head(result_normal, 5), c(-0.4943, -2.5698, -0.9613, 0.0046, 1.1645), tolerance = 1e-4)
expect_error(residuals(object, type = "pearson"))
expect_error(residuals(object, type = "normalized"))
})

test_that("pearson residuals helper function works as expected", {
Expand Down

0 comments on commit 1e8c18b

Please sign in to comment.