Skip to content

Commit

Permalink
fix nmix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Clark committed Mar 26, 2024
1 parent 61f4067 commit 272ad99
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 29 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mvgam
Title: Multivariate (Dynamic) Generalized Additive Models
Version: 1.0.91
Date: 2024-01-12
Version: 1.1.0
Date: 2024-03-26
Authors@R:
person("Nicholas J", "Clark", , "nicholas.j.clark1214@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-7131-3301"))
Expand Down
22 changes: 11 additions & 11 deletions R/conditional_effects.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ conditional_effects.mvgam = function(x,
'detection', 'latent_N',
'expected'))

if(type == 'response'){
if(points){
points <- 0.5
} else {
points <- 0
}
} else {
points <- 0
rug <- FALSE
}

# Can't plot points or rugs with binomial models due to the
# cbind syntax
if(rug){
Expand All @@ -103,17 +114,6 @@ conditional_effects.mvgam = function(x,
}
}

if(type == 'response'){
if(points){
points <- 0.5
} else {
points <- 0
}
} else {
points <- 0
rug <- FALSE
}

if(use_def_effects){
# Get all term labels in the model
termlabs <- attr(terms(formula(x),
Expand Down
20 changes: 14 additions & 6 deletions R/update.mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,27 @@
#' @examples
#' \dontrun{
#' # Simulate some data and fit a Poisson AR1 model
#' simdat <- sim_mvgam(n_series = 1, trend_model = 'AR1')
#' simdat <- sim_mvgam(n_series = 1, trend_model = AR())
#' mod <- mvgam(y ~ s(season, bs = 'cc'),
#' trend_model = 'AR1',
#' data = simdat$data_train)
#' trend_model = AR(),
#' data = simdat$data_train)
#' summary(mod)
#' conditional_effects(mod, type = 'link')
#'
#' # Update to an AR2 model
#' updated_mod <- update(mod, trend_model = 'AR2')
#' updated_mod <- update(mod, trend_model = AR(p = 2))
#' summary(updated_mod)
#' conditional_effects(updated_mod, type = 'link')
#'
#' # Now update to a Negative Binomial AR1
#' updated_mod <- update(mod, family = nb())
#' # Now update to a Binomial AR1 by adding information on trials
#' # requires that we supply newdata that contains the 'trials' variable
#' simdat$data_train$trials <- max(simdat$data_train$y) + 15
#' updated_mod <- update(mod,
#' formula = cbind(y, trials) ~ s(season, bs = 'cc'),
#' data = simdat$data_train,
#' family = binomial())
#' summary(updated_mod)
#' conditional_effects(updated_mod, type = 'link')
#'}
#'@export
update.mvgam = function(object,
Expand Down
22 changes: 15 additions & 7 deletions man/update.mvgam.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified src/mvgam.dll
Binary file not shown.
10 changes: 7 additions & 3 deletions tests/testthat/test-nmixture.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ test_that("cap must be supplied in data", {
'Max abundances must be supplied as a variable named "cap" for N-mixture models',
fixed = TRUE)

poisdat$data_train$cap <- 100
poisdat$data_train$cap <- rpois(NROW(poisdat$data_train),
lambda = 5) +
max(poisdat$data_train$y, na.rm = TRUE)
expect_error(mvgam(formula = y ~ s(season),
trend_formula = ~ s(season) +
trend,
Expand All @@ -45,10 +47,12 @@ test_that("cap must be supplied in data", {
fixed = TRUE)
})

poisdat$data_train$cap <- 100
poisdat$data_train$cap <- rpois(NROW(poisdat$data_train),
lambda = 5) +
max(poisdat$data_train$y, na.rm = TRUE)
poisdat$data_test$cap <- rpois(NROW(poisdat$data_test),
lambda = 5) +
max(poisdat$data_test$y)
max(poisdat$data_test$y, na.rm = TRUE)

test_that("latent process intercept is allowed in nmixtures", {
prior_df <- get_mvgam_priors(formula = y ~ s(season),
Expand Down

0 comments on commit 272ad99

Please sign in to comment.